I don't have OSG code but I do have some GLSL stuff I was playing with a while back in another package... it should plug in pretty easily. It's not the prettiest code as I was experimenting with lots of different things and my skills are dwarfed by many on this list. There are some commented out sections since it was in flux and partially converted from regular bump-mapping as I recall.

Anyway, I've attached my vertex and fragment shaders for my parallax bump-mapping stuff.

For setup it needs tangent vectors for each of the vertexes... it expects them in the color component of the vertex. It also needs three textures: decal, height map, and normal map.

I hard-coded the lighting for two lights. It's possible I still have some stuff wrong in there. Any returned improvements are welcome as I eventually plan to get back to this.

Hope it is useful in some small way. It is just the product of a weekend's worth of my time, the web, and being intimate with the orange book. :)

-Paul

Zach Deedler wrote:
Anybody have any parallax bump mapping examples for OSG?

This sort of algorithm may work for plowing:
http://www.simcreator.com/clips/deformable_snow.wmv


Zach

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Speed
Sent: Monday, April 16, 2007 22:23
To: osg users
Subject: Re: [osg-users] Snow plowing

I'm certainly no expert, but it seems to me that if you are clever you might
be able to use the bump-mapping texture at one level for the vertex
deformation (in the fragment shader) at the higher level of detail.
Generally, bump-mapping uses a normal map from a texture.  I don't know what
the performance impact would be calculating the normals on the fly (in GLSL)
from height displacement.

Seems similar in many ways to parallax bump-mapping.
-Paul

Zach Deedler wrote:
Hi Robert,

I thought about the height field for plowing. The only problem I see there is rendering large areas. This would result in a lot of vertices which would render horribly. This calls for levels-of-detail, which will complicate things greatly. Do we just add lower-levels of detail, and modify all LODs when plowing?

Also, I am concerned that a height field will result in blocky looking snow clearing.

What about bump maps?


Zach

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robert Osfield
Sent: Monday, April 16, 2007 14:36
To: osg users
Subject: Re: [osg-users] Snow plowing

Hi Zach,

On 4/16/07, Zach Deedler <[EMAIL PROTECTED]> wrote:
INVESTIGATION
I1) I am investigating moving/removing/adding vertices in real-time.
I2) I am also investigating modifying texture alpha values (Kind of like erasing the overlying snow).

QUESTIONS
Q1) Are there any osg examples that may help me in this investigation?
Examples that may dynamically move/remove/add vertices in real-time?
The osgTDS does adding of vertices on loadtime, not quite real-time but it might give you something to review.

There arn't any other OSG examples don't do adding/removing vertices.
In general I'd say try to avoid adding and removing vertices, by adjusting their heights/colours. If keep a static mesh with static base attributes, and minimize the amount of data you update per frame then you should be in a good position for hitting real-time needs.

Q2) I am looking for consultation for simulating snow plowing with OSG. If anybody believes they have the expertise to do this please
contact me.

I'm not available right now alas, it'd would be a fun project though :-)

Q3) Anybody have suggestions on how to implement snow plowing?
I'd try out using a static height field that is displaced by values that are updated in real-time, a simple vertex shader could do the displacement either reading the z values for float tex coord array, or from using tex read.

