gl.shader make the fog effect disappear
hi all.
I would like to use a shader on a gl.model.
There 's already fog effect apply to this model.
And when I tell the shader object to apply its shade, the fog (and light) effect disappears.
Here's the patch which shows the thing:
You'll need to restart it...
Has anyone know the way to avoid this issue ?
Thx.
Ad.
fog must be computed in the fragment shader.
relevant code from the orange book for linear fog computation with clamping:
gl_FogFragCoord = gl_FogCoord;
float fog = (gl_Fog.end - gl_FogFragCoord)) * gl_Fog.scale;
fog = clamp(fog, 0.0, 1.0);
//Applying fog to compute final color value
color = mix(vec3(gl_Fog.color), color, fog);
Thank you.
I must have done something wrong in the jxs ' structure:
Here's what Max told me:
• error: -- START GLSL INFO LOG: fp --
ERROR: 0:17: 'gl_FogCoord' : undeclared identifier
ERROR: 0:17: 'assign' : l-value required "gl_FogFragCoord" (can't modify a varying)
ERROR: 0:18: '=' : cannot convert from 'float' to '4-component vector of float'
ERROR: 0:18: ')' : syntax error syntax error
ERROR: Parser found no code to compile in source strings.
• error: -- END GLSL INFO LOG: fp --
• error: jit.gl.shader: GLSL program failed to compile.
whoops, it looks like fog should be a float, not a vec4.
i just posted some snippets from the book without testing, but the general idea is there.
Here's my jxs file:
Input scale
Input offset
Output scale
Output offset
void main( void )
{
vec4 v0 = texture2DRect(texture, texcoord0);
v0 = (v0*inscale)+inoffset;
vec4 result = abs(v0);
gl_FragColor = (result*outscale)+outoffset;
float fog = (gl_Fog.end - gl_FogFragCoord)) * gl_Fog.scale;
fog = clamp(fog, 0.0, 1.0);
vec4 color = mix(vec3(gl_Fog.color), color, fog);
}
]]>
Max is not yet happy:
• error: jit_xml_document: error reading file at byte offset 1303 / not well-formed (invalid token)
• error: line (48): >
• error: jit.gl.shader: error reading shader xml file 'Macintosh HD:/Users/adrienfontaine/Desktop/op.abs.jxs'
I am searching in a red book, but can't find anything about that !
Thanks for help.
Ad.
I don't know what the shader you posted is supposed to do, but if you're trying to have fog with a shader, here's an example:
--------------------------------------
--------------------------------------
mat.phong.1.light.fog.falloff.jxs
--------------------------------------
Ambient Multiplier
Diffuse Multiplier
Light Falloff Rate
Fog Density
Fog Density
Fog Color
Specular Multiplier
Specularity Adjustment
Thank you so much !!
It Works just fine.
Ad.