mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2025-04-10 19:15:14 +00:00
Fixed new 3D engine's fragment shader to work on some older GPUs by reducing the number of discard statements to one
This commit is contained in:
parent
4b184b05dc
commit
458684eb22
|
@ -54,86 +54,90 @@ static const char *fragmentShaderBasic =
|
||||||
|
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"vec4 tex1Data;\n"
|
"vec4 tex1Data;\n"
|
||||||
"vec4 colData;\n"
|
"vec4 colData;\n"
|
||||||
"vec4 finalData;\n"
|
"vec4 finalData;\n"
|
||||||
|
|
||||||
"tex1Data = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
"bool discardFragment = false;\n"
|
||||||
|
|
||||||
"if(textureEnabled==1) {\n"
|
"tex1Data = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
||||||
|
|
||||||
"tex1Data = texture2D( tex1, gl_TexCoord[0].st);\n"
|
"if(textureEnabled==1) {\n"
|
||||||
|
|
||||||
"if (microTexture==1) {\n"
|
"tex1Data = texture2D( tex1, gl_TexCoord[0].st);\n"
|
||||||
"vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * 4.0);\n"
|
|
||||||
"tex1Data = (tex1Data+tex2Data)/2.0;\n"
|
|
||||||
"}\n"
|
|
||||||
|
|
||||||
"if (alphaTest==1) {\n" // does it make any sense to do this later?
|
"if (microTexture==1) {\n"
|
||||||
"if (tex1Data.a < (8.0/16.0)) {\n"
|
"vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * 4.0);\n"
|
||||||
"discard;\n"
|
"tex1Data = (tex1Data+tex2Data)/2.0;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"}\n"
|
|
||||||
|
|
||||||
"if (textureAlpha == 0) {\n"
|
"if (alphaTest==1) {\n" // does it make any sense to do this later?
|
||||||
"tex1Data.a = 1.0;\n"
|
"if (tex1Data.a < (8.0/16.0)) {\n"
|
||||||
"}\n"
|
"discardFragment = true;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
"colData = gl_Color;\n"
|
"if (textureAlpha == 0) {\n"
|
||||||
|
"tex1Data.a = 1.0;\n"
|
||||||
|
"}\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
"finalData = tex1Data * colData;\n"
|
"colData = gl_Color;\n"
|
||||||
"if (finalData.a < (1.0/16.0)) {\n" // basically chuck out any totally transparent pixels value = 1/16 the smallest transparency level h/w supports
|
|
||||||
"discard;\n"
|
|
||||||
"}\n"
|
|
||||||
|
|
||||||
|
"finalData = tex1Data * colData;\n"
|
||||||
"if (lightEnable==1)\n"
|
"if (finalData.a < (1.0/16.0)) {\n" // basically chuck out any totally transparent pixels value = 1/16 the smallest transparency level h/w supports
|
||||||
"{\n"
|
"discardFragment = true;\n"
|
||||||
"vec3 lightIntensity;\n"
|
"}\n"
|
||||||
"vec3 sunVector;\n" // sun lighting vector (as reflecting away from vertex)
|
|
||||||
"float sunFactor;\n" // sun light projection along vertex normal (0.0 to 1.0)
|
|
||||||
|
|
||||||
// Real3D -> OpenGL view space convention (TO-DO: do this outside of shader)
|
"if (discardFragment) {\n"
|
||||||
"sunVector = lighting[0] * vec3(1.0, -1.0, -1.0);\n"
|
"discard;\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
"if (lightEnable==1) {\n"
|
||||||
|
"vec3 lightIntensity;\n"
|
||||||
|
"vec3 sunVector;\n" // sun lighting vector (as reflecting away from vertex)
|
||||||
|
"float sunFactor;\n" // sun light projection along vertex normal (0.0 to 1.0)
|
||||||
|
|
||||||
// Compute diffuse factor for sunlight
|
// Real3D -> OpenGL view space convention (TO-DO: do this outside of shader)
|
||||||
"sunFactor = max(dot(sunVector, fsViewNormal), 0.0);\n"
|
"sunVector = lighting[0] * vec3(1.0, -1.0, -1.0);\n"
|
||||||
|
|
||||||
// Total light intensity: sum of all components
|
// Compute diffuse factor for sunlight
|
||||||
"lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y);\n" // ambient + diffuse
|
"sunFactor = max(dot(sunVector, fsViewNormal), 0.0);\n"
|
||||||
|
|
||||||
"lightIntensity = clamp(lightIntensity,0.0,1.0);\n"
|
// Total light intensity: sum of all components
|
||||||
|
"lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y);\n" // ambient + diffuse
|
||||||
|
|
||||||
"vec2 ellipse;\n"
|
"lightIntensity = clamp(lightIntensity,0.0,1.0);\n"
|
||||||
"float insideSpot;\n"
|
|
||||||
|
|
||||||
// Compute spotlight and apply lighting
|
"vec2 ellipse;\n"
|
||||||
"ellipse = (gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw;\n"
|
"float insideSpot;\n"
|
||||||
"insideSpot = dot(ellipse, ellipse);\n"
|
|
||||||
|
|
||||||
"if ((insideSpot <= 1.0) && (-fsViewVertex.z >= spotRange.x)) {\n"
|
// Compute spotlight and apply lighting
|
||||||
"lightIntensity.rgb += (1.0 - insideSpot)*spotColor;\n"
|
"ellipse = (gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw;\n"
|
||||||
"}\n"
|
"insideSpot = dot(ellipse, ellipse);\n"
|
||||||
|
|
||||||
|
"if ((insideSpot <= 1.0) && (-fsViewVertex.z >= spotRange.x)) {\n"
|
||||||
"finalData.rgb *= lightIntensity;\n"
|
"lightIntensity.rgb += (1.0 - insideSpot)*spotColor;\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
"if (sunFactor > 0.0 && specularCoefficient > 0.0) {\n"
|
|
||||||
|
"finalData.rgb *= lightIntensity;\n"
|
||||||
|
|
||||||
"vec3 v = normalize(-fsViewVertex);\n"
|
"if (sunFactor > 0.0 && specularCoefficient > 0.0) {\n"
|
||||||
"vec3 h = normalize(sunVector + v);\n" // halfway vector
|
|
||||||
|
|
||||||
"float NdotHV = max(dot(fsViewNormal,h),0.0);\n"
|
"vec3 v = normalize(-fsViewVertex);\n"
|
||||||
|
"vec3 h = normalize(sunVector + v);\n" // halfway vector
|
||||||
|
|
||||||
"finalData.rgb += vec3(specularCoefficient * pow(NdotHV,shininess));\n"
|
"float NdotHV = max(dot(fsViewNormal,h),0.0);\n"
|
||||||
"}\n"
|
|
||||||
"}\n"
|
"finalData.rgb += vec3(specularCoefficient * pow(NdotHV,shininess));\n"
|
||||||
|
"}\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
|
||||||
"finalData.rgb = mix(finalData.rgb, fogColour, fsFogFactor);\n"
|
"finalData.rgb = mix(finalData.rgb, fogColour, fsFogFactor);\n"
|
||||||
|
|
||||||
"gl_FragColor = finalData;\n"
|
"gl_FragColor = finalData;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
R3DShader::R3DShader()
|
R3DShader::R3DShader()
|
||||||
|
|
Loading…
Reference in a new issue