It just so happens that some of the upcoming work on osgTerrain will provide support for doing displacement maps that can be updated in
real-time.
Perhaps this could be reused for your purpose.

Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
/*
 * $Id: bump_mapping.vert,v 1.5 2006/01/17 18:09:14 paul Exp $
 *
 * Copyright (c) 2006, Paul Speed
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1) Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2) Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3) Neither the names "Progeeks", "NWN Tools", nor the names of its 
contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

varying vec4 direction0;
varying vec4 direction1;
varying vec4 viewDir;

void main()
{
    // Go ahead and setup the things we have to return for
    // fragment processing anyway
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;

    vec3 normal = normalize( gl_NormalMatrix * gl_Normal );

    // Grab a normalized copy of the s tangent which was sent through the color 
(glColor3f).
    vec3 sTangent = normalize( gl_NormalMatrix * gl_Color.xyz );

    /*if( gl_Color.z < 0 )
        gl_FrontColor = vec4( 1, 0, 0, 1 );
    else if( gl_Color.z == 0 )
        gl_FrontColor = vec4( 0, 1, 0, 1 );
    else
        gl_FrontColor = vec4( 0, 0, 1, 1 );
        */
    //gl_FrontColor = vec4( 1, 1, 0, 1 );

    // Calculate the binormal as the cross between tangent and normal.
    vec3 binormal = cross(normal, sTangent);

    // Calculate the vertex position in eye space
    vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

    // Calculate the light vectors that will be transformed into
    // surface tangent space.  These are verified by testing against
    // a flat poly.
    vec4 lightPos0 = gl_LightSource[0].position - ecPosition;
    vec4 lightPos1 = gl_LightSource[1].position - ecPosition;

    // Convert light direction to texture space.
    direction0.x = dot( lightPos0.xyz, sTangent );
    direction0.y = dot( lightPos0.xyz, binormal );
    direction0.z = dot( lightPos0.xyz, normal );
    direction0.w = 1.0;

    direction1.x = dot( lightPos1.xyz, sTangent );
    direction1.y = dot( lightPos1.xyz, binormal );
    direction1.z = dot( lightPos1.xyz, normal );
    direction1.w = 1.0;

    // Calculate a view vector.
    vec4 temp =  -ecPosition;
    viewDir.x = dot( temp.xyz, sTangent );
    viewDir.y = dot( temp.xyz, binormal );
    viewDir.z = dot( temp.xyz, normal );
    viewDir.w = 1.0;
}
/*
 * $Id: bump_mapping.frag,v 1.7 2006/01/17 18:28:35 paul Exp $
 *
 * Copyright (c) 2006, Paul Speed
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1) Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2) Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3) Neither the names "Progeeks", "NWN Tools", nor the names of its 
contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

varying vec4 direction0;
varying vec4 direction1;
varying vec4 viewDir;

uniform sampler2D decal;
uniform sampler2D parallaxMap;
uniform sampler2D normalMap;


void main()
{
    if( !gl_FrontFacing )
        discard;

    float scale = 0.04;
    float bias = 0.02;

    // The other approach is to prenormalize the view dir and
    // then just use the x,y components.
    viewDir = normalize(viewDir);

    // Get the height value and calculate the new texture coord.
    vec4 heightTex = texture2D(parallaxMap, gl_TexCoord[0].xy);
    float height = scale * heightTex.x - bias;
    vec2 newTexCoord = (height * viewDir.xy) + gl_TexCoord[0].xy;
    //vec2 newTexCoord = gl_TexCoord[0].xy;

    // Get the bump map normal.
    vec4 normalTex = texture2D(normalMap, newTexCoord);

    // Convert from 0 to 1 range to -1 to 1.
    normalTex = (normalTex - 0.5) * 2.0;

    // Get the decal texture color with the new tex coords.
    vec4 decalCol = texture2D(decal, newTexCoord);

    // Calculate the lighting contribution for the first two lights
    vec4 lighting;
    vec4 light0 = normalize(direction0);
    float dp = max( 0.0, dot( normalTex, light0 ) );
    lighting += gl_LightSource[0].diffuse * dp;

    vec4 light1 = normalize(direction1);
    dp = max( 0.0, dot( normalTex, light1 ) );
    lighting += gl_LightSource[1].diffuse * dp;

    // Add in the current ambient state.
    lighting += gl_LightModel.ambient;

    // Combine the decal with the lighting accumulator.
    vec4 final = decalCol * lighting;
//   vec4 final = gl_Color; //decalCol * lighting;
    gl_FragColor = final;
}


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to