View Full Version : Problem with render to texture

11-28-2011, 07:29 AM
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:

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:
and the texture coordinates are generated using these values with a simple scale and add operations.
The pixel shaders used are:
Horizontal gaussian blur:

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:

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:

#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};


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)

11-28-2011, 07:32 AM
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.

11-28-2011, 07:59 AM
I think I solved the problem enclosed with the solid red line. When generating the render targets I added the following:


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:

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,arg_Width,arg _Height,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);

instead of gluBuild2DMipmaps because when I invoked the latter with NULL data, a runtime error was generated.