A problem about if-else in for-loop

Hi, all.

I tried to write a if-else statement to chose a vector form to different arrays in for loop yesterday.  But an odd thing occurred, my program has linking error. 

The error is as follows :

Vertex info

Internal error: assembly compile error for vertex shader at offset 17290:
– error message –
line 362, column 1: error: too many result variable components written.

I have no idea why the error appears. Does every one encounter this problem as like as my problem ?

P.S. I post my code as follows.


//-- Fragment Shader
#version 120
varying vec4 world_l[8];   //(World CS)
varying vec4 tangent_l[8]; //(Tangent CS)
for( i = 0 ; i < light_number ; i++)
{
	if(normal_texture_existed_singal == true)
	{
		final_l = tangent_l[i];
		...
	}
	else
	{
		final_l = world_l[i];
		...
	}
	
	PhongBlinnShading( do ...);
}

If I modify the world_l[i] and tangent_l[i] to world_l[0] and tangent_l[0] in fragment shader, then the it will work.

I list my system information as follows :

OS : Window7
Graphics Card: G105M
Driver : 314.22

thanks.

Hi, all.

I have a new discovery about my problem

If I decrease my number of declaration for varying array, the shader can work.

But I don’t know how many varying variable we can use ??

And I have a other question. How can we handle multi-lighting in glsl ?

If we needs to calculate the phong shading effects of lights, we have to store the vectors of vertex to light sources.

Then there are eight light sources founded in OpenGL. If I render a scene with eight lights. How can I solve it ?

you’ve exceeded varying limit. you can get it by querying GL_MAX_VARYING_FLOATS with glGet. when you replace “i” with “0” in your code, compiler just optimizes out unused varyings.

varying vec4 world_l[8];
varying vec4 tangent_l[8];

  • 64 varyings already. and there are probably others you didn’t include in your example. your card, most likely, has a limit of 32 varying floats.

most likely you’ll have to optimize your shader in such way that it will use less varyings(like make a limit of 2-3 lights per object, and find most contributing lights on CPU for every object), or switch to another method of rendering multiple lights(see deferred lighting). or consider targeting different hardware, because G105M is really limited. you may also consider calculating tangent-space-normal-mapping only for main distant light(like sun) and for local lights use regular normals(passed with vertex attributes) without bump-mapping

To Nowhere-01 :

Thank you very much.

I will follow you advices to modify my shading program.

Sincerely yours,

La-La, Chen.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.