Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem with render to texture

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Location
    Villa Clara. Cuba
    Posts
    3

    Problem with render to texture

    Hi all. I'm trying to implement a simple glow effect as proposed in a NVidia paper called: "Simple Glow" but there are two problems. In the image Render.jpg I show the problem enclosed with a solid red border. I don't knwo why I get the bottom of the teapot on top of the scene. The effect shown in the image is accomplished as follows:
    1. Render the teapot to the screen. (No shaders in this stage).
    2. Render the teapot to a texture. (No shaders in this stage).
    3. Render a full-screen quad to perform the horizontal gaussian blur pass of the texture generated in (2).
    4. Render a full-screen quad to perform the vertical gaussian blur pass pf the texture generated in (3).
    5.This is the final compositing pass. Again, a full screen quad is rendered and in the pixel shader, I read a pixel in the blurred version of the scene generated by (4). Then, this pixel is blended with the pixel on the screen generated by (1).

    The vertex shader used in (3), (4) and (5) is:
    Code :
    struct g_v_out{
    	float4 Position: POSITION;
    	float2 Coordinates: TEXCOORD0;
    	};
    g_v_out mainVS(float3 in_pos : POSITION){
     
    	g_v_out Result;
    	Result.Position = float4(in_pos,1);
    	Result.Coordinates = in_pos.xy * 0.5f + 0.5f;
    	return Result;
    }
    The variable in_pos receives the values:
    (-1,-1,0)
    (1,-1,0)
    (1,1,0)
    (-1,1,0);
    and the texture coordinates are generated using these values with a simple scale and add operations.
    The pixel shaders used are:
    Horizontal gaussian blur:
    Code :
    float4 GaussHPass(float2 Coordinates: TEXCOORD0) : COLOR {
     
    	float4 Result = float4(0.0f,0.0f,0.0f,0.0f);
     
    	for(int i = 0; i < NUM_TAPS; i++)
    	{
    		Result += tex2D(SceneMap, float2(Coordinates.x + Dir[i] ,Coordinates.y)) * Weights[i]; 
    	}
     
    	return float4(Result.xyz,1.0f);
     
    }
    SceneMap is the texture generated by (2).
    Vertical gaussian blur pass:
    Code :
    uniform sampler2D HorizontalMap;
    float4 GaussVPass(float2 Coordinates: TEXCOORD0) : COLOR {
    	float4 Result = float4(0.0f,0.0f,0.0f,0.0f);
     
    	for(int i = 0; i < NUM_TAPS; i++)
    	{
    		Result += tex2D(HorizontalMap, float2(Coordinates.x ,Coordinates.y + Dir[i])) * Weights[i]; 
    	}
     
    	return Result;
    }
    HorizontalMap is the texture generated by te previous pass.
    The variables Dir and Weight are defined as follows:
    Code :
    #define SAMPLER_SIZE 512
    #define NUM_TAPS 9
     
    float Weights[NUM_TAPS] = {0.06f,0.09f,0.12f,0.15f,0.16f,0.15f,0.12f,0.09f,0.06f};
    float Dir[NUM_TAPS] = {-4.0f/SAMPLER_SIZE,-3.0f/SAMPLER_SIZE,-2.0f/SAMPLER_SIZE,-1.0f/SAMPLER_SIZE,
       					   0.0f,
    					   1.0f/SAMPLER_SIZE,2.0f/SAMPLER_SIZE,3.0f/SAMPLER_SIZE,4.0f/SAMPLER_SIZE};
    FinalCompositing:
    Code :
    float4 FinalCompositing(float2 Coordinates: TEXCOORD0):COLOR
    {
    	float4 Result;	
    		Result = tex2D(VerticalMap, Coordinates) * GlowFactor;	
    	return Result;
    }
    The pixel outputted by FinalCompositing is blended with the one already on the screen generated in (1).


    The second problem is that I noticed a bit of flicker on the borders of the teapot. I tried glGenerateMipmapExt(GL_TEXTURE_2D) but the flicker is almost the same.

    Any ideas will be appreciated. Thanks in advance. (Sorry my English)





  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    943

    Re: Problem with render to texture

    Please first edit your post and put the code inside '['code']' / '['/code']'. Decyphering CG this way is extremely tedious.

    BTW, leave the "'" out! These are tags used for formatting.


  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Location
    Villa Clara. Cuba
    Posts
    3

    Re: Problem with render to texture

    I think I solved the problem enclosed with the solid red line. When generating the render targets I added the following:
    Code :
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

    Now, it looks like Render2.jpg and the only problem remaining will be the flickering. By the way...When generating the render targets, I'm using:
    Code :
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,arg_Width,arg_Height,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);	
    glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);
    instead of gluBuild2DMipmaps because when I invoked the latter with NULL data, a runtime error was generated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •