Sign in to follow this  

Glow Effect

This topic is 2063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i downloaded one Program, FX Composer, to try to create shaders, and create there glow shader. Then i copied fx. file to my program and view was clear...i tried to debug it with PIX and saw that something strange happened with textures...this is the shader:

[CODE]#define WT_0 1.0
#define WT_1 0.8
#define WT_2 0.6
#define WT_3 0.4
#define WT_4 0.2
// these ones are based on the above....
#define WT_NORMALIZE (WT_0+2.0*(WT_1+WT_2+WT_3+WT_4))
#define KW_0 (WT_0/WT_NORMALIZE)
#define KW_1 (WT_1/WT_NORMALIZE)
#define KW_2 (WT_2/WT_NORMALIZE)
#define KW_3 (WT_3/WT_NORMALIZE)
#define KW_4 (WT_4/WT_NORMALIZE)

float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "scene";
string ScriptOrder = "postprocess";
string ScriptOutput = "color";
string Script = "Technique=Glow?Main:Main10;";
> = 0.8;

// Standard full-screen imaging value
float4 ClearColor <
string UIWidget = "color";
string UIName = "Clear (Bg) Color";
> = {0,0,0,1.0};

float ClearDepth <
string UIWidget = "None";
> = 1.0;

float2 ViewportSize : VIEWPORTPIXELSIZE <
string UIName="Screen Size";
string UIWidget="None";
>;

static float2 ViewportOffset = (float2(0.5,0.5)/ViewportSize);

///////////////////////////////////////////////////////////
/////////////////////////////////////// Tweakables ////////
///////////////////////////////////////////////////////////

float Glowness <
string UIName = "Glow Strength";
string UIWidget = "slider";
float UIMin = 0.0f;
float UIMax = 2.0f;
float UIStep = 0.05f;
> = 0.7f;

float Sceneness <
string UIName = "Scene Strength";
string UIWidget = "slider";
float UIMin = 0.0f;
float UIMax = 2.0f;
float UIStep = 0.05f;
> = 0.3f;

float GlowSpan <
string UIName = "Glow Step Size (Texels)";
string UIWidget = "slider";
float UIMin = 0.2f;
float UIMax = 8.0f;
float UIStep = 0.5f;
> = 2.5f;

///////////////////////////////////////////////////////////
///////////////////////////// Render-to-Texture Targets ///
///////////////////////////////////////////////////////////

texture2D ScnMap : RENDERCOLORTARGET <
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "X8R8G8B8" ;
string UIWidget = "None";
>;

sampler2D ScnSamp = sampler_state {
texture = <ScnMap>;
AddressU = CLAMP;
AddressV = CLAMP;
FILTER = MIN_MAG_LINEAR_MIP_POINT;
};

texture2D GlowMap1 : RENDERCOLORTARGET <
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "X8R8G8B8" ;
string UIWidget = "None";
>;

sampler2D GlowSamp1 = sampler_state {
texture = <GlowMap1>;
AddressU = CLAMP;
AddressV = CLAMP;
FILTER = MIN_MAG_LINEAR_MIP_POINT;
};

texture2D GlowMap2 : RENDERCOLORTARGET <
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "X8R8G8B8" ;
string UIWidget = "None";
>;

sampler2D GlowSamp2 = sampler_state {
texture = <GlowMap2>;
AddressU = CLAMP;
AddressV = CLAMP;
FILTER = MIN_MAG_LINEAR_MIP_POINT;
};

texture2D DepthBuffer : RENDERDEPTHSTENCILTARGET <
float2 ViewPortRatio = {1.0,1.0};
string Format = "D24S8";
string UIWidget = "None";
>;

///////////////////////////////////////////////////////////
///////////////////////////// Connector Data Struct ///////
///////////////////////////////////////////////////////////

struct OneTexelVertex {
float4 Position : POSITION;
float2 UV : TEXCOORD0;
};

// nine texcoords, to sample nine in-line texels
struct NineTexelVertex
{
float4 Position : POSITION;
float2 UV : TEXCOORD0;
float4 UV1 : TEXCOORD1; // xy AND zw used as UV coords
float4 UV2 : TEXCOORD2; // xy AND zw used as UV coords
float4 UV3 : TEXCOORD3; // xy AND zw used as UV coords
float4 UV4 : TEXCOORD4; // xy AND zw used as UV coords
};

