Jump to content
  • Advertisement
Sign in to follow this  
Fuggi

[Problem] Pointlight Shader Wont Work

This topic is 2815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, i've been trying to solve this for the good part of today and just cant find a Solution.

The problem is in my Fragment Shader.

varying vec4 diffuse[4];
varying vec4 ambient[4];
varying vec3 normal;
varying vec3 lightDir[4];
varying vec3 halfVector[4];
varying float dist[4];


void main(void)
{
vec3 n, halfV;
float NdotL,NdotHV;
vec4 fragmentColor[6];
vec4 finalColor;
float att;
n = normalize(normal);

for(int i = 0; i < 4; i++)
{
NdotL = max(dot(n,lightDir), 0.0);
if (NdotL > 0.0)
{
att = 1.0 / (gl_LightSource.constantAttenuation
+ gl_LightSource.linearAttenuation * dist
+ gl_LightSource.quadraticAttenuation * dist * dist);

fragmentColor = att * diffuse * NdotL + ambient;

halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);

fragmentColor += att * gl_FrontMaterial.specular * gl_LightSource.specular * pow(NdotHV, gl_FrontMaterial.shininess);
}
}
// This is the latest attempt to get it to work

finalColor = vec4(fragmentColor[0].xyz + fragmentColor[1].xyz + fragmentColor[2].xyz, 1); //Works Fine without the next line
finalColor += vec4(fragmentColor[3].xyz, 1); // This is where the problem is
//finalColor = vec4(fragmentColor[3].xyz, 1); <- Works fine
//finalColor = vec4(6,1,1,1); <- Works Fine
gl_FragColor = finalColor;
}


Everytime I want to add a fourth vec4 to gl_FragColor or assign the a vec4 that is the sum of 4 differente vec4s the Shader just wont work.
If its three vec4s there is no problem

Share this post


Link to post
Share on other sites
Advertisement

Can you define what "wont work" means in your case?

Are you checking glsl compiler errors/warnings?


Ah ok, i'm just so pissed right now, i forgot to explain.
So I am a student, and I have a JoGL course, so I am pretty much a Newbie when it comes to shaders.

However, I want to use 4 of the fixed pipeline Lights in my shader. For now just pointlights.

In my Java Framework I load these Shaders using a class I wrote myself, this class has very little debugging possibilities. All I can tell you is:
The Fragment and Vertex Shaders are appearantly fine, the program consisting of the two is not, which leads my Program to just use the fixed Pipeline rendering.

I use this to get the information


gl.glGetShaderiv(vert, GL2.GL_COMPILE_STATUS, test, 0);
<- returns GL_TRUE in my framework

gl.glGetShaderiv(frag, GL2.GL_COMPILE_STATUS, test, 0);
<- returns GL_TRUE in my framework


gl.glGetProgramiv(shaderProgram, GL2.GL_LINK_STATUS, test,0);
<- returns GL_FALSE in my framework


Please excuse my horrible english as i am not a native speaker.

Share this post


Link to post
Share on other sites

So it appears your compiler doesn't like something about your shader.

Read this article: http://www.lighthous...dex.php?oglinfo

and use that information to get the full error logs from the shader compiler and linker. It should give you some explanation of what's going wrong.


Ok, i did this it what i get:

Error in Program validate!
lne=14036
Vertex info
-----------
Internal error: assembly compile error for vertex shader at offset 13816:
-len2=99
[/quote]

Share this post


Link to post
Share on other sites
Hmm that's less helpful than I'd hoped =\

Could be some kind of implementation variable limit... maybe instead of storing each loop in it's own vec4, you can just add it to the total as you iterate over each light?

I'm stumped though.

Share this post


Link to post
Share on other sites

Hmm that's less helpful than I'd hoped =\

Could be some kind of implementation variable limit... maybe instead of storing each loop in it's own vec4, you can just add it to the total as you iterate over each light?

I'm stumped though.


I tried that, thats the reason I introduced the finalColor variable. So inside the loop i did finalColor += color, before that it was just:

