17 Replies  2202 Views  Last Post: 10 February 2011  05:52 AM
#1
Question about openGL shaders
Posted 08 February 2011  03:58 AM
Thanks in advances for any advice.
Dave
Replies To: Question about openGL shaders
#2
Re: Question about openGL shaders
Posted 08 February 2011  06:18 AM
#3
Re: Question about openGL shaders
Posted 08 February 2011  01:29 PM
#4
Re: Question about openGL shaders
Posted 08 February 2011  04:36 PM
#5
Re: Question about openGL shaders
Posted 09 February 2011  05:41 AM
#6
Re: Question about openGL shaders
Posted 09 February 2011  05:52 AM
#7
Re: Question about openGL shaders
Posted 09 February 2011  06:29 AM
#8
Re: Question about openGL shaders
Posted 09 February 2011  09:58 AM
#9
Re: Question about openGL shaders
Posted 09 February 2011  12:08 PM
I've nearly got it shader to work but I'm still having some problems with multiple spot lights, for some reason I'm getting the occassional shader artifact when using more than one spot light ( certain areas go strainge/black then the spot light heads towards it ) I don't suppose you might know what could be causing this, I'm lead to believe that it have something to do with the final color calculation but I can't find anything on google that helps:
Here is my shader code for the spot lights:
#version 130 uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat3 normal_matrix; uniform vec4 material_ambient; uniform vec4 material_diffuse; uniform vec4 material_specular; uniform vec4 material_emissive; uniform float material_shininess; uniform struct { vec4 position; vec4 diffuse; vec4 specular; vec4 ambient; float constant_attenuation; float linear_attenuation; float quadratic_attenuation; float spotCutOff; vec3 spotDirection; float spotExponent; } light[2]; in vec3 a_Vertex; in vec2 a_TexCoord0; in vec3 a_Normal; out vec4 color; out vec2 texCoord0; vec4 finalColor; float attenuation[2]; void main(void) { vec3 N = normalize(normal_matrix * a_Normal); vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0); vec3 E = (pos.xyz); for( int i = 0; i < 2; ++i ) { vec3 lightPos = (modelview_matrix * light[i].position).xyz; vec3 lightDir = (lightPos  pos.xyz).xyz; float NdotL = max(dot(N, lightDir.xyz), 0.0); float dist = length(lightDir); finalColor = material_ambient * light[i].ambient; attenuation[i] = 1.0; //If the surface is facing the light source if (NdotL > 0.0) { //Find the angle between the light direction and spotlight direction float spotEffect = dot(normalize(light[i].spotDirection), normalize(lightDir)); //If it's greater than the cosine of the spotlight cutoff then it should be illuminated if (spotEffect > cos(light[i].spotCutOff)) { vec3 HV = normalize(lightPos + E); float NdotHV = max(dot(N, HV), 0.0); finalColor += material_specular * light[i].specular * pow(NdotHV, material_shininess); spotEffect = pow(spotEffect, light[i].spotExponent); attenuation[i] = spotEffect / (light[i].constant_attenuation + light[i].linear_attenuation * dist + light[i].quadratic_attenuation * dist * dist); finalColor += material_diffuse * light[i].diffuse * NdotL; } } } color = material_emissive + (finalColor * attenuation[0]) + (finalColor * attenuation[1]); texCoord0 = a_TexCoord0; gl_Position = projection_matrix * pos; }
I've had a mess around with the color = section but still gives me artifacts either way but works fine if i'm only applying one attenuation reather than two?
#10
Re: Question about openGL shaders
Posted 09 February 2011  12:19 PM
#11
Re: Question about openGL shaders
Posted 09 February 2011  12:36 PM
color = finalColor * attenuation[0];or
color = finalColor * attenuation[1];it only happens when I try to get them both on the scene at the same time, it takes both light sources into account but still with artifacts when the second light reaches near the edge of the terrain. attatched is a screenshot.
#12
Re: Question about openGL shaders
Posted 09 February 2011  12:46 PM
#13
Re: Question about openGL shaders
Posted 09 February 2011  03:19 PM
Edit:
My test is comfirmed, I stopped the light[0]'s moving pattern so that it was stationary and light[1] works fine then so I'll need to look into the calculations some more.
This post has been edited by Kain6622: 09 February 2011  03:33 PM
#14
Re: Question about openGL shaders
Posted 09 February 2011  04:12 PM
#15
Re: Question about openGL shaders
Posted 09 February 2011  04:25 PM
