Announcement

Collapse
No announcement yet.

Has disabling Backface culling changed?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • lifepower
    replied
    I'm glad you got the shadows working. Looks nice!

    Leave a comment:


  • Zimond
    replied
    I think I understood this a lot better now. How the frustum works that defines until where the shadows are visible and that you have to manage a reasonable limit until which you want to increase the shadow map texture size. I think I can pull of some kind of Sun system now.

    Leave a comment:


  • Zimond
    replied
    Daaaamn... Of course the viewprojection needs the new view too.

    Leave a comment:


  • lifepower
    replied
    In above code, "Viewport_SceneLights" is unrelated to shadows, it is part of main scene. But, in the code related to shadows, specifically this line:
    Code:
    LShadowCaster.ViewProjection := TMatrix4f.PerspectiveFOVY(Pi * 0.25, 1.0, 100.0, 1800.0, LDepthClipNegative);
    "ViewProjection" means that it is a combined view/projection matrix. You need to combine "look up" and "perspective" matrices together. Normally, when you assign these matrices to a view associated with the shadow caster, you can read its "ViewProjection", which has already both matrices multiplied. Otherwise, you would need to manually assign them, e.g.:
    Code:
    LShadowCaster.ViewProjection := TMatrix4f.LookAt(Vector3f(600.0, 100.0, -300.0), TVector3f.Zero, TVector3f.AxisY) * 
      TMatrix4f.PerspectiveFOVY(Pi * 0.25, 1.0, 100.0, 1800.0, LDepthClipNegative);
    Normally, however, you need to create a view for the shadow caster, which will track what objects are within shadow casting frustum. You will assign both View and Projection matrices to the view, then assign "ViewProjection" to shadow caster reading it directly from the view. For instance:

    Code:
      var LShadowCasterView := FObjects.CreateView;
      LShadowCasterView.View := TMatrix4f.LookAt(LightPosition, TVector3f.Zero, TVector3f.AxisY);
      LShadowCasterView.SetProjection(TMatrix4f.PerspectiveFOVY(Pi * 0.25, 1.0, 100.0, 1400.0,
        LDepthClipNegative), LDepthClipNegative);
    
      LShadowCaster.ViewProjection := LShadowCasterView.ViewProjection;

    Leave a comment:


  • Zimond
    replied
    Hey, me again with more need for help

    So, I try to implement the shadow path and well, I got something working, but very weirdly. I copied portions of one of the demos first. The perspective seems to be totally off as seen in the screenshot. The selected object at the bottom is where the light source is. Besides that also half of the space is completely black, everything in the Z minus range.

    Here is what I used:

    Create code:
    Code:
    //Create Shadow Atlas
    LTechniqueShadows := TTechniqueShadows.EVSM;
    FShadowCastingAtlas := TShadowCastingAtlas.Create(FDevice, Point2i(256, 256), LTechniqueShadows, 8);
    FShadowCastingAtlas.Add(Point2i(256, 256));
    
    Viewport_SceneLights := TSceneLights.Create(FDevice);
    // Add some light.
    LSceneLight := Viewport_SceneLights.Add;
    LSceneLight.AmbientColor := FloatColorRGB($FFFFFF);
    LSceneLight.AlbedoColor := FloatColorRGB($FFFFFF);
    LSceneLight.SpecularColor := FloatColorRGB($ffffff);
    LSceneLight.ShadowCaster := 0;
    LSceneLight.Position := Vector3f(600.0, 100.0, -300.0);​
    Rendering code:
    Code:
        // Perform light assignment for 3D scene.
        Viewport_SceneLights.ViewSize := point2i (CurrentWidth, CurrentHeight);
    
        // Only one light is used for the entire scene, so only minimal light culling is required.
        Viewport_SceneLights.ClustersCullingMode := TClustersCullingMode.Quality;
        Viewport_SceneLights.ClusterSize := 512;
        Viewport_SceneLights.DepthSlices := 1;
        Viewport_SceneLights.Execute(Viewport_View, Viewport_Projection);
    
        // Render shadow map.
        FShadowCastingAtlas.BorderFill;
    
        LShadowCaster := FShadowCastingAtlas.Casters[0];
        LShadowCaster.ViewProjection := TMatrix4f.PerspectiveFOVY(Pi * 0.25, 1.0, 100.0, 1800.0, LDepthClipNegative);
    
        LShadowCaster.Clear;
        LShadowCaster.BeginScene;
        try
          Viewport_SceneDepthNormals.Attributes := [];
          Viewport_SceneDepthNormals.View := TMatrix4f.LookAt(Viewport_SceneLights[0].Position, TVector3f.Zero, TVector3f.AxisY);
          Viewport_SceneDepthNormals.Projection := LShadowCaster.ViewProjection;
    
          for i := 0 to GameScenes[Viewport_LoadedNum].GameModels.Count -1 do
           RenderSceneModels (Viewport_SceneDepthNormals, i, true);
    
        finally
          LShadowCaster.EndScene;
        end;
        LShadowCaster.Filter;​
    ​​
    I am not using a ObjectModels or ObjectModelView class as you do in all examples. Is that necessary in this case? I thought I could use a LookAt view from the light source directly and also use the Viewprojection that you used in the examples.
    Attached Files

    Leave a comment:


  • lifepower
    replied
    No, it should not affect the rendering of textures with holes. However, when you are rendering shadow maps, it does update device's rendering state, so you have to make sure to set the appropriate device rendering state when rendering main scene.

    Leave a comment:


  • Zimond
    replied
    Just for clarification. Right now, does using a ShadowAtlas pass also cause all textures to have no more alpha as using a depth pre pass does? I tried implementing it and all Textures with alpha "holes" turned solid again. I was aware that the shadows itself would be solid of course but I thought that the textures itself would stay the same.

    If that is the case. I will just add "shadows" to the later list since 3d "sprites" (or billboards) with alpha have priority in my project.

    Really just wanna know. Take your time, nothing in my regard is urgent in any way.

    Leave a comment:


  • lifepower
    replied
    Actually, depth pre-pass is needed for fog and water effects. So if you are going to use those, you'd need to enable depth pre-pass.

    Leave a comment:


  • Zimond
    replied
    No problem. I doubt I will hit a performance wall anytime soon doing it without the prepass 👍

    Leave a comment:


  • lifepower
    replied
    Sorry, but texturing in depth/normals scene could not make it into this update. I did try to include it, but there were significant interface breaking changes, as well as some unforeseen consequences in the rendering pipeline, so it requires further research. However, I'll be getting another look at it within next couple of months to see how it can be integrated.

    Leave a comment:


  • Zimond
    replied
    "An update is coming with some features that could not make it into first v3 release, I'll try to make sure that texturing for depth/normals scene is exposed - this would also allow rendering shadows with holes using textures like in your approach."

    Just wanted to ask if this got into the 3.5. Hadnt had time to check. Then I can reinsert the depth prepass.

    Leave a comment:


  • lifepower
    replied
    Depth pre-pass is, as the name implies, a separate pass to produce depth buffers, which would be used for ambient occlusion, and to speed up the main pass. This means that AO calculation can be performed at the same time, for instance, while lighting calculations are performed. While rendering the main pass, depth buffer testing is set to equal, so only those pixels that are actually visible will be processed.

    This has nothing to do with canvas and its projected rendering. However, to avoid Z-fighting, you might need to adjust depth testing to "equal or less", and/or enable depth bias, like in Chart3D example (see RenderText function there).

    Leave a comment:


  • Zimond
    replied
    Originally posted by lifepower View Post
    In previous versions, Delphi/Pascal Cube example wasn't using depth pre-pass. In latest version, it's been updated to use depth pre-pass similar to C and C# examples.

    Therefore, I would suggest disabling depth pre-pass: comment out the appropriate block and make sure to move texture cabinet occlusion filter command to be executed after the main rendering pass.

    Rendering with a depth pre-pass is a more common approach in Afterwarp as it allows to improve performance both by reducing overdraw and allowing ambient occlusion to execute in parallel while some other processing takes place (otherwise it is computed after the main pass). However, depth/normals scene does not expose texturing interface, so you can't render texture "holes" in depth pre-pass.

    An update is coming with some features that could not make it into first v3 release, I'll try to make sure that texturing for depth/normals scene is exposed - this would also allow rendering shadows with holes using textures like in your approach.
    Just to make sure. Am I guessing right that a projected SDF canvas also doesn't work when a depth pre pass is active, for the same reasons?

    Leave a comment:


  • Zimond
    replied
    I'll keep that in mind. 👍 Thanks again

    Leave a comment:


  • lifepower
    replied
    When you load a mesh from file either to mesh buffer or directly to scene meshes, there is "TMeshMetaTags" collection that is provided. Each "tag" contains name of the appropriate object, min/max boundaries, first vertex, vertex count, first index and index count. If you want to render this particular tag, you can issue a draw call specifying first index and index count (these parameters are always passed to Draw functions, just by default they are set to zero, which means the entire mesh).

    Splitting is also possible - Voxelize tool does this and provides you XML file with information on each sub-object, and it also detects instances (same object, different position). So you can either use tags directly (more efficient approach), or do the split with Voxelize and use information from XML file.

    Leave a comment:

Working...
X