View Full Version : Light artifacts
08-19-2010, 05:47 AM
I detected light artifacts in my engine when wall consists of two triangles with texture tiling. If wall has lots of triangles then artifacts are minimal.
I made also screenshot:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">http://www.upload.ee/image/753018/SpotLightArtifacts.png[/QUOTE]</div>
Camera location = light location
Could anyone say what may cause those sharp artifacts?
My shaders are taken from tutorials.
08-19-2010, 06:27 AM
Shaders are incorrect. Post them here.
Guess: the vertex shader computes cos(angle) and interpolates it instead of computing it in the fragment shader.
08-19-2010, 06:52 AM
Thanks for your quick reply.
I just found out that light distortion depends on size of surface. I made some very high walls:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">http://www.upload.ee/image/753187/SpotLightArtifacts2.png[/QUOTE]</div>
Walls are 8x2000. 8x1 is most correct. Looks like lighting is still per vertex somehow...
I have one shader for any type of light. If you see some other wrong coding in shaders, please let me know :D My performance isnt't excellent with shaders binded.
I zipped and uploaded my shaders here (http://www.upload.ee/files/753208/Light.zip.html).
08-19-2010, 07:11 AM
I found a bug in my vertex shader experimentally! Thanks to DmitryM for a hint! :cool:
LightDirection = normalize(Aux);
have to be
LightDirection = Aux;
08-19-2010, 07:25 AM
Yes, that should do it. Be sure to understand why your original code (from what tutorial?) was wrong.
08-19-2010, 07:52 AM
I mixed directional, point and spot lights tutorial codes in here (http://zach.in.tu-clausthal.de/teaching/cg_literatur/glsl_tutorial/).
There are also 'aux' variable normalized in vertex shader. I had spotlight distortions even with clean copy-paste code:
<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">http://www.upload.ee/image/747534/SpotLight.png[/QUOTE]</div>
Could anyone look my shaders, why specular light doesn't work (it's blinking)? :(
Link to my current shaders (http://www.upload.ee/download/753572/74103ac0cf334f3fc05/Light3.zip)
08-19-2010, 02:50 PM
It looks like a very longwinded and convoulted shader. You're calculating the distance in the vertex shader which means that if your scene isn't very high-poly, your shader will interpolate the results, causing squints along the edges of polygons and such.
08-19-2010, 03:27 PM
At the moment my scene is very low-poly. Every surface has 4 vertices with texture tiling. So far I have found only ONE shader which has working specular light (even with my low-poly scene) >> LINK (http://126.96.36.199/forums/viewtopic.php?f=2&t=17999)
All other shaders on the web failed with specular light.
Unfortunately, I had no luck to implement parts of his code into my shader. Always got white screen. I also don't understand 100% his code.
I'll try to calculate distance in fragment program. Anything else that should be in fragment?
Thanks for all of he replies. For the moment only bug is specular lighting and problem lies somewhere in the halfvector calculation.
08-19-2010, 03:29 PM
I get the impression you're trying to piece this together without really knowing how it all works. And believe me, when I was learning this, I couldn't find a working shader anywhere.
08-20-2010, 05:32 PM
I think that I finally get rid of artifacts after hours of work :)
This (http://www.gamedev.net/reference/articles/article2428.asp) tutorial helped me to get correct specular light.
I used dot product of reflect vector and vertex position to calculate specular light.
NormalVector = vec3(gl_NormalMatrix * gl_Normal);
VertexPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
LightPosition = vec4(gl_LightSource.position);
LightVector = vec3(LightPosition.xyz - VertexPosition.xyz * LightPosition.w);
ReflectVector = reflect(normalize(-LightVector), normalize(NormalVector));
RVdotVP = dot(normalize(ReflectVector), normalize(-VertexPosition));
Color += Attenuation * Specular * pow(RdotVP, Shininess);
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.