Hi,
I’m trying to get deferred 2D-Light working.
The shader I’m using to combine the textures doesn’t work for OpenGL, though.
Using the same Shader on DirectX works perfectly fine.
When trying to set the parameters in OpenGL it can’t find “LightMap” and “NormalMap” in parameters.
Why is that and how can I solve this?
This is the Shader:
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
float ambient;
float4 ambientColor;
float lightAmbient;
sampler ColorMapSampler: register (s0); //Set by spritebatch
Texture2D LightMap;
sampler LightMapSampler: register (s1)
{
Texture = (LightMap);
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = wrap;
AddressV = wrap;
};
Texture2D NormalMap;
sampler NormalMapSampler: register (s2)
{
Texture = (NormalMap);
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = wrap;
AddressV = wrap;
};
float4 DeferredLightPixelShader(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
{
float4 col= tex2D(ColorMapSampler, texCoord.xy);
float4 shading = LightMap.Sample(LightMapSampler, texCoord.xy);
float3 normal = NormalMap.Sample(NormalMapSampler, texCoord.xy).rgb;
if(!any(normal))
{
return float4(0, 0, 0, 0);
}
return (col * ambientColor *ambient)+((shading * col) * lightAmbient);
}
technique DeferredLightEffect
{
pass Pass1
{
PixelShader = compile PS_SHADERMODEL DeferredLightPixelShader();
}
}