A minimalist rendering library.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: A minimalist rendering library.

Postby JoeJ » Tue Oct 07, 2025 3:09 am

My gravity problem was because the model update function signature has changed (in the notify, now not taking the world as param). Easy to fix and now everything is working.
But i wonder if there is a way to trigger compiler errors in this case?

Here my fixed code:
Code: Select all
class ModelNotify : public ndModelNotify
{
//...

      void Update (/*ndWorld* const world, */ndFloat32 timestep)
      {
         model->Update(GetModel()->GetWorld(), timestep);
      }
};


Would i get an error if i would add some 'virtual' in front of the void, or something like that?

I should not really ask such C++ beginner questions here, but feel free to help an OOP noob out :oops:
I think there really should be a way to make clear that i want to provide an implementation of a certain virtual function. It's not the first time simple signature changes break my stuff, and ther should be at least compiler warnings.

Regarding depth bias, i have never learned to use it. Reading the specs left me with confusion on what those API features exactly do. But iirc, there are two different forms of bias, both with their own related tools on the API side. Maybe one for a slope bias (acne) and the other for a constant offset (peter panning), but idk.

Personally i could fix acne by creating a plane from the shading normal and projecting my samples to that plane. So that's a form of slope bias i guess. The fix creates a discontinuity due to plane flipping cases, but it's in shadow and thus not visible. But i use a crazy expensive 4x4 region of samples. Only this way i could hide visible SM texels and fix all artifacts (acne, panning, and VSM leaks).

Yes, i did it! My shadows are practically free of all those known artifacts! It's possible! \:D/
But by getting there, i have also discovered new artifacts. They really are not bad, and i could call them 'high end artifacts'. :D But it's still artifacts.


For the sky i want a procedural model, like this for example: https://www.shadertoy.com/view/slSXRW
But i hope there are simpler models to find.
User avatar
JoeJ
 
Posts: 1493
Joined: Tue Dec 21, 2010 6:18 pm

Re: A minimalist rendering library.

Postby Julio Jerez » Tue Oct 07, 2025 9:02 am

For virtual functions, yes there is a way to make the compiler warn you if the signature of a virtual function on a sub class is incorrect.
Unfortunately it an optional cpp 17, I think option,
You just add the keyword override at the end of the function in the derived class.
I have being trying to do it in the SDK, every time I could.
Apple clang is good at warning that.

The zbias, in shadow, there are essentially two methods.
One: you set the bias when generating the shadow maps, which is the method I am using because I find more reliably. Since the hardware supposedly does it at the rasterization stage, considering the face normal of each triangle.
This is supposed to be the most sophisticated method, because consider the triangle inclination to generate a variable bias in the sgadowmap buffer.
But you are right, it is a black magic art, that has never being well documented, and in fact can change from GPU to GPU.

The second option is to do it yourself when rendering the mesh from the camera, by reading the shadow pixel and offseting in a variable in the pixel shader.
This method, you are in control, because to know all the parameters.
But so far in all my experimentations, I found worse to tune.
The reason is that you do not know the slope of triangle the pixel in the shadow maps texture.

Anyway, as I said before, I think my problem is that I am setting the bias, as a const for all shadow maps.
And that not current.
For example.
A pixel in shadow, that happens to be in the shadow closer to the eye point, had an enormous z buffer resolution, basically a depth value cover a few meters.
So here the bias has to be very big, like 30,000 or so.

As the cascade zone move away from the camera I point, the pixel cover more distance, so each pixel in shadow get less resolution. Therefore the bias should be smaller.

A naive way is to just multiply 0.5 for each unit, map as the are farther away.
Buy the maps din exactly cover twice the distance, the distance are usually set by hand,
I am using an exponential heuristic.
Si I will add the calculation of the bias there.

The true answer is that the only way to get good shadow is ray tracing
Julio Jerez
Moderator
Moderator
 
Posts: 12448
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A minimalist rendering library.

Postby Julio Jerez » Tue Oct 07, 2025 11:06 am

I think I have a better setting now, I move the bias setting to the inner loop on the shadow pap rendering passes.

Code: Select all
         glViewport(vp_x, vp_y, m_width, m_height);
         glPolygonOffset(GLfloat(1.0f), GLfloat(zbias));
         for (ndList<ndSharedPtr<ndRenderSceneNode>>::ndNode* node = scene.GetFirst(); node; node = node->GetNext())
         {
            ndRenderSceneNode* const sceneNode = *node->GetInfo();
            sceneNode->Render(owner, lightSpaceMatrix, modepass);
         }
         zbias *= ndReal(2.0f);


This makes it a lot better, but it is not perfect. THer will be flick at very shaper angles.
anyway, and continue the I will hold on this ndMesh export import, so that I can make a blender plugin that can read and write meshes.

I have a unit that can read fbx file using the Autodesk dll, but the files are fbx, and I can onle load the in my 2012 version of 3dxmax.
I have to use that tool to convert some fpx files, before I can load them int max, or else Max just crashes. and for some the hierarchy in blender is all screwup.
I think having a transport format can help fix that problem. plus allow manual minor editing
Julio Jerez
Moderator
Moderator
 
Posts: 12448
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A minimalist rendering library.

Postby Dave Gravel » Tue Oct 07, 2025 11:53 am

I tested the latest SDK, and yes, it looks better with less flickering.
I noticed only one possible issue, the reflection on the floor.
When I rotate the camera, the reflection rotates too, which looks a bit strange.

off-topic:
I updated my code for the multibody monster truck, and everything seems to work as before, very cool!
You can see it at 10:52 in the video:
https://www.youtube.com/watch?v=iAuK_kQAMbs

I also updated my old raycast car demo. This one works pretty well too, but I still have a few things to fix regarding the friction.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 807
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: A minimalist rendering library.

Postby Julio Jerez » Tue Oct 07, 2025 2:05 pm

Dave Gravel wrote:I tested the latest SDK, and yes, it looks better with less flickering.

I just committed that last tweak for that. I end up making a nard coded look up table for the bias settings. It is the best I got so far, the bridge does show flicker, and it discriminate
the overlapping shadow pixels better. I guess that it will probably fail on smaller meshes, but so fat I think this is good enough.

Dave Gravel wrote:I noticed only one possible issue, the reflection on the floor.
When I rotate the camera, the reflection rotates too, which looks a bit strange.

I will check that out.

Dave Gravel wrote:off-topic:
I updated my code for the multibody monster truck, and everything seems to work as before, very cool!

I saw it, it's cool.
Julio Jerez
Moderator
Moderator
 
Posts: 12448
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A minimalist rendering library.

Postby Julio Jerez » Tue Oct 07, 2025 2:09 pm

oh yeah!!! you are right, the reflection is attached to the camera.

There have to be a wrong reflection matrix somewhere. I will check it out

Oh I see the problem.
The reflection vector is calculated in the camera space, but if it sample the cube map with that direction them reflect are in cam space, I need to rotate the final direction of the world space before sampling the cube map, it should be an easy fix.
Julio Jerez
Moderator
Moderator
 
Posts: 12448
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A minimalist rendering library.

Postby Julio Jerez » Tue Oct 07, 2025 5:42 pm

ahh, I have working for one of the three shaders. Nee to apply it to the other two.
Now reflection on background objects, make sense.
Thank to point that out. :D :mrgreen: :shock: 8)
Julio Jerez
Moderator
Moderator
 
Posts: 12448
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests