Jump to content
  • Advertisement
Sign in to follow this  
polyfrag

iPhone OpenGL ES 2 shadow map black

This topic is 1929 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

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

Share this post


Link to post
Share on other sites
Advertisement

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

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!