help with normals for terrain
category: code [glöplog]
Hi everybody
I'm building terrain on a tiny planet: https://www.shadertoy.com/view/Ms3SD4
I got it working quite nicely but I am having trouble getting the normals out of my terrain functions: I tried 2 approaches and both of them fail (I get very weird discontinuities). See lines: 257-292 for the relevant code part.
I'm using a combination of normal raytracing and sampling a 3D noise height func. Not 2D func, not distance field based. Maybe that's the problem?
If anyone can take a look and give their 2 cents would be appreciated,
cheers
V
I'm building terrain on a tiny planet: https://www.shadertoy.com/view/Ms3SD4
I got it working quite nicely but I am having trouble getting the normals out of my terrain functions: I tried 2 approaches and both of them fail (I get very weird discontinuities). See lines: 257-292 for the relevant code part.
I'm using a combination of normal raytracing and sampling a 3D noise height func. Not 2D func, not distance field based. Maybe that's the problem?
If anyone can take a look and give their 2 cents would be appreciated,
cheers
V
If all cails calculate normals like You do for signed distance functions.
It should work well on a 3d array of normals or distances to surfaces.
It acerages both neibots on all dimensions, resulting in a good fast local approximation.
It should work well on a 3d array of normals or distances to surfaces.
It acerages both neibots on all dimensions, resulting in a good fast local approximation.
The normal for a good SDF is just a gradient, which is what you're trying to get, but it doesn't work because:
Your noise is an offset, making any SDF non-linear and breaking the gradient, usually solved by scaling the distance by something between 0.4 and 0.7 making more steps necessary but glitches less occuring.
It looks like your noise is added to a raytraced sphere, getting the distance to the raycast surface instead of the closest point in the scene as distance really really does not work when combined with other SDF raymarching.
Also, it looks like a lot of code for a noisy sphere. Anyhow, my advice would be to raymarch either way, makes volumetrics, atmosphere, shadows and AO much easier.
I may be wrong there, didn't look long enough and also I'm sure there's people around here more capable than I that can actually solve your problem :D
Your noise is an offset, making any SDF non-linear and breaking the gradient, usually solved by scaling the distance by something between 0.4 and 0.7 making more steps necessary but glitches less occuring.
It looks like your noise is added to a raytraced sphere, getting the distance to the raycast surface instead of the closest point in the scene as distance really really does not work when combined with other SDF raymarching.
Also, it looks like a lot of code for a noisy sphere. Anyhow, my advice would be to raymarch either way, makes volumetrics, atmosphere, shadows and AO much easier.
I may be wrong there, didn't look long enough and also I'm sure there's people around here more capable than I that can actually solve your problem :D
@TropicalTrevor the code is part of a bigger library and I'm using this non-SDF method because I also do clouds in the same raymarch steps (I took that out for clarity)
I fixed it by using SDF only for the normals while leaving the rest "dumb" raytracer
If anyone is interested I overcame all problems and in the end came up with quite a cool thing: https://www.shadertoy.com/view/ldyXRw