Hey guys,
I've been looking at EVOLVED's post-bloom shader (original .FX file is attached, you can download the demo from
his site [DEMO]), and I can't wrap my head around this. All I'm trying to do is create a global tweakable variable that I can change from DBPro and use on a certain aspect of the shader. The variable is fine everywhere EXCEPT when I try to use it in the POW(number, power) command. When I plug it into the "power" part, it doesn't work. Here is what I'm trying to do, in more detail:
So I was looking at the shader, trying to make the bloom effect brighter and more widespread. I realized that changing this:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
return float4(pow(color,10),1);
}
To this:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
return float4(pow(color,2),1);
}
Made the bloom shader significantly brighter. By decreasing that power in the
pow command from 10 to 2, the color was less dark, and everything just looked brighter. So I figured I would try to make a variable to control it with. I called it ColorPower and put it at the top, changing this:
//--------------
// tweaks
//--------------
float ViewScaleX;
float ViewScaleY;
float BlurOffset = 0.005f;
float GlowIntensity = 0.15f;
float MotionBlur = 0.25f;
to this:
//--------------
// tweaks
//--------------
float ViewScaleX;
float ViewScaleY;
float BlurOffset = 0.005f;
float GlowIntensity = 0.15f;
float MotionBlur = 0.25f;
float ColorPower = 2.0f;
And then I tried doing this:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
return float4(pow(color,ColorPower),1);
}
The problem is, the screen turns out black, which means the shader isn't working. I thought maybe the ColorPower variable wasn't working, so I tried doing this which would make the screen have a red overtone to it:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
color.x=ColorPower;
return float4(pow(color,2),1);
}
It worked, so I knew that the ColorPower variable was indeed global. So then I thought maybe the POW command didn't like variables, so I tried this:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
float power=2.0;
return float4(pow(color,power),1);
}
Which also worked. So, I tried this:
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
float power=ColorPower;
return float4(pow(color,power),1);
}
Which did not work. Any idea why this is happening? I just want to be able to allow this global tweakable variable "ColorPower" to change the value used in the "pow" command, but it's not working! It doesn't work for any other global variables either, even those that are already there.
Anyway, if anyone has any idea why this is happening (I hope it's just some stupid mistake I don't know about), I would appreciate it.
Here is the full code:
//====================================================
// Post Bloom (ps 1.4)
// By EVOLVED
//====================================================
//--------------
// tweaks
//--------------
float ViewScaleX;
float ViewScaleY;
float BlurOffset = 0.005f;
float GlowIntensity = 0.15f;
float MotionBlur = 0.25f;
float ColorPower=2.0f;
//--------------
// Textures
//--------------
texture RenderColorTX
<
string Name = " ";
>;
sampler2D RenderColor=sampler_state
{
Texture=<RenderColorTX>;
ADDRESSU=CLAMP;
ADDRESSV=CLAMP;
ADDRESSW=CLAMP;
MagFilter = None;
MinFilter = None;
MipFilter = None;
};
texture DownColorTX
<
string Name = " ";
>;
sampler2D DownColor=sampler_state
{
Texture=<DownColorTX>;
ADDRESSU=CLAMP;
ADDRESSV=CLAMP;
ADDRESSW=CLAMP;
};
texture GlowHColorTX
<
string Name = " ";
>;
sampler2D GlowHColor=sampler_state
{
Texture=<GlowHColorTX>;
ADDRESSU=CLAMP;
ADDRESSV=CLAMP;
ADDRESSW=CLAMP;
};
texture GlowVColorTX
<
string Name = " ";
>;
sampler2D GlowVColor=sampler_state
{
Texture=<GlowVColorTX>;
ADDRESSU=CLAMP;
ADDRESSV=CLAMP;
ADDRESSW=CLAMP;
};
//--------------
// structs
//--------------
struct InPut
{
float4 pos:POSITION;
float2 UV:TEXCOORD;
};
struct OutPut
{
float4 opos:POSITION;
float2 Tex1:TEXCOORD0;
float2 Tex2:TEXCOORD1;
float2 Tex3:TEXCOORD2;
float2 Tex4:TEXCOORD3;
};
//--------------
// vertex shader
//--------------
OutPut VS(InPut IN)
{
OutPut OUT;
OUT.opos=IN.pos;
OUT.Tex1=IN.UV;
OUT.Tex2=IN.UV+0.5*float2(ViewScaleX,ViewScaleY);
OUT.Tex3=0;
OUT.Tex4=0;
return OUT;
}
OutPut VSH1(InPut IN)
{
OutPut OUT;
OUT.opos=IN.pos;
OUT.Tex1=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(BlurOffset,0)*0.1f);
OUT.Tex2=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(BlurOffset,0)*1.1f);
OUT.Tex3=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(BlurOffset,0)*2.1f);
OUT.Tex4=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(BlurOffset,0)*3.1f);
return OUT;
}
OutPut VSH2(InPut IN)
{
OutPut OUT;
OUT.opos=IN.pos;
OUT.Tex1=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(BlurOffset,0)*0.1f);
OUT.Tex2=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(BlurOffset,0)*1.1f);
OUT.Tex3=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(BlurOffset,0)*2.1f);
OUT.Tex4=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(BlurOffset,0)*3.1f);
return OUT;
}
OutPut VSV1(InPut IN)
{
OutPut OUT;
OUT.opos=IN.pos;
OUT.Tex1=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(0,BlurOffset)*0.1f);
OUT.Tex2=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(0,BlurOffset)*1.1f);
OUT.Tex3=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(0,BlurOffset)*2.1f);
OUT.Tex4=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))+(float2(0,BlurOffset)*3.1f);
return OUT;
}
OutPut VSV2(InPut IN)
{
OutPut OUT;
OUT.opos=IN.pos;
OUT.Tex1=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(0,BlurOffset)*0.1f);
OUT.Tex2=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(0,BlurOffset)*1.1f);
OUT.Tex3=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(0,BlurOffset)*2.1f);
OUT.Tex4=(IN.UV+0.5*float2(ViewScaleX,ViewScaleY))-(float2(0,BlurOffset)*3.1f);
return OUT;
}
//--------------
// pixel shader
//--------------
float4 DownSamplePS(OutPut IN) : COLOR
{
float3 color=tex2D(RenderColor,IN.Tex2);
return float4(pow(color,ColorPower),1);
}
float4 BlurPS(OutPut IN, uniform sampler2D texmap) : COLOR
{
float3 color=tex2D(texmap,IN.Tex1);
color +=tex2D(texmap,IN.Tex2);
color +=tex2D(texmap,IN.Tex3);
color +=tex2D(texmap,IN.Tex4);
return float4(color*GlowIntensity,1);
}
float4 FinalCompPS(OutPut IN) : COLOR
{
float3 Scene = tex2D(RenderColor,IN.Tex1);
float3 Blur = tex2D(GlowVColor,IN.Tex2);
return float4(Scene+Blur,MotionBlur);
}
//--------------
// techniques
//--------------
technique DownSample
{
pass p1
{
vertexShader = compile vs_1_1 VS();
pixelShader = compile ps_1_4 DownSamplePS();
}
}
technique GlowHPassA
{
pass p1
{
vertexShader = compile vs_1_1 VSH1();
pixelShader = compile ps_1_4 BlurPS(DownColor);
}
pass p2
{
vertexShader = compile vs_1_1 VSH2();
pixelShader = compile ps_1_4 BlurPS(DownColor);
AlphaBlendEnable = True;
SrcBlend = One;
DestBlend = One;
}
}
technique GlowVPassA
{
pass p1
{
vertexShader = compile vs_1_1 VSV1();
pixelShader = compile ps_1_4 BlurPS(GlowHColor);
}
pass p2
{
vertexShader = compile vs_1_1 VSV2();
pixelShader = compile ps_1_4 BlurPS(GlowHColor);
AlphaBlendEnable = True;
SrcBlend = One;
DestBlend = One;
}
}
technique GlowHPassB
{
pass p1
{
vertexShader = compile vs_1_1 VSH1();
pixelShader = compile ps_1_4 BlurPS(GlowVColor);
}
pass p2
{
vertexShader = compile vs_1_1 VSH2();
pixelShader = compile ps_1_4 BlurPS(GlowVColor);
AlphaBlendEnable = True;
SrcBlend = One;
DestBlend = One;
}
}
technique GlowVPassB
{
pass p1
{
vertexShader = compile vs_1_1 VSV1();
pixelShader = compile ps_1_4 BlurPS(GlowHColor);
}
pass p2
{
vertexShader = compile vs_1_1 VSV2();
pixelShader = compile ps_1_4 BlurPS(GlowHColor);
AlphaBlendEnable = True;
SrcBlend = One;
DestBlend = One;
}
}
technique FinalComp
{
pass p1
{
vertexShader = compile vs_1_1 VS();
pixelShader = compile ps_1_4 FinalCompPS();
}
}
Thanks,
-Sixty Squares