Attention |
Topic was automatically imported from the old Question2Answer platform. | |

Asked By |
davidpwbrown |

I’m adapting this shader to Godot : - 3D Shaders In A 2D World

and its kinda working so far, I have the circle, I have the light source, but I cannot get the distortion or rotation

as below

```
const float PI = 3.141592653589793238462643383;
vec3 l = normalize(lightDir);
vec2 uv = (uvAlphaTime.xy - 0.5) * 2.;
float radius = length(uv);
vec3 normal = vec3(uv.x, uv.y, sqrt(1. - uv.x*uv.x - uv.y*uv.y));
float ndotl = max(0., dot(normal, l));
float rot = uvAlphaTime.w * 0.1;
vec2 texCoords = vec2(0.5 + atan(normal.x, normal.z) / (2.*PI) + rot, asin(normal.y) / PI - 0.5);
vec3 texColor = texture2D(uDiffuseSampler, texCoords, 0.).xyz;
vec3 lightColor = vec3(ndotl) * texColor;
vec4 inside = vec4(lightColor, 1.);
vec4 outside = vec4(0.);
gl_FragColor = radius <= 1.? inside: outside;
```

Adapting it to Godot Im halfway there :-

```
void fragment() {
vec2 circle = (UV - 0.5) * 2.0;
float rot = sin(TIME) * 10.0;
float radius = length(circle);
vec3 normal = vec3(circle.x, circle.y, sqrt(1.0 - circle.x*circle.x - circle.y*circle.y));
vec3 l = normalize(lightDir);
float ndotl = max(0.0, dot(normal, l));
vec2 texCoords = vec2(0.5 + atan(normal.x, normal.z) / (2.0*PI) + rot, asin(normal.y) / PI - 0.5);
vec3 texColor = texture(TEXTURE, UV).xyz;
vec3 lightColor = vec3(ndotl) * texColor;
vec4 inside = vec4(lightColor, 1.0);
vec4 outside = vec4(0.0);
COLOR = radius <= 1.0? inside: outside;
```

}

the problem lines are

vec2 texCoords = vec2(0.5 + atan(normal.x, normal.z) / (2.0*PI) + rot, asin(normal.y) / PI - 0.5);

vec3 texColor = texture(TEXTURE, **UV**).xyz;

For the moment, in bold, I’ve substituted in UV as texCoord does not work there as it needs to.

Im assuming sin(TIME) can be used as a substitute for that shader languages “uvalphatime”

I understand the texCoord line distorts and rotates, and then you use those coords to set colors, but it just outputs black when I replace UV with texCoord.

Can anyone see how that code can be adapted to Godot shader language?