Hello everyone,
I’m using gles2 for my ipad project. right now, I’m working on duplicating the opengl fix pipeline. but I met some problems.
I want to support more lights in the scene and I store all the lights in an array and group the lights by their types in the array (directional, point and spot light)
so my lighting function has three loops (simplified sudo code):
void computeLights()
{
for(int i=beginOfDirectionalLights;i<numOfDirectionalLights;++i)
{
ComputeDirectionalLight(…);
}
for(int i=beginOfSpotLights;i<numOfSpotLights;++i)
{
ComputeSpotLight();
}
for(int i=beginOfPointLight;i<numOfPointLights;++i)
{
ComputePointLight();
}
}
this shader code works perfectly on the ipad simulator, but on the ipad device, i couldn’t see anything.
i tested each of the three light functions and also my input values. they are all correct.
however, if i remove two of the three loops, the shader starts to work on the ipad.
it seems that the opengl es 2 shader on ipad doesn’t support three loops inside one function.
I’m aware that the shader cannot be too large (complex), otherwise the registers will be used up.
but if that is the case, I should get come compiling error, but i got nothing.
so right now i’ve changed my code into this one, which works but pretty slow:
const int numLights = 8;
void computeLights()
{
//get a light from the light array
for(int i=0;i<numLights;++i)
{
if(currentLightType==DirectionalLight)
{
ComputeDirectionalLight();
}
else if(currentLightType==SpotLight)
{
ComputeSpotLight();
}
else if(currentLightType==PointLight)
{
ComputePointLight();
}
else if(currentLightType==EmptyLight)
{
//do nothing here
}
}
}
the problem with this code is that, it runs very slow even all lights are the EmptyLight type.
because GLES2 does not allow to use a uniform dynamic value to specify the loop times, i fixed the light number as 8 and loop over the entire light array no matter how many lights are defined. the way to determine if it is an empty light as well as the light type is through the value “lightType”.
I hard coded every light to be empty. but the performance is still low.
does this has something to do with loop unrolling? is there any solution to this?
thank you very much in advance.