From 0f69778e233ebab0b8eafe2fb02e206a535bc109 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 21 Jan 2018 01:53:44 +0100 Subject: [PATCH] - Add new material shader entries for specular and PBR light modes --- src/gl/scene/gl_sprite.cpp | 2 +- src/gl/scene/gl_weapon.cpp | 2 +- src/gl/shaders/gl_shader.cpp | 44 ++++++++++++++++++++---------------- src/gl/shaders/gl_shader.h | 32 ++++++++++++++------------ 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index edd0da1d9..3a27a7cde 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -991,7 +991,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) { // Todo: implement shader selection here RenderStyle = LegacyRenderStyles[STYLE_Translucent]; - OverrideShader = gl_fuzztype + 4; + OverrideShader = SHADER_NoTexture + gl_fuzztype; trans = 0.99f; // trans may not be 1 here hw_styleflags = STYLEHW_NoAlphaTest; } diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 69551f28a..2061d67f3 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -355,7 +355,7 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { // Todo: implement shader selection here RenderStyle = LegacyRenderStyles[STYLE_Translucent]; - OverrideShader = gl_fuzztype + 4; + OverrideShader = SHADER_NoTexture + gl_fuzztype; trans = 0.99f; // trans may not be 1 here } else diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index c7944f141..5d7cdd359 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -325,9 +325,10 @@ bool FShader::Bind() // //========================================================================== -FShader *FShaderCollection::Compile (const char *ShaderName, const char *ShaderPath, bool usediscard, EPassType passType) +FShader *FShaderCollection::Compile (const char *ShaderName, const char *ShaderPath, const char *shaderdefines, bool usediscard, EPassType passType) { FString defines; + defines += shaderdefines; // this can't be in the shader code due to ATI strangeness. if (gl.MaxLights() == 128) defines += "#define MAXLIGHTS128\n"; if (!usediscard) defines += "#define NO_ALPHATEST\n"; @@ -374,24 +375,29 @@ struct FDefaultShader { const char * ShaderName; const char * gettexelfunc; + const char * Defines; }; -// Note: the ShaderIndex enum in gl_shader.h needs to be updated whenever this array is modified. +// Note: the MaterialShaderIndex enum in gl_shader.h needs to be updated whenever this array is modified. static const FDefaultShader defaultshaders[]= { - {"Default", "shaders/glsl/func_normal.fp"}, - {"Warp 1", "shaders/glsl/func_warp1.fp"}, - {"Warp 2", "shaders/glsl/func_warp2.fp"}, - {"Brightmap","shaders/glsl/func_brightmap.fp"}, - {"No Texture", "shaders/glsl/func_notexture.fp"}, - {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp"}, - {"Smooth Fuzz", "shaders/glsl/fuzz_smooth.fp"}, - {"Swirly Fuzz", "shaders/glsl/fuzz_swirly.fp"}, - {"Translucent Fuzz", "shaders/glsl/fuzz_smoothtranslucent.fp"}, - {"Jagged Fuzz", "shaders/glsl/fuzz_jagged.fp"}, - {"Noise Fuzz", "shaders/glsl/fuzz_noise.fp"}, - {"Smooth Noise Fuzz", "shaders/glsl/fuzz_smoothnoise.fp"}, - {NULL,NULL} + {"Default", "shaders/glsl/func_normal.fp", ""}, + {"Warp 1", "shaders/glsl/func_warp1.fp", ""}, + {"Warp 2", "shaders/glsl/func_warp2.fp", ""}, + {"Brightmap","shaders/glsl/func_brightmap.fp", ""}, + {"Specular","shaders/glsl/func_normal.fp", "#define SPECULAR\n"}, + {"SpecularBrightmap","shaders/glsl/func_brightmap.fp", "#define SPECULAR\n"}, + {"PBR","shaders/glsl/func_normal.fp", "#define PBR\n"}, + {"PBRBrightmap","shaders/glsl/func_brightmap.fp", "#define PBR\n"}, + {"No Texture", "shaders/glsl/func_notexture.fp", ""}, + {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp", ""}, + {"Smooth Fuzz", "shaders/glsl/fuzz_smooth.fp", ""}, + {"Swirly Fuzz", "shaders/glsl/fuzz_swirly.fp", ""}, + {"Translucent Fuzz", "shaders/glsl/fuzz_smoothtranslucent.fp", ""}, + {"Jagged Fuzz", "shaders/glsl/fuzz_jagged.fp", ""}, + {"Noise Fuzz", "shaders/glsl/fuzz_noise.fp", ""}, + {"Smooth Noise Fuzz", "shaders/glsl/fuzz_smoothnoise.fp", ""}, + {NULL,NULL,NULL} }; static TArray usershaders; @@ -530,11 +536,11 @@ void FShaderCollection::CompileShaders(EPassType passType) for(int i=0;defaultshaders[i].ShaderName != NULL;i++) { - FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, true, passType); + FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, defaultshaders[i].Defines, true, passType); mMaterialShaders.Push(shc); - if (i <= SHADER_Brightmap) + if (i < SHADER_NoTexture) { - FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, false, passType); + FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, defaultshaders[i].Defines, false, passType); mMaterialShadersNAT.Push(shc); } } @@ -544,7 +550,7 @@ void FShaderCollection::CompileShaders(EPassType passType) FString name = ExtractFileBase(usershaders[i]); FName sfn = name; - FShader *shc = Compile(sfn, usershaders[i], true, passType); + FShader *shc = Compile(sfn, usershaders[i], "", true, passType); mMaterialShaders.Push(shc); } diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 6995c7b28..aa81808ec 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -365,7 +365,7 @@ class FShaderCollection public: FShaderCollection(EPassType passType); ~FShaderCollection(); - FShader *Compile(const char *ShaderName, const char *ShaderPath, bool usediscard, EPassType passType); + FShader *Compile(const char *ShaderName, const char *ShaderPath, const char *shaderdefines, bool usediscard, EPassType passType); int Find(const char *mame); FShader *BindEffect(int effect); void ApplyMatrices(VSMatrix *proj, VSMatrix *view); @@ -399,19 +399,23 @@ public: enum MaterialShaderIndex { - SHADER_Default = 0, - SHADER_Warp1 = 1, - SHADER_Warp2 = 2, - SHADER_Brightmap = 3, - SHADER_NoTexture = 4, - SHADER_BasicFuzz = 5, - SHADER_SmoothFuzz = 6, - SHADER_SwirlyFuzz = 7, - SHADER_TranslucentFuzz = 8, - SHADER_JaggedFuzz = 9, - SHADER_NoiseFuzz = 10, - SHADER_SmoothNoiseFuzz = 11, - FIRST_USER_SHADER = 12 + SHADER_Default, + SHADER_Warp1, + SHADER_Warp2, + SHADER_Brightmap, + SHADER_Specular, + SHADER_SpecularBrightmap, + SHADER_PBR, + SHADER_PBRBrightmap, + SHADER_NoTexture, + SHADER_BasicFuzz, + SHADER_SmoothFuzz, + SHADER_SwirlyFuzz, + SHADER_TranslucentFuzz, + SHADER_JaggedFuzz, + SHADER_NoiseFuzz, + SHADER_SmoothNoiseFuzz, + FIRST_USER_SHADER }; enum