Jump to content

  • Log In with Google      Sign In   
  • Create Account


GL_COMPARE_TO_REF breaks my everything!


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 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 16 April 2013 - 11:01 PM

I'm having issues with getting GL_LINEAR filtering on my shadow mapping texture.

When I use:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);

I get results like this:

http://inferno.codebrainshideout.net/Images/pcf%20problem%202.png

http://inferno.codebrainshideout.net/Images/pcf%20problem%203.png


But when I use this code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_TO_REF);

I get no shadows at all:

http://inferno.codebrainshideout.net/Images/pcf%20problem%204.png

 

The difference between the first 2 pictures and the last one is just that one line of code. D:

 

This is kind of odd. Am I just doing something wrong?

 

Here is the fragment shader.

And here is the method that creates the FBO texture and the FBO.

	public static void generateShadowFBO() {
		int shadowMapWidth = (int)(Settings.displayWidth * shadowQuality);
		int shadowMapHeight = (int)(Settings.displayHeight * shadowQuality);
		
		int FBOstatus;
		
		// Try to use a texture depth component
		depthTextureId = glGenTextures();
		glBindTexture(GL_TEXTURE_2D, depthTextureId);
		
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
		glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); 	
		
		// Remove artifact on the edges of the shadowmap
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
		
		ByteBuffer depth = null;
		glTexImage2D(GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
		glBindTexture(GL_TEXTURE_2D, 0);
		
		// create a framebuffer object
		IntBuffer buffer = ByteBuffer.allocateDirect(1*4).order(ByteOrder.nativeOrder()).asIntBuffer(); // allocate a 1 int byte buffer
		org.lwjgl.opengl.EXTFramebufferObject.glGenFramebuffersEXT(buffer);
		fbo = buffer.get();
		org.lwjgl.opengl.EXTFramebufferObject.glBindFramebufferEXT(org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo);
		
		glDrawBuffer(GL_NONE);
		glReadBuffer(GL_NONE);
		glEnable(GL_CULL_FACE);
		 
		// attach the texture to FBO depth attachment point
		org.lwjgl.opengl.EXTFramebufferObject.glFramebufferTexture2DEXT(org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_EXT, org.lwjgl.opengl.EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureId, 0);
		// check FBO status
		FBOstatus = org.lwjgl.opengl.EXTFramebufferObject.glCheckFramebufferStatusEXT(org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_EXT);
		if(FBOstatus != org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT)
			System.out.println("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO\n");
		
		// switch back to window-system-provided framebuffer
		org.lwjgl.opengl.EXTFramebufferObject.glBindFramebufferEXT(org.lwjgl.opengl.EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
	}

Edited by newObjekt, 16 April 2013 - 11:04 PM.


Sponsor:

#2 mafian89   Members   -  Reputation: 154

Like
2Likes
Like

Posted 18 April 2013 - 04:12 PM

Well, when you want to use 

 

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_TO_REF);
 

Your texture sampler should be

 

 

uniform sampler2DShadow ShadowMap;
 

instead of

 

 

 

uniform sampler2D ShadowMap;
 

Edited by mafian89, 18 April 2013 - 04:12 PM.





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