///////////////////////////////////////////////////////////
/////////////////////////////////// Vertex Shaders ////////
///////////////////////////////////////////////////////////

// vertex shader to align blur samples vertically
NineTexelVertex vert9BlurVS(
float3 Position : POSITION,
float2 UV : TEXCOORD0
) {
NineTexelVertex OUT = (NineTexelVertex)0;
OUT.Position = float4(Position, 1);
float TexelIncrement = GlowSpan/ViewportSize.y;
float2 Coord = float2(UV.xy + ViewportOffset);
OUT.UV = Coord;
OUT.UV1 = float4(Coord.x, Coord.y + TexelIncrement,
Coord.x, Coord.y - TexelIncrement);
OUT.UV2 = float4(Coord.x, Coord.y + TexelIncrement*2,
Coord.x, Coord.y - TexelIncrement*2);
OUT.UV3 = float4(Coord.x, Coord.y + TexelIncrement*3,
Coord.x, Coord.y - TexelIncrement*3);
OUT.UV4 = float4(Coord.x, Coord.y + TexelIncrement*4,
Coord.x, Coord.y - TexelIncrement*4);
return OUT;
}

// vertex shader to align blur samples horizontally
NineTexelVertex horiz9BlurVS(
float3 Position : POSITION,
float2 UV : TEXCOORD0
) {
NineTexelVertex OUT = (NineTexelVertex)0;
OUT.Position = float4(Position, 1);
float TexelIncrement = GlowSpan/ViewportSize.x;
float2 Coord = float2(UV.xy + ViewportOffset);
OUT.UV = Coord;
OUT.UV1 = float4(Coord.x + TexelIncrement, Coord.y,
Coord.x - TexelIncrement, Coord.y);
OUT.UV2 = float4(Coord.x + TexelIncrement*2, Coord.y,
Coord.x - TexelIncrement*2, Coord.y);
OUT.UV3 = float4(Coord.x + TexelIncrement*3, Coord.y,
Coord.x - TexelIncrement*3, Coord.y);
OUT.UV4 = float4(Coord.x + TexelIncrement*4, Coord.y,
Coord.x - TexelIncrement*4, Coord.y);
return OUT;
}

OneTexelVertex ScreenQuadVS(
float3 Position : POSITION,
float2 UV : TEXCOORD0
) {
OneTexelVertex OUT = (OneTexelVertex)0;
OUT.Position = float4(Position, 1);
OUT.UV = float2(UV.xy + ViewportOffset);
return OUT;
}

///////////////////////////////////////////////////////////
/////////////////////////////////// Pixel Shaders /////////
///////////////////////////////////////////////////////////

float4 blur9PS(NineTexelVertex IN,
uniform sampler2D SrcSamp) : COLOR
{
float4 OutCol = tex2D(SrcSamp, IN.UV4.zw) * KW_4;
OutCol += tex2D(SrcSamp, IN.UV3.zw) * KW_3;
OutCol += tex2D(SrcSamp, IN.UV2.zw) * KW_2;
OutCol += tex2D(SrcSamp, IN.UV1.zw) * KW_1;
OutCol += tex2D(SrcSamp, IN.UV) * KW_0;
OutCol += tex2D(SrcSamp, IN.UV1.xy) * KW_1;
OutCol += tex2D(SrcSamp, IN.UV2.xy) * KW_2;
OutCol += tex2D(SrcSamp, IN.UV3.xy) * KW_3;
OutCol += tex2D(SrcSamp, IN.UV4.xy) * KW_4;
return OutCol;
}

// add glow on top of model

float4 PS_GlowPass(OneTexelVertex IN) : COLOR
{
float4 scn = Sceneness * tex2D(ScnSamp, IN.UV);
float3 glow = Glowness * tex2D(GlowSamp2, IN.UV).xyz;
return float4(scn.xyz+glow,scn.w);
}

////////////////////////////////////////////////////////////
/////////////////////////////////////// techniques /////////
////////////////////////////////////////////////////////////
RasterizerState DisableCulling
{
CullMode = NONE;
};

DepthStencilState DepthEnabling
{
DepthEnable = FALSE;
DepthWriteMask = ZERO;
};

BlendState DisableBlend
{
BlendEnable[0] = FALSE;
};

