I've searched the forums high and low. Everytime I call dbSetEffectConstantVector I get a visual studio 2008 debug error. I had limited success converting a shader to 1_1 from 1_4 and it cleared up that problem for one program, but I'm trying to use the per pixel lighting shader and have converted it(in my limited knowledge) to this:
//
````````````````````````````````````
````
// basic pixel lighting
// by EVOLVED
//
````````````````````````````````````
````
//
````````````````````````````````````
````
// un-TWEAKABLES
//
````````````````````````````````````
````
matrix WorldViewProj :
WorldViewProjection;
matrix World :
World;
matrix ViewInv :
ViewInverse;
//
````````````````````````````````````
````
// TWEAKABLES
//
````````````````````````````````````
````
float U <> = 1.0f;
float V <> = 1.0f;
float Height <> = 0.04;
float4 Light_Position <> =
{100.0f, 100.0f, 100.0f, 0.0f};
float4 Light_Colour <> =
{1.0f, 1.0f, 1.0f, 0.0f};
float Light_Range <> =
250.0f;
//
````````````````````````````````````
````
// Textures
//
````````````````````````````````````
````
// base texture
texture colorTexture <
string Name = ""; >;
// base Texture sampler
sampler2D colorSampler =
sampler_state
{
texture =
<colorTexture>;
};
// normal map texture
texture normalTexture <
string Name = ""; >;
// normal Texture sampler
sampler2D normalSampler =
sampler_state
{
texture =
<normalTexture>;
};
// offset height map
texture
texture offsetTexture <
string Name = ""; >;
// offset texture
sampler2D offsetSampler =
sampler_state
{
texture =
<offsetTexture>;
};
// point light 3d texture
texture lightTexture :
DIFFUSE
<
string Name
= "";
string
ResourceType = "3D";
>;
// point light Sampler
sampler3D lightSampler =
sampler_state
{
Texture =
<lightTexture>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MIPFILTER = NONE;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
//
````````````````````````````````````
````
// DATA STRUCTS
//
````````````````````````````````````
````
struct VS {
float4 Position :
POSITION;
float2 UV :
TEXCOORD;
float3 Normal :
NORMAL;
float3 Tangent :
TANGENT;
float3 Binormal :
BINORMAL;
};
struct VStoPS {
float4 pos
: POSITION;
float2 uv
: TEXCOORD0;
float3 View
: TEXCOORD1;
float3 light_vertex
: TEXCOORD2;
float3 light_pixel
: TEXCOORD3;
float light_range
: TEXCOORD4;
};
//
````````````````````````````````````
````
// Vertex shader V1.1
//
````````````````````````````````````
````
VStoPS VS_v11(VS IN)
{
VStoPS OUT;
// multiply vertex data to
world position
float3 wNormal =
mul(IN.Normal ,World);
float3 wTangent =
mul(IN.Tangent ,World);
float3 wBinorm =
mul(IN.Binormal,World);
float3 WPosition =
mul(IN.Position,World);
// normalize new vertex data
wNormal =
normalize(wNormal);
wTangent =
normalize(wTangent);
wBinorm =
normalize(wBinorm);
// Tangent matrix space
float3x3
Tangentmatrix = {wTangent, wBinorm,
wNormal};
Tangentmatrix =
transpose(Tangentmatrix);
// View noraml
float3 viewpos =
ViewInv[3].xyz - WPosition;
viewpos =
normalize(mul(viewpos,Tangentmatrix)
);
// light positions
float3 Lightpos
= Light_Position - WPosition;
float3 LightTangent
= mul(Lightpos,Tangentmatrix);
float Lightdis
= length(mul(Lightpos,wNormal));
// light fall out
float lightfall =
((1/Lightdis)*(Light_Range/5))-0.2;
if (lightfall>1)
lightfall=1;
if (lightfall<0)
lightfall=0;
// pointer light position
float lightpointdis
= Lightdis/1.5;
if
(lightpointdis>Light_Range)
lightpointdis=Light_Range;
float3
pointlight=(0.5+LightTangent*0.5 ) /
(Light_Range-lightpointdis)+0.5;
// output data
OUT.pos =
mul(IN.Position,WorldViewProj);
OUT.uv =
IN.UV*float2(U,V);
OUT.View =
viewpos;
OUT.light_vertex =
normalize(LightTangent);
OUT.light_pixel =
pointlight;
OUT.light_range =
lightfall;
return OUT;
}
//
````````````````````````````````````
````
// pixel shader V1.4
//
````````````````````````````````````
````
float4 PS_v14(VStoPS IN) : COLOR
{
// new pixel uv data for
offset mapping
float3 viewnormal =
IN.View ;
float heightmap =
tex2D(offsetSampler,IN.uv).x+(Height
/3);
float2 newuv =
(Height*heightmap*viewnormal)+IN.uv;
// textures
float4 texturebase =
tex2D(colorSampler,newuv);
float3 normalbase =
tex2D(normalSampler,newuv)*2-1;
float4 pointbase =
tex3D(lightSampler,IN.light_pixel);
// basic normal mapping
float3 lightvec
= IN.light_vertex;
float lightnormal
=
saturate(dot(normalbase,lightvec));
lightnormal
= lightnormal +
pow(saturate(dot(normalbase,lightvec
)),1);
float4 texturenormal
= lightnormal*Light_Colour;
texturenormal
= texturenormal*IN.light_range;
// return this
float4 result =
pointbase*texturebase*texturenormal;
return result;
}
//
````````````````````````````````````
````
// Vertex shader V2.0
//
````````````````````````````````````
````
VStoPS VS_v20(VS IN)
{
VStoPS OUT;
float3 wNormal =
mul(IN.Normal ,World);
float3 wTangent =
mul(IN.Tangent ,World);
float3 wBinorm =
mul(IN.Binormal,World);
float3 WPosition =
mul(IN.Position,World);
wNormal =
normalize(wNormal);
wTangent =
normalize(wTangent);
wBinorm =
normalize(wBinorm);
float3x3
Tangentmatrix = {wTangent, wBinorm,
wNormal};
Tangentmatrix =
transpose(Tangentmatrix);
float3 viewpos =
ViewInv[3].xyz - WPosition;
viewpos =
mul(viewpos,Tangentmatrix);
float3 Lightpos
= Light_Position - WPosition;
float3 LightTangent
= mul(Lightpos,Tangentmatrix);
float Lightdis
= length(mul(Lightpos,wNormal));
float lightfall =
((1/Lightdis)*(Light_Range/5))-0.2;
if (lightfall>1)
lightfall=1;
if (lightfall<0)
lightfall=0;
float lightpointdis
= Lightdis/1.5;
if
(lightpointdis>Light_Range)
lightpointdis=Light_Range;
float3
pointlight=(0.5+LightTangent*0.5 ) /
(Light_Range-lightpointdis)+0.5;
OUT.pos =
mul(IN.Position,WorldViewProj);
OUT.uv =
IN.UV*float2(U,V);
OUT.View =
viewpos;
OUT.light_vertex =
LightTangent;
OUT.light_pixel =
pointlight;
OUT.light_range =
lightfall;
return OUT;
}
//
````````````````````````````````````
````
// pixel shader v2.0
//
````````````````````````````````````
````
float4 PS_v20(VStoPS IN) : COLOR
{
float3 viewnormal =
normalize(IN.View) ;
float heightmap =
tex2D(offsetSampler,IN.uv).x+(Height
/3);
float2 newuv =
(Height*heightmap*viewnormal)+IN.uv;
float4 texturebase =
tex2D(colorSampler,newuv);
float3 normalbase =
tex2D(normalSampler,newuv)*2-1;
normalbase=normalize(normalbase);
float4 pointbase =
tex3D(lightSampler,IN.light_pixel);
float3 lightvec
= normalize(IN.light_vertex);
float lightnormal
=
saturate(dot(normalbase,lightvec));
lightnormal
= lightnormal + pow(saturate(dot(
reflect(-viewnormal,
normalbase),lightvec)),32);
float4 texturenormal
= lightnormal*Light_Colour;
texturenormal
= texturenormal*IN.light_range;
float4 result =
pointbase*texturebase*texturenormal;
return result;
}
//
````````````````````````````````````
````
// technique
//
````````````````````````````````````
````
technique pixellight14
{
pass one
{
vertexShader =
compile vs_1_1 VS_v11();
pixelShader =
compile ps_1_1 PS_v14();
}
}
technique pixellight20
{
pass one
{
vertexShader =
compile vs_2_0 VS_v20();
pixelShader =
compile ps_2_0 PS_v20();
}
}
But it still crashes, seems like something wrong with the pixel shader version, can I get some help with this?