J
Jasnsathome
Guest
I am trying to figure out how to use shaders to make a 2d texture appear as a sphere with a shadow. I found this example that is exactly what I want and tried to make it work in gamemaker but am having problems.
http://clockworkchilli.com/blog/2_3d_shaders_in_a_2d_world
This is my first try at shaders so I do not understand much of it I have been reading tutorials and xors examples but cannot figure out how to make it work right. It will compile and display a square and the lighting part somwhat but the texture displays like a single pixel takes up the whole square.
this is what I have for the fragment and I haven't changed the vertex at all yet.
Does any of this go into the Vertex segment? Do I need to use the inPosition.xy for the fragment part?
If the problem is apparent to someone experienced I would appreciate any help. I'm going to continue to figure out what everything is doing. Thanks.
http://clockworkchilli.com/blog/2_3d_shaders_in_a_2d_world
This is my first try at shaders so I do not understand much of it I have been reading tutorials and xors examples but cannot figure out how to make it work right. It will compile and display a square and the lighting part somwhat but the texture displays like a single pixel takes up the whole square.
this is what I have for the fragment and I haven't changed the vertex at all yet.
Code:
uniform float iTime;
uniform sampler2D iTex;
uniform vec3 lightDir;
uniform vec2 iCoord;
const float PI = 3.14159265358;
vec3 l = normalize(lightDir);
vec2 uv = iCoord.xy;
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 = iTime * 0.1;
vec2 texCoords = vec2(0.5 + atan(normal.x, normal.z) / (2.*PI) + rot, asin(normal.y) / PI - 0.5);
vec3 texColor = texture2D(iTex, texCoords, 0.).xyz;
vec3 lightColor = vec3(ndotl) * texColor;
vec4 inside = vec4(lightColor, 1.);
vec4 outside = vec4(0.);
void main()
{
gl_FragColor = radius <= 1.? inside: outside;
}
If the problem is apparent to someone experienced I would appreciate any help. I'm going to continue to figure out what everything is doing. Thanks.