Hey all. I'm trying to get a self shadowing shader working from the nvidia website. This is the shader:
/*********************************************************************NVMH3****
File: $Id: //devrel/Playpen/kbjorke/HLSL/PointShadowAimRad8.fx#2 $
Copyright NVIDIA Corporation 2002
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
<scene_commands>
<!-- make shadow map "ShadMap" -->
<setcolortarget texture="ShadMap"/>
<setdepthstenciltarget texture="ShadDepthTarget"/>
<clear color="1.0,1.0,1.0,0" depth="1.0"/>
<settechnique name="MakeShadow"/>
<draw type="objects_override"/>
<setcolortarget texture="SceneMap"/>
<setdepthstenciltarget texture="SceneDepthTarget"/>
<clear color="0.0,0.0,0.0,0" depth="1.0"/>
<draw type="objects"/>
<setcolortarget/>
<setdepthstenciltarget/>
<clear color="0.0,0.0,0.0,0" depth="1.0"/>
<settechnique name="UseShadow"/>
<draw type="objects_override"/>
<!-- <settechnique name="ShowShadow"/>
<draw type="buffer"/> -->
</scene_commands>
******************************************************************************/
#ifndef SHADOW_SIZE
#define SHADOW_SIZE 512
#endif /* SHADOW_SIZE */
#ifndef SHADOW_FMT
//#define SHADOW_FMT "A8R8G8B8"
#define SHADOW_FMT "a16b16g16r16f"
#endif /* SHADOW_FMT */
#include "nvMatrix.fxh"
#include "Quad.fxh"
///////////////////////////////////////////////////////////////
/// TWEAKABLES ////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
float3 UpVector <
string UIName = "Up Vector";
// bool Normalized = 1;
> = { 0.0f, 0.0f, 1.0f};
////////////////////////////////////////////// spot light
float3 LightColor <
string UIName = "Light Color";
string Object = "PointLight";
string UIWidget = "Color";
> = {1.0f, 1.0f, 1.0f};
float3 DarkColor <
string UIName = "Dark Color";
string Object = "PointLight";
string UIWidget = "Color";
> = {0.8f, 1.0f, 0.4f};
/////////////// Shadow Parameters
float3 LightPos : POSITION <
string UIName = "Shadow comes from here";
string Object = "PointLight"; // hack for now -- no nulls
string Space = "World";
> = {1.0f, 0.0f, 0.0f};
float3 ShadowCenter : POSITION <
string UIName = "Shadow is centered here";
string Object = "PointLight"; // hack for now -- no nulls
string Space = "World";
> = {0.0f, 0.0f, 0.0f};
float ShadRadius <
string UIWidget = "slider";
float UIMin = 0.01;
float UIMax = 45.0;
float UIStep = 0.01;
string UIName = "Shadow Radius";
> = 5.0;
float ShadNear <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 4.0;
float UIStep = 0.01;
string UIName = "Shadow Near Fudge";
> = 0.0;
float ShadFar <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 4.0;
float UIStep = 0.01;
string UIName = "Shadow Far Fudge";
> = 0.0;
float ShadBias <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 0.1;
float UIStep = 0.001;
string UIName = "Shadow Bias";
> = 0.01;
////////////////////////////////////////////////////////
/// TEXTURES ///////////////////////////////////////////
////////////////////////////////////////////////////////
// screen-sized bg target
texture SceneMap : RENDERCOLORTARGET <
float2 ViewPortDimensions = {1.0,1.0};
int MIPLEVELS = 1;
string format = "a8b8g8r8";
string UIWidget = "None";
>;
sampler SceneSampler = sampler_state {
texture = <SceneMap>;
AddressU = BORDER;
AddressV = BORDER;
MIPFILTER = NONE;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
texture SceneDepthTarget : RENDERDEPTHSTENCILTARGET <
float2 ViewPortDimensions = {1.0,1.0};
string format = "D24S8";
string UIWidget = "None";
>;
// fixed-size shadow texture
texture ShadMap : RENDERCOLORTARGET <
// float2 ViewPortDimensions = {1.0,1.0};
int Width = SHADOW_SIZE;
int Height = SHADOW_SIZE;
// int MIPLEVELS = 1;
string format = (SHADOW_FMT);
string UIWidget = "None";
>;
sampler ShadSampler = sampler_state {
texture = <ShadMap>;
AddressU = BORDER;
AddressV = BORDER;
MIPFILTER = NONE;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
texture ShadDepthTarget : RENDERDEPTHSTENCILTARGET <
int Width = SHADOW_SIZE;
int Height = SHADOW_SIZE;
string format = "D24S8";
string UIWidget = "None";
>;
/////////////////////////////////////////////////////////////
#ifdef USE_NORMALIZATION_CUBEMAP
#include "normalize.fxh"
// only for pixel shaders....
/*
half3 my_normalize(half3 v)
{
half3 v2 = texCUBE(NormalizeSampler,v);
return (2*(v2-0.5));
}
half4 my_normalize(half4 v)
{
half3 v2 = texCUBE(NormalizeSampler,v.xyz);
return half4((2*(v2-0.5)),1);
}
*/
#define NORM my_normalize
#else /* !USE_NORMALIZATION_CUBEMAP */
#define NORM normalize
#endif /* !USE_NORMALIZATION_CUBEMAP */
/************* "UN-TWEAKABLES," TRACKED BY CPU APPLICATION **************/
float4x4 WorldITXf : WorldInverseTranspose <string UIWidget="None";>;
float4x4 WorldViewProjXf : WorldViewProjection <string UIWidget="None";>;
float4x4 WorldXf : World <string UIWidget="None";>;
float4x4 ViewIXf : ViewInverse <string UIWidget="None";>;
float4x4 WorldViewITXf : WorldViewInverseTranspose <string UIWidget="None";>;
float4x4 WorldViewXf : WorldView <string UIWidget="None";>;
float4x4 ViewXf : View <string UIWidget="None";>;
float4x4 ViewITXf : ViewInverseTranspose <string UIWidget="None";>;
////////////////////////////////////////////////////////////////////////////
/// SHADER CODE BEGINS /////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/*********************************************************/
/************* SHARED DATA STRUCT ************************/
/*********************************************************/
/* data from application vertex buffer */
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
};
///////////////////////////////////////////////////////////////////////////////
/// Basic Version Does Almost All Calcs in the Pixel Shader ///////////////////
///////////////////////////////////////////////////////////////////////////////
struct vertexOutput {
float4 HPosition : POSITION;
float4 UV : TEXCOORD0;
float4 LP : TEXCOORD1;
float4 diff : COLOR0;
};
/*********************************************************/
/*********** VM funcs ************************************/
/*********************************************************/
float4x4 shadowProjXf()
{
float3 aimVec = (ShadowCenter-LightPos);
float d = length(aimVec);
float shadCone = asin(ShadRadius/length(aimVec));
float3 aimN = normalize(aimVec);
float4x4 spotXf = nv_spot_xf(LightPos,aimN,UpVector);
float shadHither = max(0.01,(d-(ShadRadius+ShadNear)));
float shadYon = d+ShadRadius+ShadFar;
float4x4 projXf = nv_spot_proj_xf(spotXf,
shadCone,
shadHither,
shadYon);
return projXf;
}
////////////////////////////////////////////////////////////////////////////////
/// Vertex Shaders /////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// from lamp POV
vertexOutput shadVS(appdata IN,
uniform float4x4 ShadowXf)
{
vertexOutput OUT = (vertexOutput)0;
float4 Po = float4(IN.Position.xyz,(float)1.0); // object coordinates
float4 Pw = mul(Po,WorldXf); // world coordinates
float4 Pl = mul(Pw,ShadowXf); // "P" in light coords
OUT.LP = Pl; // view coords
OUT.HPosition = Pl; // mul(Po,WorldViewProjXf); // screen clipspace coords
OUT.UV = IN.UV;
return OUT;
}
// from scene camera POV
vertexOutput mainCamVS(appdata IN,
uniform float4x4 ShadowXf)
{
vertexOutput OUT = (vertexOutput)0;
float4 Po = float4(IN.Position.xyz,(float)1.0); // object coordinates
float4 Pw = mul(Po,WorldXf); // world coordinates
float4 Pl = mul(Pw,ShadowXf); // "P" in light coords
OUT.LP = Pl; // shad proj coords
float4 Ph = mul(Po,WorldViewProjXf); // screen clipspace coords
OUT.HPosition = Ph;
float2 buv = 0.5*(Ph.xy/Ph.w)+float2(0.5,0.5);
OUT.UV = float4(buv.x,1-buv.y,Ph.z,Ph.w);
OUT.diff = IN.UV;
return OUT;
}
/*********************************************************/
/*********** pixel shader ********************************/
/*********************************************************/
float4 makeShadPS(vertexOutput IN) : COLOR
{
return float4(IN.LP.zzz/IN.LP.w,1);
}
float4 useShadowPS(vertexOutput IN) : COLOR
{
//float4 texc = float4(IN.UV.xy,0,1);
float4 texc = tex2D(SceneSampler,IN.UV.xy);
// float4 texc = IN.diff;
float2 nuv = float2(.5,-.5)*IN.LP.xy/IN.LP.w + float2(.5,.5);
float shad = tex2D(ShadSampler,nuv).x;
float depth = (IN.LP.z/IN.LP.w) - ShadBias;
//shad = ShadBias+ShadNear + shad*(ShadFar-ShadNear);
float inShad = (shad<depth);
float3 col = texc.xyz * lerp(LightColor,DarkColor,inShad);
return float4(col.xyz,texc.w);
}
QUAD_REAL4 TexQuadFPS(QuadVertexOutput IN,
uniform sampler2D InputSampler,
uniform float minVal,
uniform float maxVal) : COLOR
{
QUAD_REAL4 texCol = tex2D(InputSampler, IN.UV);
return (texCol-minVal)/(maxVal-minVal);
}
////////////////////////////////////////////////////////////////////
/// TECHNIQUES /////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
technique MakeShadow {
pass shadPass {
VertexShader = compile vs_2_0 shadVS(shadowProjXf());
ZEnable = true;
ZWriteEnable = true;
CullMode = None;
PixelShader = compile ps_2_a makeShadPS();
}
}
technique UseShadow {
pass drawPass {
VertexShader = compile vs_2_0 mainCamVS(shadowProjXf());
ZEnable = true;
ZWriteEnable = true;
CullMode = None;
PixelShader = compile ps_2_a useShadowPS();
}
}
technique ShowShadow {
pass p0 {
VertexShader = compile vs_2_0 ScreenQuadVS();
AlphaBlendEnable = false; ZEnable = false;
// PixelShader = compile ps_2_a TexQuadFPS(ShadSampler,ShadNear,ShadFar);
PixelShader = compile ps_2_a TexQuadPS(ShadSampler);
}
}
/***************************** eof ***/
When i try to set effect after loading it, it says the effect doesnt exist and quits out. I'm guessing the loading fails. I guess it needs to be modified for use in dbp? (I will ultimatly be using with darksdk but im testing stuff in dbp 5.8 for now because shaders dont work in the sdk) but I dont even know where to begin..
Anyone fancy taking a look at it please? If something did need changing it would be nice if you say what you changed so I wont have to bug anyone next time a shader needs converting and just do it myself ^^
Thanks
[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu
[07:17:22-pm] « Mouse » he was hanging himself lol