0 votes

is there any way to run loops in visual shaders right now? I wanna do ray marching and that requires a loop, which is possible in a text shader (some dude has an open source godot ray marching project with shaders that do it) but I can't find any way to do it in a visual shader

Godot version 3.3
in Engine by (16 points)

Can you add to your (edit) question a link to the ray marching project. Maybe that can give us hints.

Was my answer useful? If so please mark it as such :-)

1 Answer

0 votes

Thanks for the link. I tested with an Expression node with an input Scalar times and output Color color.

color = vec3(0.5,0.1,0.1);
for(int i=0; i < int(times);i++) {
  color = color + 0.1;

so you can add loops :-)

This loop gets injected into the VisualShader output like:

// Expression:3
vec3 n_out3p0;
n_out3p0 = vec3(0.0, 0.0, 0.0);
    n_out3p0 = vec3(0.5,0.1,0.1);
    for(int i=0; i < int(n_out4p0);i++) {
      n_out3p0 = n_out3p0 + 0.1;

by (638 points)

Technically this works but the idea was to create the loop, and the content of said loop, entirely using node

But this is the only method available using an Expression so is the right answer IMHO ;-)

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 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.