Skip to content
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

New feature: calculate normal from height map (GLSL and HLSL) #167

Conversation

shadielhajj
Copy link
Collaborator

@shadielhajj shadielhajj commented Jul 16, 2024

When displacing a grid based on a height map texture, we need to calculate the normals. This function does it for us.

Here's an example of 2048x2048 grid being displaced by a simple noise texture. Normals are calculated directly from the height maps using sample/normalFromTexture.
Screenshot 2024-07-16 224230

@patriciogonzalezvivo
Copy link
Owner

Nice one!
Just for the record. You can also use this one https://lygia.xyz/sample/bumpMap ( which calculates derivatives using this other one https://lygia.xyz/sample/derivative) it makes more samples. I like your approach.

Thank you again!

@patriciogonzalezvivo patriciogonzalezvivo merged commit e95284c into patriciogonzalezvivo:main Jul 16, 2024
@shadielhajj
Copy link
Collaborator Author

shadielhajj commented Jul 16, 2024

Thanks for the head up @patriciogonzalezvivo. I missed sample/bumpMap. Works nicely indeed.
HLSL version of sample/derivative is broken btw. I'll make a PR with a fix in a sec.

@shadielhajj shadielhajj deleted the feature/normalFromTexture branch July 16, 2024 23:33
@patriciogonzalezvivo
Copy link
Owner

Nit: I was wondering about the name 'sampleNormalFromTextue' wouldn't be more clear 'sampleNormalFromHeightmap'? Being a sampler implies is sampling from a texture. Just a thought. Happy to go with your gut feeling

@shadielhajj
Copy link
Collaborator Author

@patriciogonzalezvivo agreed. I was also hesitating. Let's go with normalFromHeightmap. I'll PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants