Hi everyone,
I followed this example
https://forum.thegamecreators.com/thread/212611 but I have a problem and a request:
1) If it is used on win or mac, everything works correctly, but if it is used on mobile the coordinates of positioning of the lights are wrong.
I modified the original shader with at most 2 lights; one for the environment, the other as lighting related to the sprite in motion (android api 5.1 min-sdk is my target and manages at most 2 lights, over the fps collapses).
form:
vec3 GLight;
for(int i=0; i < int(LightCount); i++)
{
GLight = GLight + light(LightPosition[i], LightColor[i]);
}
to
GLight = light(LightPosition[i, LightColor[0]) + light(LightPosition[i, LightColor[0]);
This is because in iOs the for-next cycle causes an incorrect display
2) I would like to create, as a second light, a trapezoidal spotlight able to rotate, is it possible?
Thanks
my Full shader:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uvVarying;
varying vec2 posVarying;
uniform vec4 LP[2];
uniform vec4 LC[2];
uniform vec4 Resolution;
uniform vec4 AmbientColor;
uniform vec3 Falloff;
vec3 light(vec4 TLightPos, vec4 TLightColor)
{
TLightPos.y = Resolution.y - TLightPos.y;
vec3 normal = texture2D(texture1, uvVarying.xy ).rgb;
vec3 LightDir = vec3(TLightPos.xy - gl_FragCoord.xy, TLightPos.z);
vec3 LDIR=normalize(LightDir);
normal = normal * 2.0 - 1.0;
vec3 NDIR=normalize(normal);
float distance = length(LightDir);
float Attenuation = clamp((0.1 / (Falloff.x +(Falloff.y * distance) +(Falloff.z * distance * distance))) * TLightPos.w,0.0,1.0);
return TLightColor.rgb * max(dot(NDIR, LDIR), 0.0) * Attenuation;
}
void main()
{
vec4 diffuse = texture2D(texture0, uvVarying.xy);
vec3 PLight = light(LP[0],LC[0]) + light(LP[1],LC[1]);
gl_FragColor = diffuse * (AmbientColor + vec4(PLight,0.0));
}
My agc Settings:
Ps: As a "Resolution" directive, I tested the coordinates based on the virtual resolution, the sum of the horizontal and vertical GetScreenBounds and the native resolution of the device, but the shader in any case position the lights according to incorrect coordinates (mobile, desktop ok).
SetShaderConstantArrayByName( game.shader_master, "LC",0, 1.0,0.8,0.6, 1.0 )
SetShaderConstantByName( game.shader_master, "Resolution",GetDeviceWidth(),GetDeviceHeight(),0.0, 0.0 )
SetShaderConstantByName( game.shader_master, "AmbientColor", 0.1,0.1,0.1, 1.0 )
SetShaderConstantByName( game.shader_master, "Falloff", 0.1,0.01,0.001, 0.0 )
// setting light 1
SetShaderConstantArrayByName( game.shader_master, "LC",1, 1.0, 0.8, 0.6, 1.0 )
SetShaderConstantArrayByName( game.shader_master, "LP",1,50,300,100, 300 )