mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-02 22:11:22 +00:00
world shader: avoid matrix multiplication in the fragment shader
alias shader: sync fog implementation with world shader Thanks to Axel for the suggestion. Add a FIXME where our shader differs from vkQuake in treatment of alpha transparent faces + fog. see: https://sourceforge.net/p/quakespasm/bugs/24/ https://github.com/Novum/vkQuake/blob/master/Shaders/world.vert https://github.com/Novum/vkQuake/blob/master/Shaders/world.frag git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1546 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
a3f395b0f7
commit
ec4b6115d1
2 changed files with 15 additions and 17 deletions
|
@ -140,6 +140,9 @@ void GLAlias_CreateShaders (void)
|
||||||
"attribute vec3 Pose1Normal;\n"
|
"attribute vec3 Pose1Normal;\n"
|
||||||
"attribute vec4 Pose2Vert;\n"
|
"attribute vec4 Pose2Vert;\n"
|
||||||
"attribute vec3 Pose2Normal;\n"
|
"attribute vec3 Pose2Normal;\n"
|
||||||
|
"\n"
|
||||||
|
"varying float FogFragCoord;\n"
|
||||||
|
"\n"
|
||||||
"float r_avertexnormal_dot(vec3 vertexnormal) // from MH \n"
|
"float r_avertexnormal_dot(vec3 vertexnormal) // from MH \n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float dot = dot(vertexnormal, ShadeVector);\n"
|
" float dot = dot(vertexnormal, ShadeVector);\n"
|
||||||
|
@ -152,14 +155,12 @@ void GLAlias_CreateShaders (void)
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_TexCoord[0] = TexCoords;\n"
|
" gl_TexCoord[0] = TexCoords;\n"
|
||||||
" vec4 lerpedVert = mix(Pose1Vert, Pose2Vert, Blend);\n"
|
" vec4 lerpedVert = mix(vec4(Pose1Vert.xyz, 1.0), vec4(Pose2Vert.xyz, 1.0), Blend);\n"
|
||||||
" gl_Position = gl_ModelViewProjectionMatrix * lerpedVert;\n"
|
" gl_Position = gl_ModelViewProjectionMatrix * lerpedVert;\n"
|
||||||
|
" FogFragCoord = gl_Position.w;\n"
|
||||||
" float dot1 = r_avertexnormal_dot(Pose1Normal);\n"
|
" float dot1 = r_avertexnormal_dot(Pose1Normal);\n"
|
||||||
" float dot2 = r_avertexnormal_dot(Pose2Normal);\n"
|
" float dot2 = r_avertexnormal_dot(Pose2Normal);\n"
|
||||||
" gl_FrontColor = LightColor * vec4(vec3(mix(dot1, dot2, Blend)), 1.0);\n"
|
" gl_FrontColor = LightColor * vec4(vec3(mix(dot1, dot2, Blend)), 1.0);\n"
|
||||||
" // fog\n"
|
|
||||||
" vec3 ecPosition = vec3(gl_ModelViewMatrix * lerpedVert);\n"
|
|
||||||
" gl_FogFragCoord = abs(ecPosition.z);\n"
|
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
const GLchar *fragSource = \
|
const GLchar *fragSource = \
|
||||||
|
@ -170,6 +171,9 @@ void GLAlias_CreateShaders (void)
|
||||||
"uniform bool UseFullbrightTex;\n"
|
"uniform bool UseFullbrightTex;\n"
|
||||||
"uniform bool UseOverbright;\n"
|
"uniform bool UseOverbright;\n"
|
||||||
"uniform bool UseAlphaTest;\n"
|
"uniform bool UseAlphaTest;\n"
|
||||||
|
"\n"
|
||||||
|
"varying float FogFragCoord;\n"
|
||||||
|
"\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n"
|
" vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n"
|
||||||
|
@ -181,11 +185,10 @@ void GLAlias_CreateShaders (void)
|
||||||
" if (UseFullbrightTex)\n"
|
" if (UseFullbrightTex)\n"
|
||||||
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
|
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
|
||||||
" result = clamp(result, 0.0, 1.0);\n"
|
" result = clamp(result, 0.0, 1.0);\n"
|
||||||
" // apply GL_EXP2 fog (from the orange book)\n"
|
" float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n"
|
||||||
" float fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n"
|
|
||||||
" fog = clamp(fog, 0.0, 1.0);\n"
|
" fog = clamp(fog, 0.0, 1.0);\n"
|
||||||
" result = mix(gl_Fog.color, result, fog);\n"
|
" result = mix(gl_Fog.color, result, fog);\n"
|
||||||
" result.a = gl_Color.a;\n"
|
" result.a = gl_Color.a;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
|
||||||
" gl_FragColor = result;\n"
|
" gl_FragColor = result;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|
|
@ -832,14 +832,14 @@ void GLWorld_CreateShaders (void)
|
||||||
"attribute vec2 TexCoords;\n"
|
"attribute vec2 TexCoords;\n"
|
||||||
"attribute vec2 LMCoords;\n"
|
"attribute vec2 LMCoords;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"varying vec3 VertVarying;\n"
|
"varying float FogFragCoord;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_TexCoord[0] = vec4(TexCoords, 0.0, 0.0);\n"
|
" gl_TexCoord[0] = vec4(TexCoords, 0.0, 0.0);\n"
|
||||||
" gl_TexCoord[1] = vec4(LMCoords, 0.0, 0.0);\n"
|
" gl_TexCoord[1] = vec4(LMCoords, 0.0, 0.0);\n"
|
||||||
" gl_Position = gl_ModelViewProjectionMatrix * vec4(Vert, 1.0);\n"
|
" gl_Position = gl_ModelViewProjectionMatrix * vec4(Vert, 1.0);\n"
|
||||||
" VertVarying = Vert;\n"
|
" FogFragCoord = gl_Position.w;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
const GLchar *fragSource = \
|
const GLchar *fragSource = \
|
||||||
|
@ -853,7 +853,7 @@ void GLWorld_CreateShaders (void)
|
||||||
"uniform bool UseAlphaTest;\n"
|
"uniform bool UseAlphaTest;\n"
|
||||||
"uniform float Alpha;\n"
|
"uniform float Alpha;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"varying vec3 VertVarying;\n"
|
"varying float FogFragCoord;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -866,15 +866,10 @@ void GLWorld_CreateShaders (void)
|
||||||
" if (UseFullbrightTex)\n"
|
" if (UseFullbrightTex)\n"
|
||||||
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
|
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
|
||||||
" result = clamp(result, 0.0, 1.0);\n"
|
" result = clamp(result, 0.0, 1.0);\n"
|
||||||
" // apply GL_EXP2 fog (from the orange book)\n"
|
" float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n"
|
||||||
" // needs to be done fully in the fragment shader to match fixed-function's quality\n"
|
|
||||||
" // (visible on large polygons / large texture scales)\n"
|
|
||||||
" vec3 ecPosition = vec3(gl_ModelViewMatrix * vec4(VertVarying, 1.0));\n"
|
|
||||||
" float fogFragCoord = abs(ecPosition.z);\n"
|
|
||||||
" float fog = exp(-gl_Fog.density * gl_Fog.density * fogFragCoord * fogFragCoord);\n"
|
|
||||||
" fog = clamp(fog, 0.0, 1.0);\n"
|
" fog = clamp(fog, 0.0, 1.0);\n"
|
||||||
" result = mix(gl_Fog.color, result, fog);\n"
|
" result = mix(gl_Fog.color, result, fog);\n"
|
||||||
" result.a = Alpha;\n"
|
" result.a = Alpha;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
|
||||||
" gl_FragColor = result;\n"
|
" gl_FragColor = result;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue