mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Added fog to shader
This commit is contained in:
parent
8366d90f96
commit
1d2a8bc58f
2 changed files with 24 additions and 2 deletions
|
@ -8,6 +8,10 @@ module.exports = [
|
|||
'uniform vec3 uLightDiffuse;',
|
||||
'uniform vec3 uLightSpecular;',
|
||||
'',
|
||||
'uniform vec3 uFogColor;',
|
||||
'uniform float uFogNear;',
|
||||
'uniform float uFogFar;',
|
||||
'',
|
||||
'uniform vec3 uMaterialAmbient;',
|
||||
'uniform vec3 uMaterialDiffuse;',
|
||||
'uniform vec3 uMaterialSpecular;',
|
||||
|
@ -39,7 +43,15 @@ module.exports = [
|
|||
'',
|
||||
' vec3 result = (ambient + diffuse + specular) * color.rgb;',
|
||||
'',
|
||||
' gl_FragColor = vec4(result, color.a);',
|
||||
' float depth = gl_FragCoord.z / gl_FragCoord.w;',
|
||||
'',
|
||||
' float fogFactor = smoothstep(uFogNear, uFogFar, depth);',
|
||||
'',
|
||||
' // gl_FragColor = vec4(result, color.a);',
|
||||
'',
|
||||
' gl_FragColor.rgb = mix(result.rgb, uFogColor, fogFactor);',
|
||||
'',
|
||||
' gl_FragColor.a = color.a;',
|
||||
'}',
|
||||
''
|
||||
].join('\n');
|
||||
|
|
|
@ -7,6 +7,10 @@ uniform vec3 uLightAmbient;
|
|||
uniform vec3 uLightDiffuse;
|
||||
uniform vec3 uLightSpecular;
|
||||
|
||||
uniform vec3 uFogColor;
|
||||
uniform float uFogNear;
|
||||
uniform float uFogFar;
|
||||
|
||||
uniform vec3 uMaterialAmbient;
|
||||
uniform vec3 uMaterialDiffuse;
|
||||
uniform vec3 uMaterialSpecular;
|
||||
|
@ -38,5 +42,11 @@ void main (void)
|
|||
|
||||
vec3 result = (ambient + diffuse + specular) * color.rgb;
|
||||
|
||||
gl_FragColor = vec4(result, color.a);
|
||||
float depth = gl_FragCoord.z / gl_FragCoord.w;
|
||||
|
||||
float fogFactor = smoothstep(uFogNear, uFogFar, depth);
|
||||
|
||||
gl_FragColor.rgb = mix(result.rgb, uFogColor, fogFactor);
|
||||
|
||||
gl_FragColor.a = color.a;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue