Menu

Clip plane

Help
Daniel
2020-06-08
2020-07-20
  • Daniel

    Daniel - 2020-06-08

    Hi!
    I am setting up a clip plane like this:

    GL.Enable(GL_CLIP_PLANE0);
        SetPlane(clipPlane, PlaneMake(AffineVectorMake(FclipPlane.AbsolutePosition),
        VectorNegate(AffineVectorMake(FclipPlane.AbsoluteDirection))));
        GL.ClipPlane(GL_CLIP_PLANE0, @clipPlane);
    

    It works on standard objects like a GLSphere, but it doesn't work on my FreeForm objects, any idea why?

    Cheers and thanks!
    /Daniel

     
  • Daniel

    Daniel - 2020-06-14

    An update.
    When I remove the material which has a shader, then the clipping plane works!?
    How can I use the clip plane on a textured freeform?

     
  • Daniel

    Daniel - 2020-06-14

    And if I remove the shader and leave the texture on the object, then the clipping plane works.
    So having a shader on the material is the problem. How can I solve this?

     
  • Daniel

    Daniel - 2020-07-16

    Hi Jerome!

    Thanks! That worked.
    But I am having trouble with the matrixes.
    I do this on a moving shipmodel:

    gl_ClipDistance[0] = dot(gl_Vertex * modelMatrix, clipPlane);
    

    ModelMatrix I get from scene.buffer.rendercontext.pipelinetransformations.modelmatrix,
    and clipPlane is a vector4f that I send in as a uniform vec4(0.0, 1.0, 0.0 0.0).
    The clipplane seems to be stuck in the object space and follows the moving ships movements and do not stay at the world pos.
    Any idea what's wrong?

     
  • Jerome.D (BeanzMaster)

    Hi Daniel, hard to answer like this.

    1st On what tutorial have you take reference ?
    2nd Can you make a little sample, for testing ?

    So i think

    gl_ClipDistance[0] = dot(gl_Vertex * modelMatrix, clipPlane);

    is wrong

    if i understand well, it should be

    position = gl_Vertex * modelViewProjectionMatrix
    gl_ClipDistance[0] = dot(position, clipPlane);

    Cheers

     
  • Daniel

    Daniel - 2020-07-18

    Sadly it didn't help.
    I am using the code from https://prideout.net/clip-planes
    I will try to make an sample program.

    Thanks for helping!!

     
  • Jerome.D (BeanzMaster)

    Hi Daniel can you post the code of your shader, and how you pass attributes to it ?

    Cheers

     
  • Daniel

    Daniel - 2020-07-20

    Absolutly!

    uniform mat4 mm;
    uniform vec4 cPlane;  
    varying vec2 Texcoord;   
      varying vec3 ViewDirection;   
    
      varying vec3 fvViewDirection;   
      varying vec3 fvNormal;   
      varying vec3 fvBinormal;   
      varying vec3 fvTangent;   
    
          void main( void )   
          {   
             gl_Position = ftransform();
    
             Texcoord    = gl_MultiTexCoord0.xy;
          gl_ClipDistance[0] = dot(mm * gl_Vertex, cPlane);
    
             fvViewDirection   = (gl_ModelViewMatrix * gl_Vertex).xyz;   
    
             fvNormal         = gl_NormalMatrix * gl_Normal;   
             fvBinormal       = gl_NormalMatrix * gl_MultiTexCoord2.xyz;   
             fvTangent        = gl_NormalMatrix * gl_MultiTexCoord1.xyz;   
    
             ViewDirection.x  = dot( fvTangent, fvViewDirection );   
             ViewDirection.y  = dot( fvBinormal, fvViewDirection );   
             ViewDirection.z  = dot( fvNormal, fvViewDirection );   
    
             ViewDirection  = normalize(ViewDirection);   
          }
    

    mm := GLSceneViewer1.Buffer.RenderingContext.PipelineTransformation.modelMatrix;
    cPlane := Vector4fMake(0.0,1.0,0.0,2.0);

    I will fix a sample program as soon as I can.

     

    Last edit: Daniel 2020-07-20

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.