Skip to content

Commit

Permalink
fog shader is fixed for the polygon type: it mixes with background co…
Browse files Browse the repository at this point in the history
…lor instead of decreasing alpha channel
  • Loading branch information
vicrucann committed Nov 16, 2016
1 parent 0296d3c commit 39b32a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/cherish/Shaders/Polygon.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ uniform bool IsFogged;
uniform float FogMin;
uniform float FogMax;
uniform vec4 CameraEye;
uniform vec4 FogColor;

in VertexData{
vec4 mColor;
vec4 mVertex; // to calculate distance to camera eye
} VertexIn;

float getFogFactor(float d, float a)
float getFogFactor(float d)
{
if (d>=FogMax) return 0;
if (d<=FogMin) return a;
if (d>=FogMax) return 1;
if (d<=FogMin) return 0;

return (FogMax - d) / (FogMax - FogMin) * a;
return 1 - (FogMax - d) / (FogMax - FogMin);
}

void main(void)
{
float alpha = VertexIn.mColor.a;
vec4 color = VertexIn.mColor;
if (IsFogged){
float d = distance(CameraEye, VertexIn.mVertex);
alpha = getFogFactor(d, alpha);
float alpha = getFogFactor(d);
color = mix(color, FogColor, alpha);
}
gl_FragColor = vec4(VertexIn.mColor.rgb, alpha);

gl_FragColor = color;
//vec4(VertexIn.mColor.rgb, alpha);
}
4 changes: 4 additions & 0 deletions src/libSGControls/ProgramPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ bool ProgramPolygon::addPresetUniforms()
qCritical("Could not initialize fog min factor");
return false;
}
if (!this->addUniform<osg::Vec4f>("FogColor", osg::Uniform::FLOAT_VEC4, cher::BACKGROUND_CLR)){
qCritical("Could not initialize fog color uniform");
return false;
}

return true;
}

0 comments on commit 39b32a6

Please sign in to comment.