Jump to content

  • Log In with Google      Sign In   
  • Create Account


iPhone OpenGL ES 2 shadow map black


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 polyfrag   Crossbones+   -  Reputation: 1734

Like
0Likes
Like

Posted 02 June 2013 - 08:55 PM

It works on Windows but it's giving a black texture on iPhone.

 

On the top right is the shadow map:

 

photoshmp_zps3c30ebaa.jpg

 

On Windows I use GL_RGBA16 for the texture but on iPhone that's not available so I've tried GL_R16F_EXT and GL_RGBA8_OES, which should also work.

 

void InitShadows()
{
	glGenTextures(1, &g_depth);
	glBindTexture(GL_TEXTURE_2D, g_depth);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, g_depthSizeX, g_depthSizeY, 0, GL_RGBA, GL_UNSIGNED_SHORT, 0);
    //glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F_EXT, g_depthSizeX, g_depthSizeY, 0, GL_RGBA, GL_UNSIGNED_SHORT, 0);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, g_depthSizeX, g_depthSizeY, 0, GL_RGBA, GL_UNSIGNED_SHORT, 0);
	glBindTexture(GL_TEXTURE_2D, 0);
    
	glGenRenderbuffers(1, &g_rbDepth);
	glBindRenderbuffer(GL_RENDERBUFFER, g_rbDepth);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, g_depthSizeX, g_depthSizeY);
	glBindRenderbuffer(GL_RENDERBUFFER, 0);
    
	glGenFramebuffers(1, &g_fbDepth);
	glBindFramebuffer(GL_FRAMEBUFFER, g_fbDepth);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_depth, 0);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_rbDepth);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    
	//... load shaders
}

void RenderToShadowMap(Matrix projection, Matrix viewmat, Matrix modelmat)
{
    GLint oldFBO;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO);
	GLint viewport[4];
	glGetIntegerv( GL_VIEWPORT, viewport );
    
	//... get light view
	g_lightPos = g_lightEye + Vec3f(-viewD, viewD, viewD);
    
	glBindFramebuffer(GL_FRAMEBUFFER, g_fbDepth);
	glViewport(0, 0, g_depthSizeX, g_depthSizeY);
    
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(2.0, 500.0);
    
	g_lightProjectionMatrix = setorthographicmat(-PROJ_RIGHT, PROJ_RIGHT, PROJ_RIGHT, -PROJ_RIGHT, 30.0, 10000.0);
	g_lightModelViewMatrix = gluLookAt2(g_lightPos.x, g_lightPos.y, g_lightPos.z,
                                        g_lightEye.x, g_lightEye.y, g_lightEye.z,
                                        g_lightUp.x, g_lightUp.y, g_lightUp.z);
    
	Use(DEPTH);
	glUniformMatrix4fv(g_shader[DEPTH].m_slot[PROJECTION], 1, 0, g_lightProjectionMatrix.getMatrix());
	glUniformMatrix4fv(g_shader[DEPTH].m_slot[MODELMAT], 1, 0, modelmat.getMatrix());
	glUniformMatrix4fv(g_shader[DEPTH].m_slot[VIEWMAT], 1, 0, g_lightModelViewMatrix.getMatrix());
	glUniform4f(g_shader[MODEL].m_slot[COLOR], 1, 1, 1, 1);
	glEnableVertexAttribArray(g_shader[DEPTH].m_slot[POSITION]);
	glEnableVertexAttribArray(g_shader[DEPTH].m_slot[TEXCOORD0]);
    
	g_map.draw();
	DrawBuildings();
	DrawPowerlines();
	DrawRoads();
	DrawPipelines();
	DrawSelB();
	DrawUnits();
	DrawScenery();
    
	TurnOffShader();
    
	glDisable(GL_POLYGON_OFFSET_FILL);
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, oldFBO);
    
    //glViewport(0, 0, g_width, g_height);
	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
}

Any help appreciated.


Edited by polyfrag, 02 June 2013 - 08:56 PM.


Sponsor:

#2 marcClintDion   Members   -  Reputation: 431

Like
1Likes
Like

Posted 10 June 2013 - 05:44 AM

try this      

 

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, g_depthSizeXg_depthSizeY, 0, GL_DEPTH_COMPONENT,  GL_UNSIGNED_INT,  NULL);

 

Windows GPU drivers allow everything across every spec and more with vendor specific extensions.  The OpenGL ES 2.0 spec is a lot more strict.

 

You might want to grab a copy of the PowerVR SDK it should help you to keep things consistent across multiple platforms.

 

http://www.imgtec.com/powervr/insider/sdkdownloads/index.asp


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS