Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualnewObjekt

Posted 16 April 2013 - 11:04 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);
	}

#2newObjekt

Posted 16 April 2013 - 11:03 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);
		
		// GL_LINEAR does not make sense for depth texture. However, next tutorial shows usage of GL_LINEAR and PCF
		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 );
		
		// No need to force GL_DEPTH_COMPONENT24, drivers usually give you the max precision if available
		ByteBuffer depth = null; //ByteBuffer.allocateDirect(shadowMapWidth*shadowMapHeight*4).order(ByteOrder.nativeOrder()); // allocacate texture buffer
		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);
		
		// Instruct openGL that we won't bind a color texture with the currently bound 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);
	}

#1newObjekt

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%201.png

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 3 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);
		
		// GL_LINEAR does not make sense for depth texture. However, next tutorial shows usage of GL_LINEAR and PCF
		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 );
		
		// No need to force GL_DEPTH_COMPONENT24, drivers usually give you the max precision if available
		ByteBuffer depth = null; //ByteBuffer.allocateDirect(shadowMapWidth*shadowMapHeight*4).order(ByteOrder.nativeOrder()); // allocacate texture buffer
		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);
		
		// Instruct openGL that we won't bind a color texture with the currently bound 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);
	}

 


PARTNERS