Menu

Depth texture and FBOrenderer

Help
Daniel
2020-10-21
2020-11-07
  • Daniel

    Daniel - 2020-10-21

    Hi!
    I need the depth texture of the scene to use it for shadows via a shader.
    As I check the shadowmapping demo I see that the FBOrenderer is using the colorbuffer and converting it to a depth texture. But why not use the depth texture directly?
    Is the FBOrenderers depth texture not working? I cannot make it work.

    Is there another way of creating a depth texture that can be used in my shaders?

    Cheers!

     
  • Daniel

    Daniel - 2020-10-21

    I was using the Lazarus shadowFBO demo, but now I noticed the Delphi version called shadowmappingFBO. I will check that out first.
    Cheers!

     
  • Jerome.D (BeanzMaster)

    Hi Daniel, where is the ShadowMappingFBO example ? i didn't found it. The Lazarus ShadowFBO example is the same as Delphi and both use ColorTextureName.

    Regards

     
  • Daniel

    Daniel - 2020-10-23

    Hi Jerome!
    I cannot manage to make the FBORenderer actually render a depthTexture. The only way seems to be to use a shader to genereate a depthtexture from the the ColorTextureName.
    The demo is here: https://sourceforge.net/p/glscene/code/HEAD/tree/trunk/Demos/Delphi/specialsFX/ShadowmappingFBO/
    It has a much bigger TGLFBORenderer unit than the Lazarus version, so maybe there is some update that fixes the depthTexture generation?

    Cheers!

     
  • Jerome.D (BeanzMaster)

    Hi Daniel, under Lazarus, the Delphi FBORenderer unit is split in two Units : GLFBO and GLFBORenderer

    I converted the ShadowMappingFBO sample, it work well except the HUDSprite something is not correct with the ShadowMapVis_fp script. I think the problem is shader2 is apply after Shader1
    See the screenshot. I joined the zip of the converted sample. Just copy the resources needed from Delphi media folder to Lazarus media folder.

    Cheers

     
  • Daniel

    Daniel - 2020-10-29

    Thanks alot Jerome!!!
    It works like a charm!

    I have some issues making the resolution of the shadow good enough.
    But my biggest concern is that as soon as my model move, the shadows gets displaced and I cannot solve it:
    https://youtu.be/5Uk9PaEGrBA

    Is a different Matrix needed?
    Cheers!

     
  • Jerome.D (BeanzMaster)

    Hi Daniel, hum do you same code as sample for initalize matrix ? Take llook to the Scale and bias parameters. It's seem the Shadow not follow the model but stay in center of the screen

     
  • Daniel

    Daniel - 2020-10-30

    Hi Jerome!
    Yes, it's all the same code.
    If you try this in the the ShadowMappingFBO sample, you'll see the same problem there.

    procedure TForm1.GLCadencer1Progress(Sender: TObject; const deltaTime,
      newTime: Double);
    begin
      GLTorus1.Turn(deltaTime * 25);
      GLCylinder1.turn(deltaTime * 50);
      //GLCamera2.Position.Rotate(VectorMake(0, 1, 0), deltaTime * 0.1);
      SceneRoot.Position.X := SceneRoot.Position.x + 0.01;
      glcamera2.Position.x := GLCamera2.Position.X + 0.01;
      glcamera1.Position.x := GLCamera1.Position.X + 0.01;
    end;
    

    The shadow starts to move away, ahead of the objects, the same way as in my program.
    Any idea what might cause this?
    Cheers!

     
  • Daniel

    Daniel - 2020-11-02

    Hi!
    Is there a specific reason why the directOpenGLrenderer is child of the sceneroot dummycube?
    Moving it to the GlScene root solves the issue!

     
  • Jerome.D (BeanzMaster)

    Hi Daniel, well see to move directOpenGLrenderer , indeed matrix for the shadow must be relative to the world and not attached to objects in a certain case is logic .
    The person who's made this sample at base, SceneRoot not move. So it's correct.

    But when you move sceneroot, directOpenGLrenderer's modelview matrix is also modified and going to wrong.
    I think for solving this behaviours is to use absolutmatrix instead of relative and compute the modelview matrix ourself

    But by moving directOpenGLrenderer directly in the Root is a quick and working hack ! +1

    Cheers

     
  • Daniel

    Daniel - 2020-11-07

    Hi Jerome!

    Yes, it seems to be working nicely!
    https://youtu.be/GNcFy8XMVJg

    Now my problem is the resolution and the shadow acne.
    Maybe I should look at cascaded shadow maps. Do you know some glScene demo using those?

    Cheers!

     

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.