fix shader compilation

update_gitlab_rules
Cody Glassman 2 years ago
parent 2ea71fbc5c
commit 6a64f352a4

@ -2206,7 +2206,7 @@ namespace NifOsg
{ {
auto texprop = static_cast<const Nif::BSEffectShaderProperty*>(property); auto texprop = static_cast<const Nif::BSEffectShaderProperty*>(property);
bool shaderRequired = true; bool shaderRequired = true;
node->setUserValue("shaderPrefix", std::string("nv_nolighting")); node->setUserValue("shaderPrefix", std::string("bs/nolighting"));
node->setUserValue("shaderRequired", shaderRequired); node->setUserValue("shaderRequired", shaderRequired);
osg::StateSet* stateset = node->getOrCreateStateSet(); osg::StateSet* stateset = node->getOrCreateStateSet();
if (!texprop->mSourceTexture.empty()) if (!texprop->mSourceTexture.empty())

@ -37,6 +37,18 @@ namespace
throw std::runtime_error("unrecognized shader template name: " + templateName); throw std::runtime_error("unrecognized shader template name: " + templateName);
} }
std::string getRootPrefix(const std::string& path)
{
if (path.starts_with("lib"))
return "lib";
else if (path.starts_with("compatibility"))
return "compatibility";
else if (path.starts_with("core"))
return "core";
else
return "";
}
} }
namespace Shader namespace Shader
@ -129,11 +141,15 @@ namespace Shader
return false; return false;
} }
std::string includeFilename = source.substr(start + 1, end - (start + 1)); std::string includeFilename = source.substr(start + 1, end - (start + 1));
std::filesystem::path includePath
= shaderPath / std::filesystem::path(fileName).parent_path() / includeFilename;
if (!std::filesystem::exists(includePath)) // Check if this include is a relative path
includePath = shaderPath / includeFilename; // TODO: We shouldn't be relying on soft-coded root prefixes, just check if the path exists and fallback to
// searching root if it doesn't
if (getRootPrefix(includeFilename).empty())
includeFilename
= Files::pathToUnicodeString(std::filesystem::path(fileName).parent_path() / includeFilename);
std::filesystem::path includePath = shaderPath / includeFilename;
// Determine the line number that will be used for the #line directive following the included source // Determine the line number that will be used for the #line directive following the included source
size_t lineDirectivePosition = source.rfind("#line", foundPos); size_t lineDirectivePosition = source.rfind("#line", foundPos);
@ -504,8 +520,7 @@ namespace Shader
// TODO: Implement mechanism to switch to core or compatibility profile shaders. // TODO: Implement mechanism to switch to core or compatibility profile shaders.
// This logic is temporary until core support is supported. // This logic is temporary until core support is supported.
if (!templateName.starts_with("lib") && !templateName.starts_with("compatibility") if (getRootPrefix(templateName).empty())
&& !templateName.starts_with("core"))
templateName = "compatibility/" + templateName; templateName = "compatibility/" + templateName;
// read the template if we haven't already // read the template if we haven't already

