From 7a59bcde4c0c77314b88125b6af5eba56f6e3289 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 25 Jan 2018 19:53:55 +0100 Subject: [PATCH] - move glossiness and specular level to GLDEFS --- src/gl/renderer/gl_renderstate.cpp | 3 +++ src/gl/renderer/gl_renderstate.h | 8 ++++++++ src/gl/shaders/gl_shader.cpp | 1 + src/gl/shaders/gl_shader.h | 1 + src/gl/textures/gl_texture.cpp | 14 ++++++++++++++ src/textures/textures.h | 2 ++ wadsrc/static/shaders/glsl/main.fp | 2 +- wadsrc/static/shaders/glsl/shaderdefs.i | 3 +++ 8 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 119444af6..499303cab 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -87,6 +87,8 @@ void FRenderState::Reset() mSpecialEffect = EFF_NONE; mClipHeight = 0.f; mClipHeightDirection = 0.f; + mGlossiness = 0.0f; + mSpecularLevel = 0.0f; mShaderTimer = 0.0f; ClearClipSplit(); @@ -178,6 +180,7 @@ bool FRenderState::ApplyShader() activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now activeShader->muClipSplit.Set(mClipSplit); activeShader->muViewHeight.Set(viewheight); + activeShader->muSpecularMaterial.Set(mGlossiness, mSpecularLevel); if (mGlowEnabled) { diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 92de96e9a..e6a6c1dcb 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -94,6 +94,7 @@ class FRenderState bool mLastDepthClamp; float mInterpolationFactor; float mClipHeight, mClipHeightDirection; + float mGlossiness, mSpecularLevel; float mShaderTimer; FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer; @@ -152,6 +153,7 @@ public: } mEffectState = overrideshader >= 0? overrideshader : mat->mShaderIndex; mShaderTimer = mat->tex->gl_info.shaderspeed; + SetSpecular(mat->tex->gl_info.Glossiness, mat->tex->gl_info.SpecularLevel); mat->Bind(clampmode, translation); } @@ -386,6 +388,12 @@ public: mObjectColor2 = pe; } + void SetSpecular(float glossiness, float specularLevel) + { + mGlossiness = glossiness; + mSpecularLevel = specularLevel; + } + void SetFog(PalEntry c, float d) { const float LOG2E = 1.442692f; // = 1/log(2) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 833c1722d..bcaea9bb4 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -254,6 +254,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muClipHeight.Init(hShader, "uClipHeight"); muClipHeightDirection.Init(hShader, "uClipHeightDirection"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); + muSpecularMaterial.Init(hShader, "uSpecularMaterial"); muViewHeight.Init(hShader, "uViewHeight"); muTimer.Init(hShader, "timer"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 5b4e23c63..8041f4880 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -285,6 +285,7 @@ class FShader FBufferedUniform1f muClipHeightDirection; FBufferedUniform1f muAlphaThreshold; FBufferedUniform1i muViewHeight; + FBufferedUniform2f muSpecularMaterial; FBufferedUniform1f muTimer; int lights_index; diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index e7e459186..6501d9709 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -191,6 +191,8 @@ FTexture::MiscGLInfo::MiscGLInfo() throw() mIsTransparent = -1; shaderspeed = 1.f; shaderindex = 0; + Glossiness = 0.0f; + SpecularLevel = 0.0f; Material[1] = Material[0] = NULL; SystemTexture[1] = SystemTexture[0] = NULL; @@ -598,6 +600,18 @@ void gl_ParseMaterial(FScanner &sc, int deflump) // only affects textures defined in the IWAD. iwad = true; } + else if (sc.Compare("glossiness")) + { + sc.MustGetFloat(); + if (tex) + tex->gl_info.Glossiness = sc.Float; + } + else if (sc.Compare("specularlevel")) + { + sc.MustGetFloat(); + if (tex) + tex->gl_info.SpecularLevel = sc.Float; + } else { for (int i = 0; keywords[i] != nullptr; i++) diff --git a/src/textures/textures.h b/src/textures/textures.h index 72501e492..c80abf87b 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -372,6 +372,8 @@ public: FTexture *Metallic; // Metalness texture for the physically based rendering (PBR) light model FTexture *Roughness; // Roughness texture for PBR FTexture *AmbientOcclusion; // Ambient occlusion texture for PBR + float Glossiness; + float SpecularLevel; PalEntry GlowColor; int GlowHeight; FloatRect *areas; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 6bc9f7a90..d1ae8f50f 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -369,7 +369,7 @@ vec2 pointLightAttenuation(vec4 lightpos, float lightcolorA) float diffuseAmount = diffuseContribution(lightDirection, pixelnormal); #if defined(SPECULAR) - float specularAmount = blinnSpecularContribution(diffuseAmount, lightDirection, pixelnormal, 100.0, 200.0); + float specularAmount = blinnSpecularContribution(diffuseAmount, lightDirection, pixelnormal, uSpecularMaterial.x, uSpecularMaterial.y); return vec2(diffuseAmount, specularAmount) * attenuation; #else return vec2(attenuation * diffuseAmount, 0.0); diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i index 15d68428e..6836135d3 100644 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ b/wadsrc/static/shaders/glsl/shaderdefs.i @@ -51,6 +51,9 @@ uniform int uLightIndex; // Software fuzz scaling uniform int uViewHeight; +// Blinn glossiness and specular level +uniform vec2 uSpecularMaterial; + // quad drawer stuff #ifdef USE_QUAD_DRAWER uniform mat4 uQuadVertices;