DXGL r294 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r293‎ | r294 | r295 >
Date:16:46, 31 December 2012
Author:admin
Status:new
Tags:
Comment:
Add fog equations.
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -270,6 +270,8 @@
271271 vec3 N;";
272272 static const char var_color[] = "vec4 color;\n";
273273 static const char var_xyzw[] = "vec4 xyzw;\n";
 274+static const char var_fogfactorvertex[] = "varying float fogfactor;\n";
 275+static const char var_fogfactorpixel[] = "float fogfactor;\n";
274276 // Operations
275277 static const char op_transform[] = "xyzw = vec4(xyz,1);\n\
276278 vec4 pos = gl_ModelViewProjectionMatrix*xyzw;\n\
@@ -297,6 +299,16 @@
298300 static const char op_texpassthru2str[] = "vec4(strX,1);\n";
299301 static const char op_texpassthru2strq[] = "strqX;\n";
300302 static const char op_texpassthru2null[] = "vec4(0,0,0,1);\n";
 303+static const char op_fogcoordstandard[] = "gl_FogFragCoord = (gl_ModelViewMatrix*gl_Vertex).z;\n";
 304+static const char op_fogcoordrange[] = "vec4 eyepos = gl_ModelViewMatrix*gl_Vertex;\n\
 305+vec3 eyepos3 = eyepos.xyz / eyepos.w;\n\
 306+gl_FragFogCoord = sqrt((eyepos3.x * eyepos3.x) + (eyepos3.y * eyepos3.y) + (eyepos3.z * eyepos3.z));\n";
 307+static const char op_foglinear[] = "fogfactor = (gl_Fog.end - gl_FogFragCoord) / (gl_Fog.end - glFog.start);\n";
 308+static const char op_fogexp[] = "fogfactor = 1 / exp(gl_FogFragCoord * gl_Fog.density);\n";
 309+static const char op_fogexp2[] = "fogfactor = 1 / exp(gl_FogFragCoord * gl_FogFragCoord *\n\
 310+gl_Fog.density * gl_Fog.density)\n";
 311+static const char op_fogclamp[] = "fogfactor = clamp(fogfactor,0.0,1.0);\n";
 312+static const char op_fogblend[] = "color = mix(color,gl_Fog.color,fogfactor);\n";
301313
302314 // Functions
303315 static const char func_dirlight[] = "void DirLight(in Light light)\n\