kordova
2006.07.10, 12:53 PM
I have not gotten any assistance on gdev so perhaps someone here can be of assistance.
I have modified the particle system example from the orange book and found that the built-in fog did not work with the shaders. I altered them and found that it worked, but only if I commented out all the lines assigning values to Color except where Background is assigned.
What exactly am I missing as to why assigning a color in the vertex shader breaks fog support?
Vertex Shader:
uniform float Time;
uniform vec4 Background;
attribute vec3 Velocity;
attribute float StartTime;
varying vec4 Color;
void main( void ) {
vec4 vert;
vec4 ecPosition = ftransform( );
gl_FogFragCoord = length( ecPosition );
float t = Time - StartTime;
if ( t >= 0.0 ) {
vert = gl_Vertex + vec4( Velocity * t, 0.0 );
vert.y -= 4.9 * t * t;
float highestTime = ( Velocity.y / 9.8 );
// Particle is falling?
if ( t > highestTime ) {
float diff = 1.0 - (( t - highestTime )/highestTime );
if ( diff <= .9 ) diff += .1;
//Color = vec4( gl_Color.rgb * diff, diff );
}
else {
//Color = gl_Color;
}
}
// Animation has not yet started
else {
vert = gl_Vertex;
Color = Background;
}
gl_Position = gl_ModelViewProjectionMatrix * vert;
}
Fragment Shader:
varying vec4 Color;
void main( void ) {
float fog;
const float LOG2E = 1.442695;
fog = exp2( -gl_Fog.density * gl_Fog.density *
gl_FogFragCoord * gl_FogFragCoord * LOG2E );
fog = clamp( fog, 0.0, 1.0 );
//fog = 0.0; // Uncomment this to prove that fog _can_ work
vec3 color = mix( vec3( gl_Fog.color ), Color.rgb, fog );
gl_FragColor = vec4( color, Color.a );
}
Thanks for any assistance.
I have modified the particle system example from the orange book and found that the built-in fog did not work with the shaders. I altered them and found that it worked, but only if I commented out all the lines assigning values to Color except where Background is assigned.
What exactly am I missing as to why assigning a color in the vertex shader breaks fog support?
Vertex Shader:
uniform float Time;
uniform vec4 Background;
attribute vec3 Velocity;
attribute float StartTime;
varying vec4 Color;
void main( void ) {
vec4 vert;
vec4 ecPosition = ftransform( );
gl_FogFragCoord = length( ecPosition );
float t = Time - StartTime;
if ( t >= 0.0 ) {
vert = gl_Vertex + vec4( Velocity * t, 0.0 );
vert.y -= 4.9 * t * t;
float highestTime = ( Velocity.y / 9.8 );
// Particle is falling?
if ( t > highestTime ) {
float diff = 1.0 - (( t - highestTime )/highestTime );
if ( diff <= .9 ) diff += .1;
//Color = vec4( gl_Color.rgb * diff, diff );
}
else {
//Color = gl_Color;
}
}
// Animation has not yet started
else {
vert = gl_Vertex;
Color = Background;
}
gl_Position = gl_ModelViewProjectionMatrix * vert;
}
Fragment Shader:
varying vec4 Color;
void main( void ) {
float fog;
const float LOG2E = 1.442695;
fog = exp2( -gl_Fog.density * gl_Fog.density *
gl_FogFragCoord * gl_FogFragCoord * LOG2E );
fog = clamp( fog, 0.0, 1.0 );
//fog = 0.0; // Uncomment this to prove that fog _can_ work
vec3 color = mix( vec3( gl_Fog.color ), Color.rgb, fog );
gl_FragColor = vec4( color, Color.a );
}
Thanks for any assistance.