Thanks again, I will provide more context now. I have been trying around for hours and hours and just can’t get it to work at all
Also, wouldn’t it mean when just multiplying lightPosition with the gl_ModelViewMatrix solved the problem, that I could just leave it beacuse the originalPosition in the fragmentShader was originally multiplied with the same matrix in the vertex shader too? Confuses me. I tried like every possible combination of multiplying this with that and nothing works.
(Always with varying vec3 originalPos in vertexShader and the light properties (x = 500, y = 500, color = yellow, intensity = 1.0, spotLight = true, spotDirection = 0, angle = 360 (another note: cutoff is angle / 2.0f), spotExponent = 0, linearAttenuation = 0.05) and applied to a 1920 * 1080 white image)
Option 1:
Using the lightPosition as given (like, 500x and 500y, 0z) and the mysteriously transformed originalPos coming from gl_Vertex.
Vertex Shader (both shaders just contain the parts that affect the light in this example, the others dont change and work so far anyway):
originalPos = gl_Vertex;
Fragment Shader:
lightDirection = vec3(lightPosition - originalPos);
distance = length(lightDirection);
spotEffect = dot(normalize(spotDirection[i]), normalize(-lightDirection));
if (spotEffect > spotCosCutOff[i])
{
spotEffect = pow(spotEffect, spotExponent[i]);
attenuation = spotEffect / (1.0 + linearAttenuation[i] * distance + quadraticAttenuation[i] * distance * distance);
color += attenuation * lightColor[i] * ownColor * intensity[i];
}
Result:
[ATTACH=CONFIG]997[/ATTACH]
Doesn’t seem too bad, but doesn’t really work either. Light moves with the texture and the 360 degree angle isn’t quite there. Doesn’t make a difference whether I use 180 or 360 as an angle, other angles seem to work fine, spotExponent, direction and attenuation seem too work too. So just the position and the 360 degree thing (should emit light in every direction).
Option 2:
Vertex Shader:
originalPos = gl_ModelViewMatrix * gl_Vertex;
Fragment Shader:
same as above
Result:
Completely dark screen at x500 and y500. At x0 and y0 it looks like this:
[ATTACH=CONFIG]998[/ATTACH]
Weirder than before. With a spotExponent of 1 however we discover that the light source is somehow outside of the screen (even though it should be at x0 y0 now):
[ATTACH=CONFIG]999[/ATTACH]
It also reacts tto position changes and all sorts of factors, though on a totally different scale (1 in x change looks like 100 pixels). 360 degree angle seems to kinda work here, but I can’t be sure because it is offscreen. A spot direction of 180 (angle → x = -1, y = 0) just flips the whole image horizontally, which is totally not what should happen (it should stay the same because spotDirection shouldn’t matter at a 360 degree angle). When changing spotExponent to 0 and linearAttenuation to 0.1 it almost seems like as if a spotExponent of zero flips the light again, now making it seem almost correct, apart from only being halfway there:
[ATTACH=CONFIG]1000[/ATTACH]
But heyyy, the light position now at least seems to be unaffected by the texture position.
Option 3:
Only multiply light position with modelviewmatrix. Original light properties restored.
Vertex Shader:
originalPos = gl_Vertex;
Fragment Shader:
lightDirection = vec3(vec3(vec4(lightPosition[i], 0.0) * gl_ModelViewMatrix) - originalPos); //lightPosition is a vec3 so I have to cast it to vec4 with 0.0 as w to multiply it with gl_ModelViewMatrix and then cast it back to vec3
//the other part remains the same
Result:
[ATTACH=CONFIG]1001[/ATTACH]
The part I marked should demonstrate the distance 500x and 500y now represents. Kind of works too, but not really. 360 degree doesn’t work either. Position is moving with texture. spotDirection and so on works, but 360 degree and 180 are still the same (how can that even happen? isnt the cos of (180 (which is the cutoff; angle / 2.0f)) -1.0? So basically every other cos should be greater than it, right?).
Option 4:
#1 and #2 combined.
Vertex Shader:
originalPos = gl_ModelViewMatrix * gl_Vertex;
Fragment Shader:
lightDirection = vec3(vec3(vec4(lightPosition[i], 0.0) * gl_ModelViewMatrix) - originalPos);
Result:
http://imgur.com/EDDGOXV (can’t add more than 5 images per post)
Yes, it really is the whole screen. With x0 and y0 it looks like this:
Still not really better though.
Anyone any ideas? It would be super awesome if anyone could tell me why it isn’t working, I have been working on this for days now and nothing really works.