shader input question, help?

Just a sanity check here, am I missing something? Or shouldn’t this work just fine??

self.finalCard = self.blurBuffer.getTextureCard()
self.finalCard.setShader ( self.yBlurShader )
self.finalCard.setShaderInput( "various", Vec4(1.0, 0.8, 0.45, 0.0) )
self.finalCard.setShaderInput( "renderTexture", self.renderBufferTexture )

Then in the shader…

void fshader(float2 l_texcoord0 : TEXCOORD0,
             in uniform sampler2D tex_0 : TEXUNIT0,
             in uniform float4 k_various, 
             in uniform sampler2D k_renderTexture : TEXUNIT1,

             out float4 o_color : COLOR)
{ ... }

Trouble is that k_various is (0,0,0,0) at shader execution. Now I’ve written a bunch of shaders in panda, and this seems unique behaviour, so I’m hoping that I’ve missed something stupid this time around.

That looks like it should work. I wonder if we have another Cg register allocation bug. Try compiling the shader using

cgc -entry fshader -profile arbfp1 myshader.sha

And post the output.

Here ya go Josh…thanks for the help


yBlur.sha
68 lines, 0 errors.
!!ARBfp1.0
# cgc version 1.5.0008, build date May 23 2006 10:10:46
# command line args: -profile arbfp1
# source file: yBlur.sha
#vendor NVIDIA Corporation
#version 1.5.0.8
#profile arbfp1
#program fshader
#semantic fshader.tex_0 : TEXUNIT0
#semantic fshader.k_various
#semantic fshader.k_renderTexture : TEXUNIT1
#var float2 l_texcoord0 : $vin.TEXCOORD0 : TEX0 : 0 : 1
#var sampler2D tex_0 : TEXUNIT0 : texunit 0 : 1 : 1
#var float4 k_various :  : c[0] : 2 : 1
#var sampler2D k_renderTexture : TEXUNIT1 : texunit 1 : 3 : 1
#var float4 o_color : $vout.COLOR : COL : 4 : 1
#const c[1] = 0 0.00390625 0.1 0.001953125
#const c[2] = 0.2 0.4 0 -0.00390625
#const c[3] = 0 -0.001953125 0.11 0.3
#const c[4] = 0.59 1
PARAM c[5] = { program.local[0],
		{ 0, 0.00390625, 0.1, 0.001953125 },
		{ 0.2, 0.40000001, 0, -0.00390625 },
		{ 0, -0.001953125, 0.11, 0.30000001 },
		{ 0.58999997, 1 } };
TEMP R0;
TEMP R1;
TEMP R2;
ADD R0.xy, fragment.texcoord[0], -c[3];
TEX R1, R0, texture[0], 2D;
ADD R0.xy, fragment.texcoord[0], -c[2].zwzw;
TEX R0, R0, texture[0], 2D;
MUL R1, R1, c[2].x;
MAD R1, R0, c[1].z, R1;
TEX R0, fragment.texcoord[0], texture[0], 2D;
MAD R0, R0, c[2].y, R1;
ADD R2.xy, fragment.texcoord[0], -c[1].xwzw;
TEX R1, R2, texture[0], 2D;
MAD R2, R1, c[2].x, R0;
ADD R0.xy, fragment.texcoord[0], -c[1];
TEX R0, R0, texture[0], 2D;
TEX R1, fragment.texcoord[0], texture[1], 2D;
MAD R0, R0, c[1].z, R2;
ADD R0, R0, R1;
MUL R0, R0, c[0].x;
MUL R1.x, R0.y, c[4];
MAD R1.x, R0, c[3].w, R1;
MAD R1.x, R0.z, c[3].z, R1;
ADD R1.x, R1, c[0].z;
ADD R1.y, R1.x, -c[0];
CMP R1.z, R1.y, R1.x, R1.y;
ADD R1.y, R1.z, c[4];
RCP R1.y, R1.y;
MUL R1.w, R1.z, R1.y;
MOV R1.y, c[4];
SGE R1.x, R1, c[0].y;
ADD R2.x, R1.y, -c[0].y;
ABS R1.x, R1;
MAD R1.w, R1, R2.x, c[0].y;
CMP R1.x, -R1, c[1], R1.y;
CMP R1.x, -R1, R1.z, R1.w;
MUL result.color, R0, R1.x;
END
# 34 instructions, 3 R-regs

May I see the input as well? That’s a tad hard to read. :slight_smile:

Josh you are SO picky!!! :laughing:


void fshader(float2 l_texcoord0 : TEXCOORD0,
             in uniform sampler2D tex_0 : TEXUNIT0,

             uniform float4 k_various, // k_various.x is exposure, k_various.y is the high range compression threshold
             in uniform sampler2D k_renderTexture : TEXUNIT1,

             out float4 o_color : COLOR)
{
  float2 ST = (half2) l_texcoord0;
  float GlowStep = 1.0 / 512.0;
  float4 lowRange = tex2D(k_renderTexture, ST);
  float4 sample = tex2D(tex_0, ST - float2(0.0, -2 * GlowStep)); 
  float4 color =  sample * 0.1;
  
  sample = tex2D(tex_0, ST - float2(0.0, -GlowStep));
  color += sample * 0.2;
  
  sample = tex2D(tex_0, ST);
  color += sample * 0.4;

  sample = tex2D(tex_0, ST - float2(0.0, GlowStep));
  color += sample * 0.2;

  sample = tex2D(tex_0, ST - float2(0.0, 2 * GlowStep));
  color += sample * 0.1;

  o_color = k_various.x * color + lowRange;
  
  // Tone map the output color to the 0-1 range.
  float currentLuminance = getLuminance( o_color ) + k_various.z;
  float finalLuminance;
  if (currentLuminance >= k_various.y) {
  	// compress bright areas into the remaining top y%, should result in happy stuff.
  	currentLuminance -= k_various.y;  // shift high range to low range 0-1.y or so.
    finalLuminance = currentLuminance / (1.0 + currentLuminance);  // normalize this range.
    finalLuminance *= 1.0 - k_various.y;  // take 0-1 range and shrink to 0-0.y range.
    finalLuminance += k_various.y;  // shift back into the top y%...
  }
  else
    finalLuminance = currentLuminance;
  o_color *= finalLuminance;  // affect color by this tone mapped luminance.
}

I’m sorry I haven’t gotten back to this… I’m just too tired for hard-core debugging. I’ll look at it soon.

Hey Josh, any idea when you can look at this? If not soon, no biggie really, but I have to make some stuff happen here for an upcoming deadline…

thanks,

Tell ya what… why not come on over and we can debug it together? It looks too hard to debug by email.