diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-06-21 18:13:23 -0400 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-06-21 18:14:07 -0400 |
commit | 1132ddbfbb93bd91b4d3b3ee368f5026112c4713 (patch) | |
tree | 9233a175276fbf7318c8e2cf6c85abb49d8ec5e0 /src/library_gl.js | |
parent | 0a014b6a0a925abc026195430ab18fb340e5ae4e (diff) |
Compute the fog in the fragment shader
This makes the fog a bit more precise, and matches how native OpenGL
calculates the fog value. But it also means that it would be a bit more
expensive to calculate because it is calculated once per pixel.
Diffstat (limited to 'src/library_gl.js')
-rw-r--r-- | src/library_gl.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 538c89c3..e6e31826 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -1588,16 +1588,7 @@ var LibraryGL = { (hasTextures ? 'varying vec2 v_texCoord; \n' : '') + 'varying vec4 v_color; \n' + (colorSize ? 'attribute vec4 a_color; \n': 'uniform vec4 u_color; \n') + - (GLEmulation.fogEnabled ? ( - 'varying float v_fogFragCoord; \n' + - 'uniform float u_fogEnd; \n' + - 'uniform float u_fogScale; \n' + - 'float ffog(in float ecDistance) { \n' + - fogFormula + - ' fog = clamp(fog, 0.0, 1.0); \n' + - ' return fog; \n' + - '} \n' - ) : '') + + (GLEmulation.fogEnabled ? 'varying float v_fogFragCoord; \n' : '') + 'uniform mat4 u_modelView; \n' + 'uniform mat4 u_projection; \n' + 'void main() \n' + @@ -1606,7 +1597,7 @@ var LibraryGL = { ' gl_Position = u_projection * ecPosition; \n' + (hasTextures ? 'v_texCoord = a_texCoord0; \n' : '') + (colorSize ? 'v_color = a_color; \n' : 'v_color = u_color; \n') + - (GLEmulation.fogEnabled ? 'v_fogFragCoord = ffog(ecPosition.z);\n' : '') + + (GLEmulation.fogEnabled ? 'v_fogFragCoord = ecPosition.z;\n' : '') + '} \n'); Module.ctx.compileShader(this.vertexShader); @@ -1616,14 +1607,21 @@ var LibraryGL = { 'uniform sampler2D u_texture; \n' + 'varying vec4 v_color; \n' + (GLEmulation.fogEnabled ? ( - 'varying float v_fogFragCoord; \n' + - 'uniform vec4 u_fogColor; \n' + 'varying float v_fogFragCoord; \n' + + 'uniform vec4 u_fogColor; \n' + + 'uniform float u_fogEnd; \n' + + 'uniform float u_fogScale; \n' + + 'float ffog(in float ecDistance) { \n' + + fogFormula + + ' fog = clamp(fog, 0.0, 1.0); \n' + + ' return fog; \n' + + '} \n' ) : '') + 'void main() \n' + '{ \n' + (hasTextures ? 'gl_FragColor = v_color * texture2D( u_texture, v_texCoord );\n' : 'gl_FragColor = v_color;\n') + - (GLEmulation.fogEnabled ? 'gl_FragColor = vec4(mix(vec3(u_fogColor), vec3(gl_FragColor), v_fogFragCoord), gl_FragColor.a); \n' : '') + + (GLEmulation.fogEnabled ? 'gl_FragColor = vec4(mix(vec3(u_fogColor), vec3(gl_FragColor), ffog(v_fogFragCoord)), gl_FragColor.a); \n' : '') + '} \n'); Module.ctx.compileShader(this.fragmentShader); |