gl_FragColor = color[0] + color[1] + color[2] + color[3];

though, the truly screwed up part is:
gl_FragColor = color[0] + color[1] + color[2];
or
gl_FragColor = color[1] + color[2] + color[3];
or
gl_FragColor = color[0] + color[1] + color[3];
and so on will work

Thanks btw for your quick responses :P

Share this post


Link to post
Share on other sites
ok, with
finalColor = vec4(fragmentColor[3]) + vec4(fragmentColor[2]) + vec4(fragmentColor[1]) + vec4(fragmentColor[0]);

i get this now
Fragment info
-------------
0(20) : error C5025: lvalue in array access too complex
0(23) : error C[/quote]

Share this post


Link to post
Share on other sites
Looks like you're cutting off the end of the log, make sure you're reading all of it (query the length before you allocate the char buffer).

Share this post


Link to post
Share on other sites
you are right, i had the wrong length in the display loop. Well, here is the rest

Vertex info
-----------
Internal error: assembly compile error for vertex shader at offset 13816:
-- error message --
line 238, column 1: error: too many result variable components written
-- internal assembly text --
!!NVvp4.0
OPTION NV_parameter_buffer_object2;
# cgc version 3.0.0001, build date Jul 9 2010
# command line args:
#vendor NVIDIA Corporation
#version 3.0.0.1
#profile gp4vp
#program main
#semantic gl_NormalMatrix : state.matrix.modelview.inverse
#semantic gl_ModelViewMatrix : state.matrix.modelview.transpose
#semantic gl_LightSource : state.light
#semantic gl_FrontMaterial : state.material.front
#semantic gl_ModelViewProjectionMatrixTranspose : state.matrix.mvp
#var float3 gl_Normal : $vin.NORMAL : ATTR2 : -1 : 1
#var float3x3 gl_NormalMatrix : state.matrix.modelview.inverse : c[0], 3 : -1 : 1
#var float4 gl_Vertex : $vin.POSITION : ATTR0 : -1 : 1
#var float4x4 gl_ModelViewMatrix : state.matrix.modelview.transpose : c[3], 4 : -1 : 1
#var float4 gl_LightSource[0].ambient : state.light[0].ambient : c[7] : -1 : 1
#var float4 gl_LightSource[0].diffuse : state.light[0].diffuse : c[8] : -1 : 1
#var float4 gl_LightSource[0].specular : state.light[0].specular : c[9] : -1 : 0
#var float4 gl_LightSource[0].position : state.light[0].position : c[10] : -1 : 1
#var float4 gl_LightSource[0].halfVector : state.light[0].half : c[11] : -1 : 1
#var float3 gl_LightSource[0].spotDirection : state.light[0].spot.direction : c[12] : -1 : 0
#var float gl_LightSource[0].spotExponent : state.light[0].attenuation.w : c[13] : -1 : 0
#var float gl_LightSource[0].spotCutoff : state.light[0].spot.cutoff.x : c[14] : -1 : 0
#var float gl_LightSource[0].spotCosCutoff : state.light[0].spot.direction.w : c[15] : -1 : 0
#var float gl_LightSource[0].constantAttenuation : state.light[0].attenuation.x : c[16] : -1 : 0
#var float gl_LightSource[0].linearAttenuation : state.light[0].attenuation.y : c[17] : -1 : 0
#var float gl_LightSource[0].quadraticAttenuation : state.light[0].attenuation.z : c[18] : -1 : 0
#var float4 gl_LightSource[1].ambient : state.light[1].ambient : c[19] : -1 : 1
#var float4 gl_LightSource[1].diffuse : state.light[1].diffuse : c[20] : -1 : 1
#var float4 gl_LightSource[1].specular : state.light[1].specular : c[21] : -1 : 0
#var float4 gl_LightSource[1].position : state.light[1].position : c[22] : -1 : 1
#var float4 gl_LightSource[1].halfVector : state.light[1].half : c[23] : -1 : 1
#var float3 gl_LightSource[1].spotDirection : state.light[1].spot.direction : c[24] : -1 : 0
#var float gl_LightSource[1].spotExponent : state.light[1].attenuation.w : c[25] : -1 : 0
#var float gl_LightSource[1].spotCutoff : state.light[1].spot.cutoff.x : c[26] : -1 : 0
#var float gl_LightSource[1].spotCosCutoff : state.light[1].spot.direction.w : c[27] : -1 : 0
#var float gl_LightSource[1].constantAttenuation : state.light[1].attenuation.x : c[28] : -1 : 0
#var float gl_LightSource[1].linearAttenuation : state.light[1].attenuation.y : c[29] : -1 : 0
#var float gl_LightSource[1].quadraticAttenuation : state.light[1].attenuation.z : c[30] : -1 : 0
#var float4 gl_LightSource[2].ambient : state.light[2].ambient : c[31] : -1 : 1
#var float4 gl_LightSource[2].diffuse : state.light[2].diffuse : c[32] : -1 : 1
#var float4 gl_LightSource[2].specular : state.light[2].specular : c[33] : -1 : 0
#var float4 gl_LightSource[2].position : state.light[2].position : c[34] : -1 : 1
#var float4 gl_LightSource[2].halfVector : state.light[2].half : c[35] : -1 : 1
#var float3 gl_LightSource[2].spotDirection : state.light[2].spot.direction : c[36] : -1 : 0
#var float gl_LightSource[2].spotExponent : state.light[2].attenuation.w : c[37] : -1 : 0
#var float gl_LightSource[2].spotCutoff : state.light[2].spot.cutoff.x : c[38] : -1 : 0
#var float gl_LightSource[2].spotCosCutoff : state.light[2].spot.direction.w : c[39] : -1 : 0
#var float gl_LightSource[2].constantAttenuation : state.light[2].attenuation.x : c[40] : -1 : 0
#var float gl_LightSource[2].linearAttenuation : state.light[2].attenuation.y : c[41] : -1 : 0
#var float gl_LightSource[2].quadraticAttenuation : state.light[2].attenuation.z : c[42] : -1 : 0
#var float4 gl_LightSource[3].ambient : state.light[3].ambient : c[43] : -1 : 1
#var float4 gl_LightSource[3].diffuse : state.light[3].diffuse : c[44] : -1 : 1
#var float4 gl_LightSource[3].specular : state.light[3].specular : c[45] : -1 : 0
#var float4 gl_LightSource[3].position : state.light[3].position : c[46] : -1 : 1
#var float4 gl_LightSource[3].halfVector : state.light[3].half : c[47] : -1 : 1
#var float3 gl_LightSource[3].spotDirection : state.light[3].spot.direction : c[48] : -1 : 0
#var float gl_LightSource[3].spotExponent : state.light[3].attenuation.w : c[49] : -1 : 0
#var float gl_LightSource[3].spotCutoff : state.light[3].spot.cutoff.x : c[50] : -1 : 0
#var float gl_LightSource[3].spotCosCutoff : state.light[3].spot.direction.w : c[51] : -1 : 0
#var float gl_LightSource[3].constantAttenuation : state.light[3].attenuation.x : c[52] : -1 : 0
#var float gl_LightSource[3].linearAttenuation : state.light[3].attenuation.y : c[53] : -1 : 0
#var float gl_LightSource[3].quadraticAttenuation : state.light[3].attenuation.z : c[54] : -1 : 0
#var float4 gl_LightSource[4].ambient : state.light[4].ambient : c[55] : -1 : 0
#var float4 gl_LightSource[4].diffuse : state.light[4].diffuse : c[56] : -1 : 0
#var float4 gl_LightSource[4].specular : state.light[4].specular : c[57] : -1 : 0
#var float4 gl_LightSource[4].position : state.light[4].position : c[58] : -1 : 0
#var float4 gl_LightSource[4].halfVector : state.light[4].half : c[59] : -1 : 0
#var float3 gl_LightSource[4].spotDirection : state.light[4].spot.direction : c[60] : -1 : 0
#var float gl_LightSource[4].spotExponent : state.light[4].attenuation.w : c[61] : -1 : 0
#var float gl_LightSource[4].spotCutoff : state.light[4].spot.cutoff.x : c[62] : -1 : 0
#var float gl_LightSource[4].spotCosCutoff : state.light[4].spot.direction.w : c[63] : -1 : 0
#var float gl_LightSource[4].constantAttenuation : state.light[4].attenuation.x : c[64] : -1 : 0
#var float gl_LightSource[4].linearAttenuation : state.light[4].attenuation.y : c[65] : -1 : 0
#var float gl_LightSource[4].quadraticAttenuation : state.light[4].attenuation.z : c[66] : -1 : 0
#var float4 gl_LightSource[5].ambient : state.light[5].ambient : c[67] : -1 : 0
#var float4 gl_LightSource[5].diffuse : state.light[5].diffuse : c[68] : -1 : 0
#var float4 gl_LightSource[5].specular : state.light[5].specular : c[69] : -1 : 0
#var float4 gl_LightSource[5].position : state.light[5].position : c[70] : -1 : 0
#var float4 gl_LightSource[5].halfVector : state.light[5].half : c[71] : -1 : 0
#var float3 gl_LightSource[5].spotDirection : state.light[5].spot.direction : c[72] : -1 : 0
#var float gl_LightSource[5].spotExponent : state.light[5].attenuation.w : c[73] : -1 : 0
#var float gl_LightSource[5].spotCutoff : state.light[5].spot.cutoff.x : c[74] : -1 : 0
#var float gl_LightSource[5].spotCosCutoff : state.light[5].spot.direction.w : c[75] : -1 : 0
#var float gl_LightSource[5].constantAttenuation : state.light[5].attenuation.x : c[76] : -1 : 0
#var float gl_LightSource[5].linearAttenuation : state.light[5].attenuation.y : c[77] : -1 : 0
#var float gl_LightSource[5].quadraticAttenuation : state.light[5].attenuation.z : c[78] : -1 : 0
#var float4 gl_LightSource[6].ambient : state.light[6].ambient : c[79] : -1 : 0
#var float4 gl_LightSource[6].diffuse : state.light[6].diffuse : c[80] : -1 : 0
#var float4 gl_LightSource[6].specular : state.light[6].specular : c[81] : -1 : 0
#var float4 gl_LightSource[6].position : state.light[6].position : c[82] : -1 : 0
#var float4 gl_LightSource[6].halfVector : state.light[6].half : c[83] : -1 : 0
#var float3 gl_LightSource[6].spotDirection : state.light[6].spot.direction : c[84] : -1 : 0
#var float gl_LightSource[6].spotExponent : state.light[6].attenuation.w : c[85] : -1 : 0
#var float gl_LightSource[6].spotCutoff : state.light[6].spot.cutoff.x : c[86] : -1 : 0
#var float gl_LightSource[6].spotCosCutoff : state.light[6].spot.direction.w : c[87] : -1 : 0
#var float gl_LightSource[6].constantAttenuation : state.light[6].attenuation.x : c[88] : -1 : 0
#var float gl_LightSource[6].linearAttenuation : state.light[6].attenuation.y : c[89] : -1 : 0
#var float gl_LightSource[6].quadraticAttenuation : state.light[6].attenuation.z : c[90] : -1 : 0
#var float4 gl_LightSource[7].ambient : state.light[7].ambient : c[91] : -1 : 0
#var float4 gl_LightSource[7].diffuse : state.light[7].diffuse : c[92] : -1 : 0
#var float4 gl_LightSource[7].specular : state.light[7].specular : c[93] : -1 : 0
#var float4 gl_LightSource[7].position : state.light[7].position : c[94] : -1 : 0
#var float4 gl_LightSource[7].halfVector : state.light[7].half : c[95] : -1 : 0
#var float3 gl_LightSource[7].spotDirection : state.light[7].spot.direction : c[96] : -1 : 0
#var float gl_LightSource[7].spotExponent : state.light[7].attenuation.w : c[97] : -1 : 0
#var float gl_LightSource[7].spotCutoff : state.light[7].spot.cutoff.x : c[98] : -1 : 0
#var float gl_LightSource[7].spotCosCutoff : state.light[7].spot.direction.w : c[99] : -1 : 0
#var float gl_LightSource[7].constantAttenuation : state.light[7].attenuation.x : c[100] : -1 : 0
#var float gl_LightSource[7].linearAttenuation : state.light[7].attenuation.y : c[101] : -1 : 0
#var float gl_LightSource[7].quadraticAttenuation : state.light[7].attenuation.z : c[102] : -1 : 0
#var float4 gl_FrontMaterial.emission : state.material.front.emission : : -1 : 0
#var float4 gl_FrontMaterial.ambient : state.material.front.ambient : c[103] : -1 : 1
#var float4 gl_FrontMaterial.diffuse : state.material.front.diffuse : c[104] : -1 : 1
#var float4 gl_FrontMaterial.specular : state.material.front.specular : : -1 : 0
#var float gl_FrontMaterial.shininess : state.material.front.shininess : : -1 : 0
#var float4 gl_Position : $vout.POSITION : HPOS : -1 : 1
#var float4x4 gl_ModelViewProjectionMatrixTranspose : state.matrix.mvp : c[105], 4 : -1 : 1
#var float4 diffuse[0] : $vout.ATTR0 : ATTR0 : -1 : 1
#var float4 diffuse[1] : $vout.ATTR1 : ATTR1 : -1 : 1
#var float4 diffuse[2] : $vout.ATTR2 : ATTR2 : -1 : 1
#var float4 diffuse[3] : $vout.ATTR3 : ATTR3 : -1 : 1
#var float4 ambient[0] : $vout.ATTR4 : ATTR4 : -1 : 1
#var float4 ambient[1] : $vout.ATTR5 : ATTR5 : -1 : 1
#var float4 ambient[2] : $vout.ATTR6 : ATTR6 : -1 : 1
#var float4 ambient[3] : $vout.ATTR7 : ATTR7 : -1 : 1
#var float3 normal : $vout.ATTR8.xyz : ATTR8 : -1 : 1
#var float3 lightDir[0] : $vout.ATTR9.xyz : ATTR9 : -1 : 1
#var float3 lightDir[1] : $vout.ATTR10.xyz : ATTR10 : -1 : 1
#var float3 lightDir[2] : $vout.ATTR11.xyz : ATTR11 : -1 : 1
#var float3 lightDir[3] : $vout.ATTR12.xyz : ATTR12 : -1 : 1
#var float3 halfVector[0] : $vout.ATTR13.xyz : ATTR13 : -1 : 1
#var float3 halfVector[1] : $vout.ATTR14.xyz : ATTR14 : -1 : 1
#var float3 halfVector[2] : $vout.ATTR15.xyz : ATTR15 : -1 : 1
#var float3 halfVector[3] : $vout.ATTR16.xyz : ATTR16 : -1 : 1
#var float dist[0] : $vout.ATTR17.x : ATTR17 : -1 : 1
#var float dist[1] : $vout.ATTR18.x : ATTR18 : -1 : 1
#var float dist[2] : $vout.ATTR19.x : ATTR19 : -1 : 1
#var float dist[3] : $vout.ATTR20.x : ATTR20 : -1 : 1
PARAM c[109] = { state.matrix.modelview.inverse.row[0..2],
state.matrix.modelview.transpose.row[0..3],
state.light[0].ambient,
state.light[0].diffuse,
program.local[9],
state.light[0].position,
state.light[0].half,
program.local[12..18],
state.light[1].ambient,
state.light[1].diffuse,
program.local[21],
state.light[1].position,
state.light[1].half,
program.local[24..30],
state.light[2].ambient,
state.light[2].diffuse,
program.local[33],
state.light[2].position,
state.light[2].half,
program.local[36..42],
state.light[3].ambient,
state.light[3].diffuse,
program.local[45],
state.light[3].position,
state.light[3].half,
program.local[48..102],
state.material.front.ambient,
state.material.front.diffuse,
state.matrix.mvp.row[0..3] };
ATTRIB vertex_attrib[] = { vertex.attrib[0..2] };
OUTPUT result_attrib[] = { result.attrib[0..20] };
TEMP R0, R1, R2, R3;
MUL.F R0.xyz, vertex.attrib[0].y, c[4];
MAD.F R1.xyz, vertex.attrib[0].x, c[3], R0;
MAD.F R1.xyz, vertex.attrib[0].z, c[5], R1;
MAD.F R2.xyz, vertex.attrib[0].w, c[6], R1;
ADD.F R1.xyz, -R2, c[10];
DP3.F R1.w, R1, R1;
MUL.F R0.xyz, vertex.attrib[2].y, c[1];
MAD.F R0.xyz, vertex.attrib[2].x, c[0], R0;
MAD.F R0.xyz, vertex.attrib[2].z, c[2], R0;
DP3.F R0.w, R0, R0;
RSQ.F R0.w, R0.w;
MUL.F result.attrib[8].xyz, R0.w, R0;
ADD.F R0.xyz, -R2, c[22];
RSQ.F R2.w, R1.w;
MUL.F result.attrib[9].xyz, R2.w, R1;
MOV.F R1, c[8];
MUL.F result.attrib[0], R1, c[104];
MOV.F R1, c[7];
MUL.F result.attrib[4], R1, c[103];
ADD.F R1.xyz, -R2, c[34];
DP3.F R1.w, R1, R1;
DP3.F R0.w, R0, R0;
RSQ.F R3.x, R0.w;
MUL.F result.attrib[10].xyz, R3.x, R0;
MOV.F R0, c[20];
MUL.F result.attrib[1], R0, c[104];
MOV.F R0, c[19];
MUL.F result.attrib[5], R0, c[103];
RSQ.F R3.y, R1.w;
MUL.F result.attrib[11].xyz, R3.y, R1;
ADD.F R1.xyz, -R2, c[46];
MOV.F R0, c[32];
MUL.F result.attrib[2], R0, c[104];
DP3.F R1.w, R1, R1;
MOV.F R0, c[31];
MUL.F result.attrib[6], R0, c[103];
RSQ.F R2.x, R1.w;
MUL.F result.attrib[12].xyz, R2.x, R1;
MOV.F R0, c[44];
MUL.F result.attrib[3], R0, c[104];
MOV.F R1, c[43];
MUL.F result.attrib[7], R1, c[103];
DP3.F R0.x, c[11], c[11];
RSQ.F R0.x, R0.x;
RCP.F result.attrib[17].x, R2.w;
MUL.F result.attrib[13].xyz, R0.x, c[11];
DP3.F R0.y, c[23], c[23];
RSQ.F R0.x, R0.y;
RCP.F result.attrib[18].x, R3.x;
MUL.F result.attrib[14].xyz, R0.x, c[23];
DP3.F R0.x, c[35], c[35];
RSQ.F R0.x, R0.x;
RCP.F result.attrib[19].x, R3.y;
MUL.F result.attrib[15].xyz, R0.x, c[35];
DP3.F R0.y, c[47], c[47];
RSQ.F R0.x, R0.y;
RCP.F result.attrib[20].x, R2.x;
MUL.F result.attrib[16].xyz, R0.x, c[47];
DP4.F result.position.w, vertex.attrib[0], c[108];
DP4.F result.position.z, vertex.attrib[0], c[107];
DP4.F result.position.y, vertex.attrib[0], c[106];
DP4.F result.position.x, vertex.attrib[0], c[105];
END
# 62 instructions, 4 R-regs
[/quote]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!