diff options
Diffstat (limited to 'src/renderergl2/glsl')
-rw-r--r-- | src/renderergl2/glsl/fogpass_vp.glsl | 12 | ||||
-rw-r--r-- | src/renderergl2/glsl/generic_vp.glsl | 33 | ||||
-rw-r--r-- | src/renderergl2/glsl/lightall_fp.glsl | 92 | ||||
-rw-r--r-- | src/renderergl2/glsl/lightall_vp.glsl | 26 |
4 files changed, 76 insertions, 87 deletions
diff --git a/src/renderergl2/glsl/fogpass_vp.glsl b/src/renderergl2/glsl/fogpass_vp.glsl index 40d14d9f..ce0e015b 100644 --- a/src/renderergl2/glsl/fogpass_vp.glsl +++ b/src/renderergl2/glsl/fogpass_vp.glsl @@ -85,13 +85,13 @@ float CalcFog(vec4 position) float s = dot(position, u_FogDistance) * 8.0; float t = dot(position, u_FogDepth); - bool eyeOutside = u_FogEyeT < 0.0; - float t2 = float(t >= float(eyeOutside)); + float eyeOutside = step(0.0, -u_FogEyeT); + float fogged = step(eyeOutside, t); + + t = max(t, 1e-6); + t *= fogged / (t - u_FogEyeT * eyeOutside); - if (eyeOutside) - t2 *= t / (t - u_FogEyeT); - - return s * t2; + return s * t; } void main() diff --git a/src/renderergl2/glsl/generic_vp.glsl b/src/renderergl2/glsl/generic_vp.glsl index 9ad4489b..429d62f5 100644 --- a/src/renderergl2/glsl/generic_vp.glsl +++ b/src/renderergl2/glsl/generic_vp.glsl @@ -93,7 +93,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st) } else if (u_DeformGen == DGEN_WAVE_TRIANGLE) { - func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0; + func = 1.0 - abs(4.0 * fract(value + 0.25) - 2.0); } else if (u_DeformGen == DGEN_WAVE_SAWTOOTH) { @@ -163,25 +163,20 @@ vec4 CalcColor(vec3 position, vec3 normal) color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0); } - vec3 toView = u_ViewOrigin - position; - vec3 viewer = normalize(u_ViewOrigin - position); + vec3 viewer = u_ViewOrigin - position; if (u_AlphaGen == AGEN_LIGHTING_SPECULAR) { - vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz); - vec3 halfangle = normalize(lightDir + viewer); + vec3 lightDir = normalize(vec3(-960.0, 1980.0, 96.0) - position.xyz); + vec3 reflected = -reflect(lightDir, normal); - color.a = pow(max(dot(normal, halfangle), 0.0), 8.0); + color.a = clamp(dot(reflected, normalize(viewer)), 0.0, 1.0); + color.a *= color.a; + color.a *= color.a; } else if (u_AlphaGen == AGEN_PORTAL) { - float alpha = length(toView) / u_PortalRange; - - color.a = clamp(alpha, 0.0, 1.0); - } - else if (u_AlphaGen == AGEN_FRESNEL) - { - color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5); + color.a = clamp(length(viewer) / u_PortalRange, 0.0, 1.0); } return color; @@ -194,13 +189,13 @@ float CalcFog(vec4 position) float s = dot(position, u_FogDistance) * 8.0; float t = dot(position, u_FogDepth); - bool eyeOutside = u_FogEyeT < 0.0; - float t2 = float(t >= float(eyeOutside)); - - if (eyeOutside) - t2 *= t / (t - u_FogEyeT); + float eyeOutside = step(0.0, -u_FogEyeT); + float fogged = step(eyeOutside, t); + + t = max(t, 1e-6); + t *= fogged / (t - u_FogEyeT * eyeOutside); - return s * t2; + return s * t; } #endif diff --git a/src/renderergl2/glsl/lightall_fp.glsl b/src/renderergl2/glsl/lightall_fp.glsl index 5bc7b11a..f223bb0c 100644 --- a/src/renderergl2/glsl/lightall_fp.glsl +++ b/src/renderergl2/glsl/lightall_fp.glsl @@ -176,17 +176,21 @@ float CalcBlinn(float NH, float shininess) #endif } -float CalcGGX(float NH, float shininess) +float CalcGGX(float NH, float gloss) { - // from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes.pdf - float m_sq = 2.0 / shininess; - float d = ((NH * NH) * (m_sq - 1.0) + 1.0); - return m_sq / (d * d); + // from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf + float a_sq = exp2(gloss * -13.0 + 1.0); + float d = ((NH * NH) * (a_sq - 1.0) + 1.0); + return a_sq / (d * d); } float CalcFresnel(float EH) { #if 1 + // From http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf + // not accurate, but fast + return exp2(-10.0 * EH); +#elif 0 // From http://seblagarde.wordpress.com/2012/06/03/spherical-gaussien-approximation-for-blinn-phong-phong-and-fresnel/ return exp2((-5.55473 * EH - 6.98316) * EH); #elif 0 @@ -196,42 +200,48 @@ float CalcFresnel(float EH) return blend; #else - return pow(1.0 - NH, 5.0); + return pow(1.0 - EH, 5.0); #endif } -float CalcVisibility(float NH, float NL, float NE, float EH, float shininess) +float CalcVisibility(float NH, float NL, float NE, float EH, float gloss) { -#if 0 - float geo = 2.0 * NH * min(NE, NL); - geo /= max(EH, geo); - - return geo; -#else - // Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes.pdf - // NL, NE in numerator factored out from cook-torrance +#if 1 + // From http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf + float k = min(1.0, gloss + 0.545); + return 1.0 / (k * EH * EH + (1.0 - k)); +#elif 0 + float roughness = exp2(gloss * -6.5); + #if defined(USE_GGX) - float roughness = sqrt(2.0 / (shininess + 2.0)); - float k = (roughness + 1.0); + // From http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf + float k = roughness + 1.0; k *= k * 0.125; #else - float k = 2.0 / sqrt(3.1415926535 * (shininess + 2.0)); + float k = roughness; #endif + // Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf + // NL, NE in numerator factored out from cook-torrance float k2 = 1.0 - k; float invGeo1 = NL * k2 + k; float invGeo2 = NE * k2 + k; return 1.0 / (invGeo1 * invGeo2); - #endif +#else + float geo = 2.0 * NH * min(NE, NL); + geo /= max(EH, geo); + + return geo; +#endif } -vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float shininess) +vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float gloss, float shininess) { float blinn = CalcBlinn(NH, shininess); vec3 fSpecular = mix(specular, vec3(1.0), CalcFresnel(EH)); - float vis = CalcVisibility(NH, NL, NE, EH, shininess); + float vis = CalcVisibility(NH, NL, NE, EH, gloss); #if defined(USE_BLINN) // Normalized Blinn-Phong @@ -330,13 +340,12 @@ void main() #endif vec4 diffuse = texture2D(u_DiffuseMap, texCoords); - -#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) - - #if defined(USE_LINEAR_LIGHT) +#if defined(USE_GAMMA2_TEXTURES) diffuse.rgb *= diffuse.rgb; - #endif +#endif + +#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_NORMALMAP) #if defined(SWIZZLE_NORMALMAP) N.xy = 2.0 * texture2D(u_NormalMap, texCoords).ag - vec2(1.0); @@ -361,9 +370,9 @@ void main() // surfaces not facing the light are always shadowed #if defined(USE_TANGENT_SPACE_LIGHT) - shadowValue *= float(var_PrimaryLightDir.z > 0.0); + shadowValue *= step(0.0, var_PrimaryLightDir.z); #else - shadowValue *= float(dot(var_Normal.xyz, var_PrimaryLightDir.xyz) > 0.0); + shadowValue *= step(0.0, dot(var_Normal.xyz, var_PrimaryLightDir.xyz)); #endif #if defined(SHADOWMAP_MODULATE) @@ -403,9 +412,9 @@ void main() #if defined(USE_SPECULARMAP) vec4 specular = texture2D(u_SpecularMap, texCoords); - #if defined(USE_LINEAR_LIGHT) + #if defined(USE_GAMMA2_TEXTURES) specular.rgb *= specular.rgb; - #endif + #endif #else vec4 specular = vec4(1.0); #endif @@ -414,7 +423,6 @@ void main() float gloss = specular.a; float shininess = exp2(gloss * 13.0); - float localOcclusion = clamp((diffuse.r + diffuse.g + diffuse.b) * 16.0f, 0.0, 1.0); #if defined(SPECULAR_IS_METALLIC) // diffuse is actually base color, and red of specular is metallicness @@ -431,10 +439,12 @@ void main() reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess); #if defined(r_deluxeSpecular) || defined(USE_LIGHT_VECTOR) + float adjGloss = gloss; float adjShininess = shininess; #if !defined(USE_LIGHT_VECTOR) - adjShininess = exp2(gloss * r_deluxeSpecular * 13.0); + adjGloss *= r_deluxeSpecular; + adjShininess = exp2(adjGloss * 13.0); #endif H = normalize(L + E); @@ -443,9 +453,9 @@ void main() NH = clamp(dot(N, H), 0.0, 1.0); #if !defined(USE_LIGHT_VECTOR) - reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjShininess) * r_deluxeSpecular * localOcclusion; + reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess) * r_deluxeSpecular; #else - reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjShininess) * localOcclusion; + reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, adjGloss, adjShininess); #endif #endif @@ -462,10 +472,6 @@ void main() vec3 cubeLightColor = textureCubeLod(u_CubeMap, R, 7.0 - gloss * 7.0).rgb; - #if defined(USE_LINEAR_LIGHT) - cubeLightColor *= cubeLightColor; - #endif - #if defined(USE_LIGHTMAP) cubeLightColor *= lightSample.rgb; #elif defined (USE_LIGHT_VERTEX) @@ -475,11 +481,11 @@ void main() #endif //gl_FragColor.rgb += diffuse.rgb * textureCubeLod(u_CubeMap, N, 7.0).rgb; - gl_FragColor.rgb += cubeLightColor * reflectance * localOcclusion; + gl_FragColor.rgb += cubeLightColor * reflectance; #endif #if defined(USE_PRIMARY_LIGHT) - L = normalize(var_PrimaryLightDir.xyz); + L = var_PrimaryLightDir.xyz; //normalize(var_PrimaryLightDir.xyz); NL = clamp(dot(N, L), 0.0, 1.0); H = normalize(L + E); @@ -487,7 +493,7 @@ void main() NH = clamp(dot(N, H), 0.0, 1.0); reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess); - reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, shininess); + reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, gloss, shininess); lightColor = u_PrimaryLightColor; // * CalcLightAttenuation(L, u_PrimaryLightDir.w); @@ -497,10 +503,6 @@ void main() gl_FragColor.rgb += lightColor * reflectance * NL; #endif - - #if defined(USE_LINEAR_LIGHT) - gl_FragColor.rgb = sqrt(gl_FragColor.rgb); - #endif gl_FragColor.a = diffuse.a; #else diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl index 8230b9db..d9655ebe 100644 --- a/src/renderergl2/glsl/lightall_vp.glsl +++ b/src/renderergl2/glsl/lightall_vp.glsl @@ -113,7 +113,7 @@ vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb) float phase = offTurb.w; vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy; - vec3 offsetPos = position * 0.0009765625; + vec3 offsetPos = position / 1024.0; offsetPos.x += offsetPos.z; vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI); @@ -183,7 +183,7 @@ void main() #if defined(USE_LIGHT_VECTOR) vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w); -#elif defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR) +#elif defined(USE_LIGHT) && !defined(USE_DELUXEMAP) vec3 L = attr_LightDirection; #if defined(USE_MODELMATRIX) L = (u_ModelMatrix * vec4(L, 0.0)).xyz; @@ -194,12 +194,10 @@ void main() var_TexCoords.zw = attr_TexCoord1.st; #endif + var_Color = u_VertColor * attr_Color + u_BaseColor; #if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT) - var_LightColor = u_VertColor.rgb * attr_Color.rgb; + var_LightColor = var_Color.rgb; var_Color.rgb = vec3(1.0); - var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a; -#else - var_Color = u_VertColor * attr_Color + u_BaseColor; #endif #if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT) @@ -209,14 +207,8 @@ void main() var_Color.rgb *= u_DirectedLight * attenuation * NL + u_AmbientLight; #endif -#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) - var_Normal.xyz = normal; - var_Tangent.xyz = tangent; - var_Bitangent.xyz = bitangent; -#endif - #if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP) - var_PrimaryLightDir.xyz = (u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w)); + var_PrimaryLightDir.xyz = u_PrimaryLightOrigin.xyz - (position * u_PrimaryLightOrigin.w); var_PrimaryLightDir.w = u_PrimaryLightRadius * u_PrimaryLightRadius; #endif @@ -229,7 +221,7 @@ void main() #endif #if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) - vec3 viewDir = (u_ViewOrigin - position); + vec3 viewDir = u_ViewOrigin - position; #endif #if defined(USE_TANGENT_SPACE_LIGHT) @@ -250,8 +242,8 @@ void main() #if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP) // store view direction in tangent space to save on varyings - var_Normal.w = viewDir.x; - var_Tangent.w = viewDir.y; - var_Bitangent.w = viewDir.z; + var_Normal = vec4(normal, viewDir.x); + var_Tangent = vec4(tangent, viewDir.y); + var_Bitangent = vec4(bitangent, viewDir.z); #endif } |