//vari::udo 12.12.2014
//@author: vvvv group
//@help: basic pixel based lightning with directional light
//@tags: shading, blinn
//@credits:
// -----------------------------------------------------------------------------
// PARAMETERS:
// -----------------------------------------------------------------------------
//transforms
float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (EX9)
float4x4 tWV: WORLDVIEW;
float4x4 tWVP: WORLDVIEWPROJECTION;
float4x4 tP: PROJECTION; //projection matrix as set via Renderer (EX9)
float4x4 tVP: VIEWPROJECTION;
- include <effects\PhongDirectional.fxh>
//position texture
texture TexData <string uiname=“Data Texture”;>;
sampler SampData = sampler_state //sampler for doing the texture-lookup
{
Texture = (TexData); //apply a texture to the sampler
MipFilter = none; //sampler states
MinFilter = none;
MagFilter = none;
};
//ColorTexture
texture ColorTex <string uiname=“Color”;>;
sampler SampColor = sampler_state
{
Texture =(ColorTex);
MipFilter = none;
MinFilter = none;
MagFilter = none;
};
//texture
texture Tex <string uiname=“Texture”;>;
sampler Samp = sampler_state //sampler for doing the texture-lookup
{
Texture = (Tex); //apply a texture to the sampler
MipFilter = LINEAR; //sampler states
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float4x4 tTex: TEXTUREMATRIX <string uiname=“Texture Transform”;>;
float4x4 tColor <string uiname=“Color Transform”;>;
struct vs2ps
{
float4 Vcol : COLOR ;
float4 PosWVP: POSITION;
float4 TexCd : TEXCOORD0;
float3 LightDirV: TEXCOORD1;
float3 NormV: TEXCOORD2;
float3 ViewDirV: TEXCOORD3;
};
// -----------------------------------------------------------------------------
// VERTEXSHADERS
// -----------------------------------------------------------------------------
vs2ps VS(
float4 Vcol : COLOR ,
float4 PosO: POSITION,
float3 NormO: NORMAL,
float4 TexCd : TEXCOORD0)
{
//inititalize all fields of output struct with 0
vs2ps Out = (vs2ps)0;
//get the position info from the Position-velocity texture:
float3 particlePosition = tex2Dlod(SampData, TexCd).rgb;
//apply the tW (points at the mesh position)
PosO = mul(PosO, tW);
//now apply the position taken from the texture
PosO.xyz += particlePosition;
Vcol.xyz = tex2Dlod(SampColor, TexCd);
//then apply the tVP
PosO.xyz += mul(PosO.xyz, tP);
//inverse light direction in view space
Out.LightDirV = normalize(-mul(lDir, tV));
//normal in view space
Out.NormV = normalize(mul(NormO, tWV));
//position (projected)
Out.PosWVP = mul(PosO, tWVP);
Out.TexCd = mul(TexCd, tTex);
Out.ViewDirV = -normalize(mul(PosO, tWV));
return Out;
}
// -----------------------------------------------------------------------------
// PIXELSHADERS:
// -----------------------------------------------------------------------------
float Alpha = 1;
float4 PS(vs2ps In): COLOR
{
//In.TexCd = In.TexCd / In.TexCd.w; // for perpective texture projections (e.g. shadow maps) ps_2_0
float4 col = tex2D(Samp, In.TexCd);
col.rgb *= PhongDirectional(In.NormV, In.ViewDirV, In.LightDirV);
col.a *= Alpha;
return mul(col, tColor);
}
// -----------------------------------------------------------------------------
// TECHNIQUES:
// -----------------------------------------------------------------------------
technique TPhongDirectional
{
pass P0
{//
//Wrap0 = U; // useful when mesh is round like a sphere
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}
technique TFallbackGouraudDirectionalFF
{
pass P0
{
//transformations
NormalizeNormals = true;
WorldTransform0 = (tW);
ViewTransform = (tV);
ProjectionTransform = (tP);
//material
MaterialAmbient = {1, 1, 1, 1};
MaterialDiffuse = {1, 1, 1, 1};
MaterialSpecular = {1, 1, 1, 1};
MaterialPower = (lPower);
//texturing
Sampler[0](0) = (Samp);
TextureTransform[0](0) = (tTex);
TexCoordIndex[0](0) = 0;
TextureTransformFlags[0](0) = COUNT2;
//Wrap0 = U; // useful when mesh is round like a sphere
//lighting
LightEnable[0](0) = TRUE;
Lighting = TRUE;
SpecularEnable = TRUE;
LightType[0](0) = DIRECTIONAL;
LightAmbient[0](0) = (lAmb);
LightDiffuse[0](0) = (lDiff);
LightSpecular[0](0) = (lSpec);
LightDirection[0](0) = (lDir);
//shading
ShadeMode = GOURAUD;
VertexShader = NULL;
PixelShader = NULL;
}
}