# Adapt a shader to Godot, one line baffling me

Attention Topic was automatically imported from the old Question2Answer platform.

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?

Believe it or not, there is actually nothing wrong with your shader. It’s the texture you’re using. When I went to test your shader out, I got the same result. That is until I reimported my test texture with the `Repeat` flag enabled. Then it worked just fine.

BTW, uvAlphaTime.w is actually equal to TIME. No sine function.

SIsilicon | 2018-09-22 19:14

Ah hah! , yes, I’m using a viewport sprite texture - the other sprite also has a shader with procedural noise output.

I’m not good enough yet to combine the noise shader and this fake sphere shader so I went about it that confusing way, and the viewport texture dosnt seem to like the rotation as I guess it cannot be repeated in the same way.

But yes - this fake sphere shader does indeed work properly, if I just simply give it an image file texture with repeat flag enabled. Thanks!

davidpwbrown | 2018-09-22 20:26