[SOLVED] Updating normals after glsl vertex displacement

aceslowman's icon

So I am working with some glsl fractal noise to displace a mesh, and a familiar issue has come up: I can't light it. I've dealt with this in the past, which kind of just led to me ditching vertex displacement in frustration. I see a lot of vertex displacement examples shared (which has helped me get what I have), but they are almost shown in wireframe, which makes me suspicious.

What is the right way to approach this problem? I would imagine I could recalculate the normals in the vertex shader, and then apply whatever fragment shader I want afterwards to light and shade my newly displaced mesh. I just don't know quite the direction to go to start.

Do I recalculate the normals? Do I generate some kind of normal map from the fractal noise and pass that along with the rest? Or am I way off base and actually unable to light a mesh this way?

Any help is appreciated!

Max Patch
Copy patch and select New From Clipboard in Max.


vertex-displacement.jxs: https://pastebin.com/7qJh66G6

fbm.jxs: https://pastebin.com/16jDHXPA

Rob Ramirez's icon

you should check out the vtf feature of jit.gl.material, described here . you can set heightmap_mode to vtf_normals, and it will attempt to generate normals based on the distortion texture.

Mathieu Chamagne's icon

there is the same kind of problem with light and jit.gl.material @heightmap_mode vtf_normals :

Max Patch
Copy patch and select New From Clipboard in Max.

(light position is wrong when using heightmap_mode vtf_normals)

aceslowman's icon

This is a really great feature for jit.gl.material, I really need to start using what's already there (although I'm always hopelessly drawn towards doing it myself). Currently, I can't seem to get vtf_normals to display *any* shading, but vtf is returning something (which doesn't appear to be proper shading). Is it related to the format of the heightmap texture?

Anything glaringly wrong about how I'm doing it here?

Max Patch
Copy patch and select New From Clipboard in Max.


hollyhook's icon

Don't know if it helps, but I made a little external glueing the normal calculation of PCL with jitter. It takes a point cloud and nicely calculates the normals, however for real time stuff it might be a bit slow if the number of points gets large

https://www.patreon.com/posts/jit-pcl-normals-11782187

aceslowman's icon

I actually ended up coming to a nice jit.slab solution, calculating the normals and passing them on to jit.material. Example below!

Max Patch
Copy patch and select New From Clipboard in Max.
Mathieu Chamagne's icon

thanks for sharing this solution !

..but :

jit.gl.shader: can't find file normal-mapper.jxs
jit.gl.shader: can't find file fbm.jxs

would you please add these 2 shaders ?

(maybe the one you posted in your previous message called "vertdisplace" is one of these ?...

thanks

Mathieu

aceslowman's icon

Updated previous post!

Mathieu Chamagne's icon

Thanks !

but now, I get these errors comming from normal-mapper.jxs :

-- START GLSL INFO LOG: fp --

ERROR: 0:77: Invalid call of undeclared identifier 'textureOffset'

ERROR: 0:78: Invalid call of undeclared identifier 'textureOffset'

ERROR: 0:79: Invalid call of undeclared identifier 'textureOffset'

ERROR: 0:80: Invalid call of undeclared identifier 'textureOffset'

ERROR: 0:81: Use of undeclared identifier 's21'

ERROR: 0:81: Use of undeclared identifier 's01'

ERROR: 0:82: Use of undeclared identifier 's12'

ERROR: 0:82: Use of undeclared identifier 's10'

ERROR: 0:83: Use of undeclared identifier 'va'

ERROR: 0:83: Use of undeclared identifier 'vb'

ERROR: 0:85: Use of undeclared identifier 'bump'

-- END GLSL INFO LOG: fp --

jit.gl.shader: GLSL program failed to compile.


Any idea ? what's wrong here ?

thanks

Mathieu

Mathieu Chamagne's icon

looks like the same patch & shaders DO work fine in windows.

but still got the same error message on mac (macMini Intel HD Graphics 4000 / macBookPro Radeon Pro 455)

is it possible that these shaders use some instructions that are only available in windows ???

or is it related to the GPU?

aceslowman's icon

Geeze, this slipped totally through the cracks in my email. I think it's a GPU specific thing, textureOffset is consistently the method that fails on Mac (and some Windows). Does anyone else know why this happens? Is it a matter of GLSL version?