From 53f4cd010837e3bbdd4c897daa97d44a7ee8a911 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 May 2014 16:06:25 +0200 Subject: [PATCH] - added objectcolor uniform. This will be used to hold the thingcolor for shader based rendering. --- src/gl/dynlights/gl_dynlight1.cpp | 8 ------- src/gl/renderer/gl_renderstate.cpp | 9 ++++++++ src/gl/renderer/gl_renderstate.h | 23 +++++++++++++++++++- src/gl/scene/gl_flats.cpp | 1 - src/gl/scene/gl_sprite.cpp | 3 ++- src/gl/scene/gl_walls_draw.cpp | 1 + src/gl/shaders/gl_shader.h | 5 ++++- wadsrc/static/shaders/glsl/func_notexture.fp | 2 +- wadsrc/static/shaders/glsl/main.fp | 3 ++- wadsrc/static/shaders/glsl/main_colormap.fp | 3 ++- 10 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index e092074114..57da56b40b 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -234,14 +234,6 @@ bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & u { gl_RenderState.BlendEquation(GL_FUNC_ADD); } - if (desaturation>0) - { - float gray=(r*77 + g*143 + b*37)/257; - - r= (r*(32-desaturation)+ gray*desaturation)/32; - g= (g*(32-desaturation)+ gray*desaturation)/32; - b= (b*(32-desaturation)+ gray*desaturation)/32; - } glColor3f(r,g,b); return true; } diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 67a53bf197..84f270e067 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -78,6 +78,7 @@ void FRenderState::Reset() mAlphaFunc = GL_GEQUAL; mAlphaThreshold = 0.5f; mBlendEquation = GL_FUNC_ADD; + mObjectColor = 0xffffffff; glBlendEquation = -1; m2D = true; mVertexBuffer = mCurrentVertexBuffer = NULL; @@ -158,6 +159,7 @@ bool FRenderState::ApplyShader() if (activeShader) { int fogset = 0; + //glColor4fv(mColor.vec); if (mFogEnabled) { if ((mFogColor & 0xffffff) == 0) @@ -226,6 +228,11 @@ bool FRenderState::ApplyShader() { glUniform3fv(activeShader->dlightcolor_index, 1, mDynLight); } + if (mObjectColor != activeShader->currentobjectcolor) + { + activeShader->currentobjectcolor = mObjectColor; + glUniform4f(activeShader->objectcolor_index, mObjectColor.r / 255.f, mObjectColor.g / 255.f, mObjectColor.b / 255.f, mObjectColor.a / 255.f); + } return true; } @@ -276,6 +283,8 @@ void FRenderState::Apply(bool forcenoshader) } if (forcenoshader || !ApplyShader()) { + //if (mColor.vec[0] >= 0.f) glColor4fv(mColor.vec); + GLRenderer->mShaderManager->SetActiveShader(NULL); if (mTextureMode != ffTextureMode) { diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 7e611f7a56..35f5795a24 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -107,11 +107,12 @@ class FRenderState bool m2D; FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer; - + FStateVec4 mColor; FStateVec3 mCameraPos; FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTopPlane, mGlowBottomPlane; PalEntry mFogColor; + PalEntry mObjectColor; float mFogDensity; int mEffectState; @@ -149,6 +150,26 @@ public: mVertexBuffer = vb; } + void SetColor(float r, float g, float b, float a = 1.f, int desat = 0) + { + mColor.Set(r, g, b, a); + } + + void SetColor(PalEntry pe, int desat = 0) + { + mColor.Set(pe.r/255.f, pe.g/255.f, pe.b/255.f, pe.a/255.f); + } + + void SetColorAlpha(PalEntry pe, float alpha = 1.f, int desat = 0) + { + mColor.Set(pe.r/255.f, pe.g/255.f, pe.b/255.f, alpha); + } + + void ResetColor() + { + mColor.Set(1,1,1,1); + } + void SetTextureMode(int mode) { mTextureMode = mode; diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index c320119986..f24db1fdd4 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -325,7 +325,6 @@ void GLFlat::DrawSubsectors(int pass, bool istrans) { if (gl_usevbo && vboindex >= 0) { - //glColor3f( 1.f,.5f,.5f); int index = vboindex; for (int i=0; isubsectorcount; i++) { diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index d018d2eea7..46541fc27f 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -749,7 +749,8 @@ void GLSprite::Process(AActor* thing,sector_t * sector) if (gl_enhanced_nightvision && (thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE)) { - Colormap.colormap = CM_FIRSTSPECIALCOLORMAP + INVERSECOLORMAP; + // needs to be fixed later + //Colormap.colormap = CM_FIRSTSPECIALCOLORMAP + INVERSECOLORMAP; } } } diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index f060978e49..7f7538dc47 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -373,6 +373,7 @@ void GLWall::RenderFogBoundary() gl_RenderState.AlphaFunc(GL_GREATER,0); glDepthFunc(GL_LEQUAL); glColor4f(fc[0],fc[1],fc[2], fogd1); + gl_RenderState.SetColor(-1, 0, 0, 0); // we do not want the render state to control the color. if (glset.lightmode == 8) glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); // Korshun. flags &= ~GLWF_GLOW; diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index bd3aa0f30c..4b0c37e1e1 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -40,7 +40,9 @@ class FShader int glowtopcolor_index; int glowbottomplane_index; int glowtopplane_index; + int objectcolor_index; + PalEntry currentobjectcolor; int currentglowstate; int currentfogenabled; int currenttexturemode; @@ -59,7 +61,7 @@ public: currentglowstate = currentfogenabled = currenttexturemode = 0; currentlightfactor = currentlightdist = 0.0f; currentfogdensity = -1; - currentfogcolor = 0; + currentobjectcolor = currentfogcolor = 0; timer_index = -1; desaturation_index = -1; @@ -73,6 +75,7 @@ public: fogcolor_index = -1; lights_index = -1; dlightcolor_index = -1; + objectcolor_index = -1; glowtopplane_index = -1; glowbottomplane_index = -1; glowtopcolor_index = -1; diff --git a/wadsrc/static/shaders/glsl/func_notexture.fp b/wadsrc/static/shaders/glsl/func_notexture.fp index 99ef44f68d..904d4a6cd7 100644 --- a/wadsrc/static/shaders/glsl/func_notexture.fp +++ b/wadsrc/static/shaders/glsl/func_notexture.fp @@ -1,6 +1,6 @@ vec4 Process(vec4 color) { - return color; + return color*objectcolor; } diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 6bb17a2ad5..a99ffa330d 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -23,6 +23,7 @@ uniform vec4 lights[128]; uniform int fogenabled; uniform vec4 fogcolor; +uniform vec4 objectcolor; uniform vec3 dlightcolor; uniform vec3 camerapos; varying vec4 pixelpos; @@ -158,7 +159,7 @@ vec4 getTexel(vec2 st) } #endif - return desaturate(texel); + return desaturate(texel * objectcolor); } //=========================================================================== diff --git a/wadsrc/static/shaders/glsl/main_colormap.fp b/wadsrc/static/shaders/glsl/main_colormap.fp index fa0f28f250..d4c079cdda 100644 --- a/wadsrc/static/shaders/glsl/main_colormap.fp +++ b/wadsrc/static/shaders/glsl/main_colormap.fp @@ -1,6 +1,7 @@ uniform int texturemode; uniform sampler2D tex; +uniform vec4 objectcolor; uniform vec3 colormapstart; uniform vec3 colormaprange; @@ -28,7 +29,7 @@ vec4 getTexel(vec2 st) texel.rgb = vec3(1.0,1.0,1.0); } - return texel; + return texel*objectcolor; }