Yes I did, but I still don´t know how to bring this stuff into my existing project. For example, how do you assign a shader to a node? And where do you put in the code, as it is not a regular attached .gd script? I have not dealt with shaders before. Thx.
Infinite ground grid shader
- Edited
vfung Assign a new shader material to the object, create a new shader for that material and with that shader selected paste the code into the shader editor. The official docs cover it in detail: https://docs.godotengine.org/en/stable/tutorials/shaders/shader_materials.html
Thanks, I managed to create the shader material and pasted the code into the shader editor. However I still don´t see the shader "screen" to place in front of the camera.
BTW, the shader code was saved into a .gdshader file, but in your project there is no such file, it looks I´m doing something different.
vfung Try to replicate the node setup from the demo scene. The geometry that has a shader must always be in front of the camera, obscuring the whole camera view. This may seem unintuitive at first but that's how the shader works. It needs full screen "coverage" to draw on.
In the demo project the shader resource is embedded in the scene file but this doesn't really matter. It can be saved in a separate file as well.
Thank you, I got it work.
Hello again. I would like to turn on/off grid depending on the zoom factor (camera distance). Is there a way to do it? Thx.
- Edited
vfung I would like to turn on/off grid depending on the zoom factor (camera distance). Is there a way to do it? Thx.
You can just toggle the visibility of the quad the grid is rendered on, depending on your criteria. Or alternatively, set the alpha component of gridColor
parameter to zero. With the latter approach you can even gradually fade it.
Thanks xyz, but can you please explain in more basic terms. How do I toggle visibility of the quad?
Got it, thank you!
Hey @xyz, big thanks for creating that shader. It's been a lifesaver. I've got a question though. I'm trying to get the grid to display on top of other objects. I tried putting it on a quad mesh, but the grid always ends up behind everything else, no matter what I do to move the quad mesh above other objects. Any tips on how to fix that? Thanks a ton!
- Edited
usual_efficiency_410 The shader outputs proper depth so it's always drawn "on the ground". If you want it to be drawn over everything just replace the line that assigns to DEPTH
with:
DEPTH = 0.0;
Note that you'll also need to keep your camera facing quad or sprite closer to the camera than any other object.
Btw don't assign the shader to a horizontal ground quad or plane because that's not how it's really intended to be used.