spimort / TerraBrush

MIT License
725 stars 27 forks source link

implement parallax occlusion mapping for textures. #129

Open Dragon20C opened 2 months ago

Dragon20C commented 2 months ago

[what is parallax occlusion mapping?] Parallax occlusion mapping is used to create 3D definition in textured surfaces, using a displacement map (similar to a topography map) instead of through the generation of new geometry. (source wiki : https://en.wikipedia.org/wiki/Parallax_occlusion_mapping)

Parallax occlusion Mapping

As you can see it adds a visual improvement to the texture and gives extra detail without too much of a performance impact, also I think there is multiple ways of getting the desired effect, with each option being more complex then the other, this youtube video on unreal seems to lightly show the difference. (https://www.youtube.com/watch?v=h0xytNFiqbQ)

also I came from the youtube video, who suggested to add this in the comments I felt it needed its own dedicated post here.

spimort commented 2 months ago

Hey @Dragon20C , that's super interesting!

I did make some tests :

Without

image

With

image

My only concern right now is that is seems pretty consuming in term of perfs. Maybe with only one texture it would be easier, but it needs to be applied to all the textures on the terrain, which seems heavy 🫤

Maybe you have better ways to do it than the way I did?

I'm open to suggestions 🙂

Dragon20C commented 2 months ago

Hello @spimort the results looks really amazing, I am no expert in this area, but I can give my opinion on maybe what could be done, so I dont know how is everything applied for the parallax, are you using a distance function to slowly apply the parallax effect only to close objects, this could improve the fps a little, also I am not sure how the texture painting works, but would it be possible to separate the textures using a shader so each material is using a custom shader that does all the texture applying, though I dont know if this is a good idea, I will try to do some research on the topic and see if I can find some interesting results, anyways excellent results!

spimort commented 2 months ago

Thanks @Dragon20C !

I think that one solution would be to allow the user to enable it just for some textures instead of all of them. And yeah, maybe with some distance that would be better, I agree!

The only thing I tried so far was to implement the code that Godot uses to handle the height thing in the standard material. image

But maybe there are other algorithms, I did not do a crazy search about all of this.

I did a pending branch that contains what I've done: https://github.com/spimort/TerraBrush/tree/feature/add-texture-parallax

It's a rough one, stuff are hard coded in the shader right now, just to do the testing.

Dragon20C commented 2 months ago

hello @spimort I am not familiar on how to enable parallax occlusion mapping in the terrabrush node, I made a mesh instance node to make sure the textures work, how do I enable the height in the terrabrush node. Screenshot_20240918_154751 Mesh instance

Screenshot_20240918_154825

Terrabrush terrain , I should also mention I am using the branch you linked to.

Screenshot_20240918_154856

spimort commented 2 months ago

Oh my bad haha, the parallax thing was commented out! I pushed the shader back.

I haven't do anything else on it as of right now.

Also, keep in mind that this branch is only an experiment. Everything is enabled by default, you should see it if you pull the branch.