0 votes

I need a shader that will be used to draw the "floor" of my game. At it's most basic behaviour, it would work as a simple world-space grid that tiles a texture each X pixels.

This shader will be applied to a texture filling the screen and following the camera, but its texture must "remain in place" with origin at the world's origin instead of following the camera.

However, I'm stuck trying to get the basics going. I managed to tile a texture using frac() but I can't figure out how to:
(A) make it retain it's aspect -- the texture is stretched horizontally to fit the screen aspect. I need to scale the UV, but mantaining square pixels.
(B) scroll it somehow to keep its origin at the world origin, instead of following the camera.

I'm using VisualShader but any help is welcome, even if it's pseudocode. I've tried a lot of the built-in nodes trying to make this work, but nothing really worked and the visualshader docs were not very helpful.

Here's a visual explanation in case that helps:
enter image description here

Thanks!

Godot version 3.3.4
in Engine by (191 points)

I ll get to it tomorrow. Until then, is it a problem in your project if You applied shader to square texture ? It is going to follow camera anyway, so part of it can stretch from viewport ? This would get rid of problem of scaling UV.
About scrolling You need to constantly feed camera movement to shader_param and add this vector to UV (or subtract )

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.