-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to calculate the normal from partial derivatives? #6
Comments
dFdx and dFdy are precisely what the Sobel operator estimates, so if you
have code that uses the Sobel filter kernels, dFdx and dFdy in fragment
shader code should be drop-in replacements.
As for analytic derivatives of noise, they are computed in texture space,
so there you might need to apply a transformation to the gradient to get it
in the correct coordinate system.
If this doesn't answer your question, let me know and I'll try again. I'm
not sure I understand exactly how you use the Sobel operators.
/Stefan Gustavson
|
Okay I may have been confusing with this sobel stuff.
So what it does is this: This is what I'm currently doing. But I saw in your wiki page that it is possible to calculate the normal map directly from the analytical derivative, so I can skip the noise2normal stuff and use the analytical derivative to create a normal map instead.
What to do with the derivatives to get a normal map? I tried to normalize them normalize(float3(dx, dy, 1.0)) but its not a valid normal map. |
The normal map you showed at the end looks OK to me. Your pattern is washed
out because of clamping issues, but I see no general problem with the
normal map - except for scaling. Sobel filters estimate the actual change
from one point to another at a specified distance, while analytic
derivatives give you the local idealized rate of change across one unit of
distance (1.0). So, you need to multiply your gradient with a factor that
tells how the noise is scaled and mapped to texture space. For example, if
you paint a pattern using 0.3*noise(4.0*u, 6.0*v), the local gradient in
texture coords is 0.3*vec2(4.0,6.0) times the analytic gradient. This is
the equivalent of an "inner derivative" for multidimensional functions.
Sort out the scaling issues and you should be fine! (I think.)
/Stefan G
|
This was the answer I was looking for! Thank you so much! |
Glad I could help. Good luck, and have fun!
|
Even though the issue was resolved, I am keeping the thread open because it's informative. |
Currently I use the sobel operator to get the normal from the noise values, but I could skip that when I would know how to use the partial derivatives.
How is the normal calculated from dx,dy?
The text was updated successfully, but these errors were encountered: