Hi,
I'm starting to use shaders, but as soon as I use the function
dbSetObjectEffect(terrainId, myEffect) the program crash.
Since I'm new in shaders, and I'm using a pre-made shader, can you help me to find the problem?
This is my code:
Code: Select all
Global myEffect.l = 1
dbLoadEffect("BasicLightMapping.fx", myEffect, 0)
.. load models, and do something else...
If dbEffectExist(myEffect)
dbSetObjectEffect(terrainId, myEffect)
dbTextureObject(terrainId, 0, 100001)
dbTextureObject(terrainId, 1, 100002)
Else
MessageRequester("d", "Error. Cannot load/use the shader.")
EndIf
This is the shader:
Code: Select all
//
// Very basic shader for blending a diffuse texture with ambient light and a
// lightmap written by Green Gandalf 31 March 2007.
//
float4x4 wvp : WorldViewProjection;
float4 ambient = {1.0, 1.0, 1.0, 1.0};
float4 blend1 = {0.3, 0.3, 0.3, 1.0};
float4 blend2 = {0.7, 0.7, 0.7, 1.0};
texture diffuseTex < string ResourceName=""; >;
texture lightMap < string ResourceName=""; >;
sampler2D diffuseSamp = sampler_state { texture = <diffuseTex>; };
sampler2D lightMapSamp = sampler_state { texture = <lightMap>; };
struct VSInput
{ float4 pos : Position;
float2 UV0 : Texcoord0;
float2 UV1 : Texcoord1;
};
struct VSOutput
{ float4 pos : Position;
float2 UV0 : Texcoord0;
float2 UV1 : Texcoord1;
};
struct PSInput
{ float2 UV0 : Texcoord0;
float2 UV1 : Texcoord1;
};
struct PSOutput
{ float4 col : Color;
};
VSOutput VShader(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV0 = In.UV0;
Out.UV1 = In.UV1;
return Out;
}
PSOutput PShader(PSInput In, PSOutput Out)
{ float4 diffuse = tex2D(diffuseSamp, In.UV0);
float4 lighting = tex2D(lightMapSamp, In.UV1);
Out.col = diffuse * (ambient * blend1 + lighting * blend2);
return Out;
}
technique basicLightMap
{ pass p0
{ vertexShader = compile vs_1_1 VShader();
pixelShader = compile ps_1_4 PShader();
}
}
[/code]