;
float4x4 WorldXf : World < string UIWidget="None"; >;
float4x4 WInvTrXf : WorldInverseTranspose < string UIWidget="None"; >;
float4x4 ViewInvXf : ViewInverse < string UIWidget="None"; >;
///////////////////////////////////////////////
// Tweakables Appear in the Properties Pane //
///////////////////////////////////////////////
float4 LightDir : Direction <
string UIName = "Light Direction";
string Object = "DirectionalLight";
string Space = "World";
> = {1.0f, -1.0f, 1.0f, 0.0f};
float4 LightColor : Diffuse <
string UIWidget = "color";
string UIName = "Diffuse Light";
string Object = "DirectionalLight";
> = {1.0f, 1.0f, 1.0f, 1.0f};
float4 LightAmbient : Ambient <
string UIWidget = "color";
string UIName = "Ambient Light";
string Space = "material";
> = {0.0f, 0.0f, 0.0f, 1.0f};
float4 MaterialDiffuse : Diffuse <
string UIWidget = "color";
string UIName = "Surface";
string Space = "material";
> = {1.0f, 1.0f, 1.0f, 1.0f};
float4 MaterialSpecular : Specular <
string UIWidget = "color";
string UIName = "Surface Specular";
string Space = "material";
> = {1.0f, 1.0f, 1.0f, 1.0f};
float Shininess : SpecularPower <
string UIWidget = "slider";
float UIMin = 1.0;
float UIMax = 128.0;
float UIStep = 1.0;
string UIName = "Specular Power";
> = 30.0;
////////////////////////////////////
// Texture ///////////////////////
////////////////////////////////////
texture diffuseTexture : Diffuse <
string ResourceName = "default_color.dds";
>;
sampler TextureSampler = sampler_state
{
texture = ;
AddressU = CLAMP;
AddressV = CLAMP;
// AddressW = CLAMP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
////////////////////////////////////
// Structures Used ////////////////
////////////////////////////////////
struct vertexInput {
float3 position : POSITION;
float3 normal : NORMAL;
float4 texCoordDiffuse : TEXCOORD0;
};
struct vertexOutput {
float4 hPosition : POSITION;
float4 texCoordDiffuse : TEXCOORD0;
float4 diffAmbColor : COLOR0;
float4 specCol : COLOR1;
};
////////////////////////////////////
// Vertex Shader ///////////////////
////////////////////////////////////
vertexOutput VS_TransformAndTexture(vertexInput IN)
{
vertexOutput OUT = (vertexOutput)0;
float4 Po = float4(IN.position.xyz,1.0); // object-coordinates position
OUT.hPosition = mul(Po,WvpXf);
OUT.texCoordDiffuse = IN.texCoordDiffuse;
//calculate our vectors N, E, L, and H
float3 Ew = ViewInvXf[3].xyz; // eye position in world coordinates
float3 Pw = mul(Po, WorldXf).xyz; // world coordinates position
float4 Nn = normalize(mul(IN.normal, WInvTrXf)); // normal vector
float3 En = normalize(Ew - Pw); // eye vector
float3 Ln = normalize( -LightDir.xyz); // light vector
float3 Hn = normalize(En + Ln); // half angle vector
// calculate the diffuse and specular contributions
float diff = max(0 , dot(Nn,Ln));
float spec = pow(max(0,dot(Nn,Hn)), Shininess);
if( diff <= 0 ) {
spec = 0;
}
//output diffuse
float4 ambColor = MaterialDiffuse * LightAmbient;
float4 diffColor = MaterialDiffuse * diff * LightColor ;
OUT.diffAmbColor = diffColor + ambColor;
//output specular
float4 specColor = MaterialSpecular * LightColor * spec;
OUT.specCol = specColor;
return OUT;
}
////////////////////////////////////
// Pixel Shader ////////////////////
////////////////////////////////////
float4 PS_Textured( vertexOutput IN): COLOR
{
float4 diffuseTexture = tex2D( TextureSampler, IN.texCoordDiffuse );
return IN.diffAmbColor * diffuseTexture + IN.specCol;
}
////////////////////////////////////
// Complete Technique //////////////
////////////////////////////////////
technique textured
{
pass p0
{
VertexShader = compile vs_1_1 VS_TransformAndTexture();
PixelShader = compile ps_1_1 PS_Textured();
}
}
//
// $Id: //sw/devrel/SDK/MEDIA/HLSL/new_material.fx#2 $
//
////////////////////////////////////
//////////////////////////// eof ///
////////////////////////////////////
]]>
// Turn this on to get the "dissolve" technique -- a bit slow just now
// #define DISSOLVE
float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "scene";
string ScriptOrder = "postprocess";
string ScriptOutput = "color";
string Script = "Technique=Teknik?title:withOpacity";
> = 0.8;
float4 ClearColor : DIFFUSE <
string UIName = "Background";
> = {0.3,0.3,0.3,1.0};
float ClearDepth
<
string UIWidget = "none";
> = 1.0;
///////////////////////////////////////////////////////////
///////////////////////////// Render-to-Texture Data //////
///////////////////////////////////////////////////////////
//DECLARE_QUAD_TEX(SceneTexture,SceneSampler,"A8R8G8B8")
//DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer, "D24S8")
/////////////////////////////////////////////////////
//// Textures for Input Images //////////////////////
/////////////////////////////////////////////////////
FILE_TEXTURE_2D_MODAL(TitleCard,BlendImgSampler,"Blended.dds",BORDER)
/////////////////////////////////////////////////////
//// Tweakables /////////////////////////////////////
/////////////////////////////////////////////////////
float Opacity <
string UIWidget = "slider";
float uimin = 0.0;
float uimax = 1.0;
float uistep = 0.01;
string UIName = "Title Opacity";
> = 1.0;
float XScale <
string UIName = "Width";
string UIWidget = "slider";
float UIMin = 0.1;
float UIMax = 10.0;
float UIStep = 0.01;
> = 1.0f;
float YScale <
string UIName = "Height";
string UIWidget = "slider";
float UIMin = 0.1;
float UIMax = 10.0;
float UIStep = 0.01;
> = 1.0f;
float XPos <
string UIName = "X";
string UIWidget = "slider";
float UIMin = -2.0;
float UIMax = 4.0;
float UIStep = 0.001;
> = 0.0f;
float YPos <
string UIName = "Y";
string UIWidget = "slider";
float UIMin = -2.0;
float UIMax = 4.0;
float UIStep = 0.001;
> = 0.0f;
#define CTR QUAD_REAL2(0.5,0.5)
static float2 Scale = 1.0/float2(XScale,YScale);
static float2 Pos = float2(-XPos,YPos) + CTR;
static QUAD_REAL2 pixelOffset = QUAD_REAL2(QuadTexOffset/(QuadScreenSize.x),QuadTexOffset/(QuadScreenSize.y));
/**************************************************************/
/********* utility pixel-shader functions and macros **********/
/**************************************************************/
QuadVertexOutput TitleQuadVS(
QUAD_REAL3 Position : POSITION,
QUAD_REAL3 TexCoord : TEXCOORD0
) {
QuadVertexOutput OUT;
OUT.Position = QUAD_REAL4(Position, 1);
QUAD_REAL2 nuv = Pos + (TexCoord.xy-CTR) * Scale;
#ifdef NO_TEXEL_OFFSET
OUT.UV = uv;
#else /* NO_TEXEL_OFFSET */
OUT.UV = QUAD_REAL2(nuv+pixelOffset);
#endif /* NO_TEXEL_OFFSET */
return OUT;
}
QUAD_REAL4 TexQuadOPS(QuadVertexOutput IN,uniform sampler2D InputSampler) : COLOR
{
QUAD_REAL4 texCol = tex2D(InputSampler, IN.UV);
return texCol*QUAD_REAL4(1,1,1,Opacity);
}
/*******************************************************************/
/************* TECHNIQUES ******************************************/
/*******************************************************************/
// simplest techniques work in ps_1_1
technique title < string Script = // "RenderColorTarget0=SceneTexture;"
// "RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=color;"
"Pass=p0;";
> {
pass p0 < string Script="Draw=Buffer;";
> {
VertexShader = compile vs_1_1 TitleQuadVS();
ZEnable = false;
ZWriteEnable = false;
CullMode = None;
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
PixelShader = compile ps_1_1 TexQuadPS(BlendImgSampler);
}
}
// simplest techniques work in ps_1_1
technique withOpacity < string Script = // "RenderColorTarget0=SceneTexture;"
// "RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=color;"
"Pass=p0;";
> {
pass p0 < string Script="Draw=Buffer;";
> {
VertexShader = compile vs_1_1 TitleQuadVS();
ZEnable = false;
ZWriteEnable = false;
CullMode = None;
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
PixelShader = compile ps_1_1 TexQuadOPS(BlendImgSampler);
}
}
/***************************** eof ***/
]]>; \
sampler SampName = sampler_state { \
texture = ; \
AddressU = AddrMode; \
AddressV = AddrMode; \
MipFilter = LINEAR; \
MinFilter = LINEAR; \
MagFilter = LINEAR; \
};
//
// Simple 2D File Textures
//
// example usage: FILE_TEXTURE_2D(GlowMap,GlowSampler,"myfile.dds")
//
#define FILE_TEXTURE_2D(TextureName,SamplerName,Diskfile) FILE_TEXTURE_2D_MODAL(TextureName,SamplerName,(Diskfile),WRAP)
//
// Use this variation of DECLARE_QUAD_TEX() if you want a *scaled* render target
//
// example usage: DECLARE_SIZED_QUAD_TEX(GlowMap,GlowSampler,"A8R8G8B8",1.0)
#define DECLARE_SIZED_QUAD_TEX(TexName,SampName,PixFmt,Multiple) texture TexName : RENDERCOLORTARGET < \
float2 ViewPortRatio = {Multiple,Multiple}; \
int MipLevels = 1; \
string Format = PixFmt ; \
string UIWidget = "None"; \
>; \
sampler SampName = sampler_state { \
texture = ; \
AddressU = CLAMP; \
AddressV = CLAMP; \
MipFilter = POINT; \
MinFilter = LINEAR; \
MagFilter = LINEAR; \
};
//
// Use this macro to easily declare typical color render targets
//
// example usage: DECLARE_QUAD_TEX(ObjMap,ObjSampler,"A8R8G8B8")
#define DECLARE_QUAD_TEX(TextureName,SamplerName,PixelFormat) DECLARE_SIZED_QUAD_TEX(TextureName,SamplerName,(PixelFormat),1.0)
//
// Use this macro to easily declare variable-sized depth render targets
//
// example usage: DECLARE_SIZED_QUAD_DEPTH_BUFFER(DepthMap,"D24S8",0.5)
#define DECLARE_SIZED_QUAD_DEPTH_BUFFER(TextureName,PixelFormat,Multiple) texture TextureName : RENDERDEPTHSTENCILTARGET < \
float2 ViewPortRatio = {Multiple,Multiple}; \
string Format = (PixelFormat); \
string UIWidget = "None"; \
>;
//
// Use this macro to easily declare typical depth render targets
//
// example usage: DECLARE_QUAD_DEPTH_BUFFER(DepthMap,"D24S8")
#define DECLARE_QUAD_DEPTH_BUFFER(TexName,PixFmt) DECLARE_SIZED_QUAD_DEPTH_BUFFER(TexName,PixFmt,1.0)
//
// declare exact-sized arbitrary texture
//
// example usage: DECLARE_SIZED_TEX(BlahMap,BlahSampler,"R32F",128,1)
#define DECLARE_SIZED_TEX(Tex,Samp,Fmt,Wd,Ht) texture Tex : RENDERCOLORTARGET < \
float2 Dimensions = { Wd, Ht }; \
string Format = Fmt ; \
string UIWidget = "None"; \
int miplevels=1;\
>; \
sampler Samp = sampler_state { \
texture = ; \
AddressU = CLAMP; \
AddressV = CLAMP; \
MipFilter = NONE; \
MinFilter = LINEAR; \
MagFilter = LINEAR; \
};
//
// declare exact-sized square texture, as for shadow maps
//
// example usage: DECLARE_SQUARE_QUAD_TEX(ShadMap,ShadObjSampler,"A16R16G16B16F",512)
#define DECLARE_SQUARE_QUAD_TEX(TexName,SampName,PixFmt,Size) DECLARE_SIZED_TEX(TexName,SampName,(PixFmt),Size,Size)
//
// likewise for shadow depth targets
//
// example usage: DECLARE_SQUARE_QUAD_DEPTH_BUFFER(ShadDepth,"D24S8",512)
#define DECLARE_SQUARE_QUAD_DEPTH_BUFFER(TextureName,PixelFormat,Size) texture TextureName : RENDERDEPTHSTENCILTARGET < \
float2 Dimensions = { Size, Size }; \
string Format = (PixelFormat) ; \
string UIWidget = "None"; \
>;
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////// Utility Functions ////////
////////////////////////////////////////////////////////////////////////////
//
// Scale inputs for use with texture-based lookup tables. A value ranging from zero to one needs
// a slight scaling and offset to be sure to point at the centers of the first and last pixels
// of that lookup texture. Pass the integer size of the table in TableSize
// For now we'll assume that all tables are 1D, square, or cube-shaped -- all axes of equal size
//
// Cost of this operation for pixel shaders: two const-register
// entries and a MAD (one cycle)
QUAD_REAL scale_lookup(QUAD_REAL Value,const QUAD_REAL TableSize)
{
QUAD_REAL scale = ((TableSize - 1.0)/TableSize);
QUAD_REAL shift = (0.5 / TableSize);
return (scale*Value + shift);
}
QUAD_REAL2 scale_lookup(QUAD_REAL2 Value,const QUAD_REAL TableSize)
{
QUAD_REAL scale = ((TableSize - 1.0)/TableSize);
QUAD_REAL shift = (0.5 / TableSize);
return (scale.xx*Value + shift.xx);
}
QUAD_REAL3 scale_lookup(QUAD_REAL3 Value,const QUAD_REAL TableSize)
{
QUAD_REAL scale = ((TableSize - 1.0)/TableSize);
QUAD_REAL shift = (0.5 / TableSize);
return (scale.xxx*Value + shift.xxx);
}
// pre-multiply and un-pre-mutliply functions. The precision
// of thse operatoions is often limited to 8-bit so don't
// always count on them!
// The macro value of NV_ALPHA_EPSILON, if defined, is used to
// avoid IEEE "NaN" values that may occur when erroneously
// dividing by a zero alpha (thanks to Pete Warden @ Apple
// Computer for the suggestion in GPU GEMS II)
// multiply color by alpha to turn an un-premultipied
// pixel value into a premultiplied one
QUAD_REAL4 premultiply(QUAD_REAL4 C)
{
return QUAD_REAL4((C.w*C.xyz),C.w);
}
#define NV_ALPHA_EPSILON 0.0001
// given a premultiplied pixel color, try to undo the premultiplication.
// beware of precision errors
QUAD_REAL4 unpremultiply(QUAD_REAL4 C)
{
#ifdef NV_ALPHA_EPSILON
QUAD_REAL a = C.w + NV_ALPHA_EPSILON;
return QUAD_REAL4((C.xyz / a),C.w);
#else /* ! NV_ALPHA_EPSILON */
return QUAD_REAL4((C.xyz / C.w),C.w);
#endif /* ! NV_ALPHA_EPSILON */
}
/////////////////////////////////////////////////////////////////////////////////////
// Structure Declaration ////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
struct QuadVertexOutput {
QUAD_REAL4 Position : POSITION;
QUAD_REAL2 UV : TEXCOORD0;
};
/////////////////////////////////////////////////////////////////////////////////////
// Hidden tweakables declared by this .fxh file /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
#ifndef NO_TEXEL_OFFSET
#ifdef TWEAKABLE_TEXEL_OFFSET
QUAD_REAL QuadTexOffset = 0.5;
#else /* !TWEAKABLE_TEXEL_OFFSET */
QUAD_REAL QuadTexOffset < string UIWidget="None"; > = 0.5;
#endif /* !TWEAKABLE_TEXEL_OFFSET */
QUAD_REAL2 QuadScreenSize : VIEWPORTPIXELSIZE < string UIWidget="None"; >;
#endif /* NO_TEXEL_OFFSET */
////////////////////////////////////////////////////////////
////////////////////////////////// vertex shaders //////////
////////////////////////////////////////////////////////////
QuadVertexOutput ScreenQuadVS(
QUAD_REAL3 Position : POSITION,
QUAD_REAL3 TexCoord : TEXCOOR