umituzun84 wrote:
> Hi Paul;
> 
> Watch the video. It can tell you much of dot and cross product :)
> 
> http://video.google.com/videosearch?q=cross+product&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&ei=LE4dSreZCpLt_AbS4OGxDQ&sa=X&oi=video_result_group&resnum=4&ct=title#
>  
> (http://video.google.com/videosearch?q=cross+product&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&ei=LE4dSreZCpLt_AbS4OGxDQ&sa=X&oi=video_result_group&resnum=4&ct=title#)
> 
> Regards.
> 
> 2009/5/27 Paul Griffiths < ()>
> 
> >  
> > Kim C Bale wrote:
> > 
> > > I presume this line:
> > > 
> > > n = (pos1 -pos0) ^ (pos2 - pos1);
> > > 
> > > is a cross product of two vectors. i.e. the normal, also known as the
> > > vector perpendicular to the two vectors that define the plane.
> > > 
> > > In which case you would want to use the glsl function cross(vec3,vec3)
> > > as on the reference sheet I sent previously.
> > > 
> > > You should have a read about the geometry math being used here. Blindy
> > > copying code without understanding it is a good way to shoot yourself in
> > > the foot later on.
> > > 
> > > 
> > > Kim.
> > > 
> > > 
> > > -----Original Message-----
> > > From:
> > > 
> > 
> > 
> > > [mailto:] On Behalf Of Paul
> > > Griffiths
> > > Sent: 27 May 2009 13:40
> > > To:
> > > 
> > 
> > 
> > 
> > > Subject: Re:  vertex shader help: compare position against
> > > plane
> > > 
> > > ok, i got the world position with:
> > > 
> > > 
> > > Code:
> > > mat4 ToWorldMatrix= osg_ViewMatrixInverse* gl_ModelViewMatrix;
> > > vec3 worldPos = ToWorldMatrix * gl_Vertex;
> > > 
> > > 
> > > 
> > > 
> > > now i need to check which side of the plane the worldPos is.
> > > I googled and found some code for this but its not for glsl, ive came up
> > > with this but i get errors.
> > > 
> > > the code is:
> > > 
> > > 
> > > Code:
> > > vec3 n;
> > > float d;
> > > 
> > > n = (pos1 -pos0) ^ (pos2 - pos1);
> > > d = -n * pos0;
> > > 
> > > inside = 1.0;
> > > 
> > > if (dot(n, gl_Position) + w)
> > > {
> > > inside = 0.0;
> > > }
> > > 
> > > 
> > > 
> > > 
> > > the errors i get are:
> > > 
> > > 
> > > Code:
> > > VERTEX glCompileShader "" FAILED
> > > VERTEX Shader "" infolog:
> > > 0(46) : error C1021: operands to "^" must be integral
> > > 
> > > glLinkProgram "eroded" FAILED
> > > Program "eroded" infolog:
> > > Vertex info
> > > -----------
> > > 0(46) : error C1021: operands to "^" must be integral
> > > 
> > > Warning: detected OpenGL error 'invalid operation' after
> > > RenderBin::draw(,)
> > > 
> > > 
> > > 
> > > 
> > > so i tried
> > > 
> > > 
> > > Code:
> > > vec3 n;
> > >       float w;
> > > 
> > >       int p0 = (pos1 -pos0);
> > >       int p1 = (pos2 - pos1);
> > >       n =  p0 ^ p1;
> > >       w = -n * pos0;
> > >       inside = 1.0;
> > > 
> > >       if (dot(n, worldPos) + w)
> > >       {
> > >               inside = 0.0;
> > >       }
> > > 
> > > 
> > > 
> > > but it alway returns inside = 0.0;
> > > 
> > > any ideas?
> > > 
> > > ------------------
> > > Read this topic online here:
> > > http://forum.openscenegraph.org/viewtopic.php?p=13031#13031 
> > > (http://forum.openscenegraph.org/viewtopic.php?p=13031#13031)
> > > 
> > > 
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > osg-users mailing list
> > > 
> > > 
> > 
> > 
> > 
> > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or 
> > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or)
> > > g
> > > 
> > 
> > 
> > > *****************************************************************************************
> > > To view the terms under which this email is distributed, please go to 
> > > http://www.hull.ac.uk/legal/email_disclaimer.html 
> > > (http://www.hull.ac.uk/legal/email_disclaimer.html)
> > > *****************************************************************************************
> > > _______________________________________________
> > > osg-users mailing list
> > > 
> > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
> > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > > 
> > > 
> > 
> > 
> > >  ------------------
> > > Post generated by Mail2Forum
> > > 
> > 
> > 
> > Thanks kim. am new to this 3d math stuff.
> > 
> > ------------------
> > Read this topic online here:
> > 
> > http://forum.openscenegraph.org/viewtopic.php?p=13051#13051 
> > (http://forum.openscenegraph.org/viewtopic.php?p=13051#13051)
> > 
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
> > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > 
> > 
> > 
> 
> 
> 
> -- 
> Ümit Uzun
> 
>  ------------------
> Post generated by Mail2Forum


Thaks umituzun84, for the link. Ill have a watch when im home and not on mobile 
broadband.

-----------------------------------------------------------------------------

Ive got my code working. But its clipping to a vertex level when I need it down 
to the fragment level. 

Is it possible to get the fragment world position in some way?

heres my code so far:

Vertex shader:

Code:
varying float lightIntensity;
varying vec3 Position;
uniform vec3 LightPosition;
uniform float Scale;
varying float inside;
uniform mat4 osg_ViewMatrixInverse;
varying vec3 pos0;
varying vec3 pos1;
varying vec3 pos2;

void main(void) {
        vec4 pos = gl_ModelViewMatrix * gl_Vertex;
        Position = vec3(gl_Vertex) * Scale;
        vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
        float dotval = max(dot(normalize(LightPosition - vec3(pos)), tnorm), 
0.0);
        lightIntensity = dotval * 1.5;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        
        pos0.x = 0.4;
        pos0.y = 0.0;
        pos0.z = 0.0;
        
        pos1.x = 0.4;
        pos1.y = 1.0;
        pos1.z = 0.0;   
        
        pos2.x = 0.4;
        pos2.y = 0.0;
        pos2.z = 1.0;

        mat4 ToWorldMatrix = osg_ViewMatrixInverse * gl_ModelViewMatrix;
        vec3 worldPos = ToWorldMatrix * gl_Vertex;
        
        vec3 n;
        float d;
        n = cross((pos1 -pos0),(pos2 - pos1));
        d = -n * pos0;

        inside = 1.0;

        if (dot(n, worldPos) + d > 0.0)
        {
                inside = 0.0;
        } 
}



Fragment Shader:

Code:
varying float lightIntensity; 
varying vec3 Position;
varying float inside;

void main (void)
{
        if (inside) discard;
        
    vec3 color;
    color.r = 1.0;
        color.g = 0.0;
        color.b = 0.0;
    
    color *= lightIntensity;
    color = clamp(color, 0.0, 1.0); 
        
    gl_FragColor = vec4 (color, 1.0);  
}



------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=13058#13058





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

Reply via email to