technique10 Main10 <
string Script =
"RenderColorTarget0=ScnMap;"
"RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=color;"
"Pass=BlurGlowBuffer_Horz;"
"Pass=BlurGlowBuffer_Vert;"
"Pass=GlowPass;";
> {
pass BlurGlowBuffer_Horz <
string Script = "RenderColorTarget=GlowMap1;"
"RenderDepthStencilTarget=DepthBuffer;"
"Draw=Buffer;";
>
{
SetVertexShader( CompileShader( vs_4_0, horiz9BlurVS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, blur9PS(ScnSamp) ) );

SetRasterizerState(DisableCulling);
SetDepthStencilState(DepthEnabling, 0);
SetBlendState(DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF);
}

pass BlurGlowBuffer_Vert <
string Script = "RenderColorTarget=GlowMap2;"
"RenderDepthStencilTarget=DepthBuffer;"
"Draw=Buffer;";
>
{
SetVertexShader( CompileShader( vs_4_0, vert9BlurVS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, blur9PS(GlowSamp1) ) );

SetRasterizerState(DisableCulling);
SetDepthStencilState(DepthEnabling, 0);
SetBlendState(DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF);
}

pass GlowPass <
string Script= "RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"Draw=Buffer;";
>
{
SetVertexShader( CompileShader( vs_4_0, ScreenQuadVS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS_GlowPass() ) );

SetRasterizerState(DisableCulling);
SetDepthStencilState(DepthEnabling, 0);
SetBlendState(DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF);
}

}


technique Main <
string Script =
"RenderColorTarget0=ScnMap;"
"RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=color;"
"Pass=BlurGlowBuffer_Horz;"
"Pass=BlurGlowBuffer_Vert;"
"Pass=GlowPass;";
> {
pass BlurGlowBuffer_Horz <
string Script = "RenderColorTarget=GlowMap1;"
"RenderDepthStencilTarget=DepthBuffer;"
"Draw=Buffer;";
> {
VertexShader = compile vs_3_0 horiz9BlurVS();
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
PixelShader = compile ps_3_0 blur9PS(ScnSamp);
}
pass BlurGlowBuffer_Vert <
string Script = "RenderColorTarget=GlowMap2;"
"RenderDepthStencilTarget=DepthBuffer;"
"Draw=Buffer;";
> {
VertexShader = compile vs_3_0 vert9BlurVS();
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
PixelShader = compile ps_3_0 blur9PS(GlowSamp1);
}
pass GlowPass <
string Script= "RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"Draw=Buffer;";
>
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
VertexShader = compile vs_3_0 ScreenQuadVS();
PixelShader = compile ps_3_0 PS_GlowPass();
}
}[/CODE]


meybe i need to set some globals from code? [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] Cause i cannot find anything that i need to set from code here...and don't know how to see it in FX Composer...

Share this post


Link to post
Share on other sites
so what happens with the textures? does the program compile without errors? if there are any errors, what are they? What is it you are expecting to see, and what do you actually see?

Share this post


Link to post
Share on other sites
i saw nothing...no objects...hm all texture coordinates in PIX after shader are like this:
[CODE]1.#IO
[/CODE]P.S. And i have strange problem with program and in PIX...PIX sad that program run out of memory....[img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img]

Share this post


Link to post
Share on other sites
[quote name='Arkanoid' timestamp='1335016449' post='4933515']
meybe i need to set some globals from code?
[/quote]

You do. I'd suggest starting with something simpler to get to know the basics of how shaders work.

By the way [url="http://www.gamedev.net/topic/544358-pix-1io---what-does-it-means/"]1.#IO is a NaN[/url].

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1335047208' post='4933624']
You do. I'd suggest starting with something simpler to get to know the basics of how shaders work.
[/quote]

i have already started) But to write a big shader code, i need to know 100% its code...so i wanna try to create shaders in special program and then use it. Its in my opinion good way to get 100% working code...

So if i understood, i need to set that textures from code, cause in another case i have devision by zero....

P.S. I still cannot understand one thing - how to get texture size?

Share this post


Link to post
Share on other sites
You get the texture size by passing it in using a global from code. You can use GetSurfaceLevel() and then GetDesc() on the surface if you don't store your own copy of the texture size.

Share this post


Link to post
Share on other sites

This topic is 2063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this