-1
\$\begingroup\$

I have some Fragmentarium code that I would like to convert so it will work in Godot anyone have any ideas how I can do this?

The code is below:

#include "Progressive2D.frag"

#group Spiral
uniform int StripesNum; slider[1,10,100]
uniform int StripesAng; slider[-180,45,180]
uniform float StripesThinkness; slider[0,0.5,1]
uniform float CenterHole; slider[0,0.125,1]
uniform float OuterHole; slider[0,0.825,1]

const float pi = 3.141592653589793;

vec2 cLog(vec2 z)
{
return vec2(log(length(z)), atan(z.y, z.x));
}

vec3 color(vec2 p)
{
float t = radians(float(StripesAng));
float c = cos(t);
float s = sin(t);
mat2 m = mat2(c, -s, s, c);
vec2 q = m * cLog(p);
return vec3(float
( mod(float(StripesNum) * q.y / (sqrt(2.0) * pi), 1.0) < StripesThinkness
|| length(p) < CenterHole
|| length(p) > OuterHole
));

}

Here's the animation of the code working in Fragmentarium animation of the code working in Fragmentarium

Here's the animation of moire patterns, I'm trying to recreate this in Godot so I can animate multiple copies of spirals turning at different rates (along with using sliders to adjust variables) to produce different moire patterns. moire patterns

Note: // Progressive2D.frag This is a utlity / include for the program to set up anti-aliased 2D rendering. Progressive2D.frag code location

\$\endgroup\$
0
\$\begingroup\$

This code is apparently a fragment shader code. You can use shaders in godot, since it have its own shading language. It's just a bit different from another shading languages, so I think you can learn it fast.

EDIT:

I achieved a similar result with Godot 3. In a scene, insert a sprite, then create a new ImageTexture or simple load any image. After that, create a new ShaderMaterial for Sprite, then create a new Shader for the ShaderMaterial and insert this shader code:

shader_type canvas_item;

// group Spiral
uniform float StripesNum = 9; //slider[1,10,100]
uniform float StripesAng = 45; //slider[-180,45,180]
uniform float StripesThinkness = 0.5; //slider[0,0.5,1]
uniform float CenterHole = 0.125; //slider[0,0.125,1]
uniform float OuterHole = 1; //slider[0,0.825,1]

vec2 cLog(vec2 z){
    return vec2(log(length(z)), atan(z.y, z.x));
}

void fragment(){
    float pi = 3.141592653589793;

    vec2 p = UV.xy - vec2(0.5, 0.5); // correct to the center of texture
    float t = radians(StripesAng);
    float c = cos(t);
    float s = sin(t);
    mat2 m = mat2(vec2(c, -s), vec2(s, c));
    vec2 q = m * cLog(p);

    float color = float(mod(StripesNum * q.y / (sqrt(2.0) * pi), 1.0) < StripesThinkness
        || length(p) < CenterHole
        || length(p) > OuterHole
    );

    COLOR = vec4(vec3(color),1);
}

The result was the following: vortex screenshot at godot

Note the uniform variables: their values can be changed via GDScript with the method set_shader_param from ShaderMaterial.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.