Godot render image with different shaders to a texture

358 views Asked by At

I'm sorry, I can't explain it normally, but I hope you understand.

In general, there is an image from the camera and it is displayed in the game. Also in 3d, the camera creates a depth texture that is not displayed, but it exists and it can be accessed in the shader.

So is it possible to create your own texture like that? I have a sprite and an additional image to it like a normal map or a reflection map, which I want to write into this texture. And then this texture should be accessed in the shader, just like it is done for depth buffer.

In other words, the camera should render the image (which will be this texture) but with other shaders on the objects. Or another way if it is possible

1

There are 1 answers

0
Theraot On

Not directly, but yes, it is possible.

The problem is that the depth buffer is not exposed. You can only ready it form the shaders. This means you will need a material that outputs the depth as color. And you would need to use that in a secondary viewport.

So the idea is to create a SubViewport with a quad that covers the entire view inside, and give this quad a screen reading material that outputs the depth buffer. Then you can get the texture from the SubViewport.

See: