• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Arkanoid

Glow Effect

5 posts in this topic

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...
0

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?
0

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]
0

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].
0

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?
0

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.
0

Share this post


Link to post
Share on other sites

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  
Followers 0