Announcement

Collapse
No announcement yet.

Has disabling Backface culling changed?

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

  • #16
    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.

    Comment


    • #17
      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.

      Comment


      • #18
        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

        Comment


        • #19
          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;

          Comment


          • #20
            Daaaamn... Of course the viewprojection needs the new view too.

            Comment


            • #21
              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.

              Comment


              • #22
                I'm glad you got the shadows working. Looks nice!

                Comment

                Working...
                X