@ -9,6 +9,8 @@
#extension GL_EXT_gpu_shader4: require #extension GL_EXT_gpu_shader4: require
#endif #endif
#define PER_PIXEL_LIGHTING 1
#if @diffuseMap #if @diffuseMap
uniform sampler2D diffuseMap; uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV; varying vec2 diffuseMapUV;
@ -28,23 +30,21 @@ varying vec4 passTangent;
varying float euclideanDepth; varying float euclideanDepth;
varying float linearDepth; varying float linearDepth;
#define PER_PIXEL_LIGHTING 1
varying vec3 passViewPos; varying vec3 passViewPos;
varying vec3 passNormal; varying vec3 passNormal;
uniform vec2 screenRes; uniform vec2 screenRes;
uniform float far; uniform float far;
uniform float alphaRef; uniform float alphaRef;
uniform float emissiveMult;
uniform float specStrength;
#include "vertexcolors.glsl"
#include "shadows_fragment.glsl"
#include "lib/light/lighting.glsl" #include "lib/light/lighting.glsl"
#include "lib/material/alpha.glsl" #include "lib/material/alpha.glsl"
#include "fog.glsl"
uniform float emissiveMult; #include "compatibility/vertexcolors.glsl"
uniform float specStrength; #include "compatibility/shadows_fragment.glsl"
#include "compatibility/fog.glsl"
void main() void main()
{ {
@ -59,7 +59,7 @@ void main()
vec4 diffuseColor = getDiffuseColor(); vec4 diffuseColor = getDiffuseColor();
gl_FragData[0].a *= diffuseColor.a; gl_FragData[0].a *= diffuseColor.a;
gl_FragData[0].a = alphaTest(gl_FragData[0].a); gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
#if @normalMap #if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV); vec4 normalTex = texture2D(normalMap, normalMapUV);

@ -8,7 +8,10 @@
#extension GL_EXT_gpu_shader4: require #extension GL_EXT_gpu_shader4: require
#endif #endif
#define PER_PIXEL_LIGHTING 1
#include "lib/core/vertex.h.glsl" #include "lib/core/vertex.h.glsl"
#if @diffuseMap #if @diffuseMap
varying vec2 diffuseMapUV; varying vec2 diffuseMapUV;
#endif #endif
@ -28,13 +31,12 @@ varying float linearDepth;
varying vec3 passViewPos; varying vec3 passViewPos;
varying vec3 passNormal; varying vec3 passNormal;
#define PER_PIXEL_LIGHTING 1
#include "vertexcolors.glsl"
#include "shadows_vertex.glsl"
#include "lib/light/lighting.glsl" #include "lib/light/lighting.glsl"
#include "lib/view/depth.glsl" #include "lib/view/depth.glsl"
#include "compatibility/vertexcolors.glsl"
#include "compatibility/shadows_vertex.glsl"
void main(void) void main(void)
{ {
gl_Position = modelToClip(gl_Vertex); gl_Position = modelToClip(gl_Vertex);

@ -1,6 +1,10 @@
#version 120 #version 120
#pragma import_defines(FORCE_OPAQUE) #pragma import_defines(FORCE_OPAQUE)
#if @useUBO
#extension GL_ARB_uniform_buffer_object : require
#endif
#if @useGPUShader4 #if @useGPUShader4
#extension GL_EXT_gpu_shader4: require #extension GL_EXT_gpu_shader4: require
#endif #endif
@ -10,20 +14,22 @@ uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV; varying vec2 diffuseMapUV;
#endif #endif
varying vec3 passNormal;
varying float euclideanDepth; varying float euclideanDepth;
varying float linearDepth; varying float linearDepth;
varying float passFalloff;
uniform bool useFalloff;
uniform vec2 screenRes; uniform vec2 screenRes;
uniform bool useFalloff;
uniform float emissiveMult; uniform float emissiveMult;
uniform float far; uniform float far;
uniform float alphaRef; uniform float alphaRef;
varying float passFalloff;
#include "lib/material/alpha.glsl" #include "lib/material/alpha.glsl"
#include "vertexcolors.glsl"
#include "fog.glsl" #include "compatibility/vertexcolors.glsl"
#include "compatibility/fog.glsl"
#include "compatibility/shadows_fragment.glsl"
void main() void main()
{ {
@ -43,11 +49,18 @@ void main()
gl_FragData[0].rgb *= emissionColor.rgb * emissiveMult; gl_FragData[0].rgb *= emissionColor.rgb * emissiveMult;
gl_FragData[0].a *= emissionColor.a * emissionColor.a; // sic gl_FragData[0].a *= emissionColor.a * emissionColor.a; // sic
gl_FragData[0].a = alphaTest(gl_FragData[0].a); gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
#if defined(FORCE_OPAQUE) && FORCE_OPAQUE #if defined(FORCE_OPAQUE) && FORCE_OPAQUE
gl_FragData[0].a = 1.0; gl_FragData[0].a = 1.0;
#endif #endif
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far); #if !defined(FORCE_OPAQUE) && !@disableNormals
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
#endif
applyShadowDebugOverlay();
} }

@ -1,42 +1,48 @@
#version 120 #version 120
#if @useUBO
#extension GL_ARB_uniform_buffer_object : require
#endif
#if @useGPUShader4
#extension GL_EXT_gpu_shader4: require
#endif
#include "lib/core/vertex.h.glsl" #include "lib/core/vertex.h.glsl"
#if @diffuseMap #if @diffuseMap
varying vec2 diffuseMapUV; varying vec2 diffuseMapUV;
#endif #endif
#if @radialFog varying vec3 passNormal;
varying float euclideanDepth; varying float euclideanDepth;
#else
varying float linearDepth; varying float linearDepth;
#endif varying float passFalloff;
uniform bool useFalloff; uniform bool useFalloff;
uniform vec4 falloffParams; uniform vec4 falloffParams;
varying float passFalloff;
#include "vertexcolors.glsl"
#include "lib/view/depth.glsl" #include "lib/view/depth.glsl"
#include "compatibility/vertexcolors.glsl"
#include "compatibility/shadows_vertex.glsl"
void main(void) void main(void)
{ {
gl_Position = modelToClip(gl_Vertex); gl_Position = modelToClip(gl_Vertex);
vec4 viewPos = modelToView(gl_Vertex); vec4 viewPos = modelToView(gl_Vertex);
gl_ClipVertex = viewPos; gl_ClipVertex = viewPos;
#if @radialFog
euclideanDepth = length(viewPos.xyz); euclideanDepth = length(viewPos.xyz);
#else
linearDepth = getLinearDepth(gl_Position.z, viewPos.z); linearDepth = getLinearDepth(gl_Position.z, viewPos.z);
#endif
#if @diffuseMap #if @diffuseMap
diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy; diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy;
#endif #endif
passColor = gl_Color; passColor = gl_Color;
passNormal = gl_Normal.xyz;
if (useFalloff) if (useFalloff)
{ {
vec3 viewNormal = gl_NormalMatrix * normalize(gl_Normal.xyz); vec3 viewNormal = gl_NormalMatrix * normalize(gl_Normal.xyz);
@ -53,4 +59,9 @@ void main(void)
{ {
passFalloff = 1.0; passFalloff = 1.0;
} }
#if @shadows_enabled
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
setupShadowCoords(viewPos, viewNormal);
#endif
} }

@ -70,7 +70,7 @@ void main()
if (euclideanDepth > @groundcoverFadeStart) if (euclideanDepth > @groundcoverFadeStart)
gl_FragData[0].a *= 1.0-smoothstep(@groundcoverFadeStart, @groundcoverFadeEnd, euclideanDepth); gl_FragData[0].a *= 1.0-smoothstep(@groundcoverFadeStart, @groundcoverFadeEnd, euclideanDepth);
gl_FragData[0].a = alphaTest(gl_FragData[0].a); gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
float shadowing = unshadowedLightRatio(linearDepth); float shadowing = unshadowedLightRatio(linearDepth);

@ -84,12 +84,13 @@ varying vec3 passNormal;
#define ADDITIVE_BLENDING #define ADDITIVE_BLENDING
#endif #endif
#include "vertexcolors.glsl"
#include "shadows_fragment.glsl"
#include "lib/light/lighting.glsl" #include "lib/light/lighting.glsl"
#include "lib/material/parallax.glsl" #include "lib/material/parallax.glsl"
#include "lib/material/alpha.glsl" #include "lib/material/alpha.glsl"
#include "fog.glsl" #include "fog.glsl"
#include "vertexcolors.glsl"
#include "shadows_fragment.glsl"
#if @softParticles #if @softParticles
#include "lib/particle/soft.glsl" #include "lib/particle/soft.glsl"
@ -164,7 +165,7 @@ vec3 viewNormal = normalize(gl_NormalMatrix * normal);
gl_FragData[0].a *= coveragePreservingAlphaScale(darkMap, darkMapUV); gl_FragData[0].a *= coveragePreservingAlphaScale(darkMap, darkMapUV);
#endif #endif
gl_FragData[0].a = alphaTest(gl_FragData[0].a); gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
#if @detailMap #if @detailMap
gl_FragData[0].xyz *= texture2D(detailMap, detailMapUV).xyz * 2.0; gl_FragData[0].xyz *= texture2D(detailMap, detailMapUV).xyz * 2.0;

@ -23,7 +23,7 @@ void main()
else else
gl_FragData[0].a = alphaPassthrough; gl_FragData[0].a = alphaPassthrough;
gl_FragData[0].a = alphaTest(gl_FragData[0].a); gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
// Prevent translucent things casting shadow (including the player using an invisibility effect). // Prevent translucent things casting shadow (including the player using an invisibility effect).
// This replaces alpha blending, which obviously doesn't work with depth buffers // This replaces alpha blending, which obviously doesn't work with depth buffers

@ -33,10 +33,10 @@ float coveragePreservingAlphaScale(sampler2D diffuseMap, vec2 uv)
#endif #endif
} }
float alphaTest(float alpha) float alphaTest(float alpha, float ref)
{ {
#if @alphaToCoverage #if @alphaToCoverage
float coverageAlpha = (alpha - clamp(alphaRef, 0.0001, 0.9999)) / max(fwidth(alpha), 0.0001) + 0.5; float coverageAlpha = (alpha - clamp(ref, 0.0001, 0.9999)) / max(fwidth(alpha), 0.0001) + 0.5;
// Some functions don't make sense with A2C or are a pain to think about and no meshes use them anyway // Some functions don't make sense with A2C or are a pain to think about and no meshes use them anyway
// Use regular alpha testing in such cases until someone complains. // Use regular alpha testing in such cases until someone complains.
@ -45,14 +45,14 @@ float alphaTest(float alpha)
#elif @alphaFunc == FUNC_LESS #elif @alphaFunc == FUNC_LESS
return 1.0 - coverageAlpha; return 1.0 - coverageAlpha;
#elif @alphaFunc == FUNC_EQUAL #elif @alphaFunc == FUNC_EQUAL
if (alpha != alphaRef) if (alpha != ref)
discard; discard;
#elif @alphaFunc == FUNC_LEQUAL #elif @alphaFunc == FUNC_LEQUAL
return 1.0 - coverageAlpha; return 1.0 - coverageAlpha;
#elif @alphaFunc == FUNC_GREATER #elif @alphaFunc == FUNC_GREATER
return coverageAlpha; return coverageAlpha;
#elif @alphaFunc == FUNC_NOTEQUAL #elif @alphaFunc == FUNC_NOTEQUAL
if (alpha == alphaRef) if (alpha == ref)
discard; discard;
#elif @alphaFunc == FUNC_GEQUAL #elif @alphaFunc == FUNC_GEQUAL
return coverageAlpha; return coverageAlpha;
@ -61,22 +61,22 @@ float alphaTest(float alpha)
#if @alphaFunc == FUNC_NEVER #if @alphaFunc == FUNC_NEVER
discard; discard;
#elif @alphaFunc == FUNC_LESS #elif @alphaFunc == FUNC_LESS
if (alpha >= alphaRef) if (alpha >= ref)
discard; discard;
#elif @alphaFunc == FUNC_EQUAL #elif @alphaFunc == FUNC_EQUAL
if (alpha != alphaRef) if (alpha != ref)
discard; discard;
#elif @alphaFunc == FUNC_LEQUAL #elif @alphaFunc == FUNC_LEQUAL
if (alpha > alphaRef) if (alpha > ref)
discard; discard;
#elif @alphaFunc == FUNC_GREATER #elif @alphaFunc == FUNC_GREATER
if (alpha <= alphaRef) if (alpha <= ref)
discard; discard;
#elif @alphaFunc == FUNC_NOTEQUAL #elif @alphaFunc == FUNC_NOTEQUAL
if (alpha == alphaRef) if (alpha == ref)
discard; discard;
#elif @alphaFunc == FUNC_GEQUAL #elif @alphaFunc == FUNC_GEQUAL
if (alpha < alphaRef) if (alpha < ref)
discard; discard;
#endif #endif
#endif #endif

Loading…
Cancel
Save