Hi guys!
I try to solve flightgear clouds sorting problem
Clouds consists of billboards position and lighting calculated in vertex and
fragment program
here is screenshot in attachment
Maybe gurus give us quick solution
Our blend equation and alpha func and shaders
                _standardBlendFunc = new osg::BlendFunc;
                _standardBlendFunc->setSource(osg::BlendFunc::SRC_ALPHA);
        
_standardBlendFunc->setDestination(osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
                alphaFunc = new osg::AlphaFunc;
                alphaFunc->setFunction(osg::AlphaFunc::GREATER,0.3f);
                newst->setRenderBinDetails(9, "DepthSortedBin");

static char vertexShaderSource[] = 
    "#version 120\n"
    "\n"
    "varying float fogFactor;\n"
    "varying float alphaBlend;\n"
    "attribute float textureIndexX;\n"
    "attribute float textureIndexY;\n"
    "attribute float wScale;\n"
    "attribute float hScale;\n"
    "attribute float shade;\n"
    "void main(void)\n"
    "{\n"
        "//shade=1;\n"
        "//wScale=1;\n"
        "//hScale=1;\n"
        "//textureIndexX=0;\n"
        "//textureIndexY=0;\n"
    "  gl_TexCoord[0] = gl_MultiTexCoord0+ vec4(textureIndexX,
textureIndexY, 0.0, 0.0);\n"
    "  vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);\n"
    "  vec4 l  = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);\n"
    "  vec3 u = normalize(ep.xyz - l.xyz);\n"
// Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
// the columns of that matrix.
    "  vec3 absu = abs(u);\n"
    "  vec3 r = normalize(vec3(-u.y, u.x, 0));\n"
    "  vec3 w = cross(u, r);\n"
// Do the matrix multiplication by [ u r w pos]. Assume no
// scaling in the homogeneous component of pos.
    "  gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
    "  gl_Position.xyz = gl_Vertex.x * u * wScale;\n"
    "  gl_Position.xyz += gl_Vertex.y * r * hScale;\n"
    "  gl_Position.xyz += gl_Vertex.z * w;\n"
    "  gl_Position.xyz += gl_Color.xyz;\n"
// Determine a lighting normal based on the sprites position from the
// center of the cloud. 
    "  float n = dot(normalize(gl_LightSource[0].position.xyz),
normalize(mat3x3(gl_ModelViewMatrix) * gl_Position.xyz));\n"
// Determine the position - used for fog and shading calculations        
    "  vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);\n"
    "  float fogCoord = abs(ecPosition.z);\n"
// Final position of the sprite
    "  gl_Position = gl_ModelViewProjectionMatrix * gl_Position;\n"
// Limit the normal range from [0,1.0], and apply the shading (vertical
factor)
    "  n = min(smoothstep(-0.5, 0.5, n), shade);\n"
// This lighting normal is then used to mix between almost pure ambient (0)
and diffuse (1.0) light
    "  vec4 backlight = 0.8 * gl_LightSource[0].ambient + 0.2 *
gl_LightSource[0].diffuse;\n"
    "  gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n);\n"
    "  gl_FrontColor += gl_FrontLightModelProduct.sceneColor;\n"
    "  gl_FrontColor.a = smoothstep(10.0, 100.0, fogCoord);\n"
    "  gl_BackColor = gl_FrontColor;\n"
// Fog doesn't affect clouds as much as other objects.        
    "  fogFactor = exp( -gl_Fog.density * fogCoord);\n"
    "  fogFactor = clamp(fogFactor, 0.0, 1.0);\n"
// As we get within 100m of the sprite, it is faded out
    "  alphaBlend = smoothstep(10.0, 100.0, fogCoord);\n"
    "}\n";

static char fragmentShaderSource[] = 
    "uniform sampler2D baseTexture; \n"
    "varying float fogFactor;\n"
    "varying float alphaBlend;\n"
    "\n"
    "void main(void)\n"
    "{\n"
    "  vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);\n"
    "  vec4 finalColor = base * gl_Color;\n"
//    "  finalColor.a = min(alphaBlend, finalColor.a);\n"
    "  gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor );\n"
        " gl_FragColor=finalColor;\n"
    "}\n";

Thanx in advance
Bye

<<attachment: 1.jpg>>

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to