I’m trying to mix two Shadow Maps together for my 3D world but don’t know how to do it without a 3D model.
My draw code is in a function returning the merged shadow map…
private Texture2D mergeShadowMaps(String technique, Texture2D shadowMap1, Texture2D shadowMap2)
{
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
this.effect.CurrentTechnique = this.effect.Techniques[technique];
this.effect.Parameters["merge1"].SetValue(shadowMap1);
this.effect.Parameters["merge2"].SetValue(shadowMap2);
device.SetRenderTarget(renderTarget);
this.effect.CurrentTechnique.Passes[0].Apply();
// WHAT TO DO NOW???
device.SetRenderTarget(null);
return (Texture2D)renderTarget;
}
But I’m used to draw a model with the effect, now I’m only going to use these two Shadow Maps to draw and return a mixed Shadow Map. The code I have isn’t enough to ‘trigger’ the Shader effect.
How can this be done without a Model?? Should I use spriteBatch in someway?
I’m stuck…
Regards, Morgan
EDIT EDIT EDIT EDIT UPDATE UPDATE UPDATE…
Ok, now I’ve read your comments and tried to implement what you’ve said but I can’t make it all the way.
This is my HLSL Shader code.
Texture merge1;
sampler merge1Sampler = sampler_state
{
texture = <merge1>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
Texture merge2;
sampler merge2Sampler = sampler_state
{
texture = <merge2>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
struct VS_Input
{
float4 Position : POSITION;
float2 uv : TEXCOORD0;
};
struct VS_Output
{
float4 Position : POSITION;
float2 uv : TEXCOORD0;
};
VS_Output imageProcessingVS(VS_Input Input)
{
VS_Output Output;
Output.Position = float4(Input.Position.xy, 0, 1);
Output.uv = (Input.Position.xy + 1) / 2;
Output.uv.y = 1 - Output.uv.y;
return Output;
}
float4 shadowMapMergerPS(VS_Output Input) : COLOR0
{
float4 depth1 = tex2D(merge1Sampler, Input.uv);
float4 depth2 = tex2D(merge2Sampler, Input.uv);
if (depth1.r < depth2.r)
{
return depth1;
}
else
{
return depth2;
}
}
technique ShadowMapMerge
{
pass P0
{
VertexShader = compile vs_2_0 imageProcessingVS();
PixelShader = compile ps_2_0 shadowMapMergerPS();
}
}
And here is the function that is drawing my 3D Plane exported from Blender.
private Texture2D mergeShadowMaps(GraphicsDevice gD, String technique, Texture2D shadowMap1, Texture2D shadowMap2)
{
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
device.SetRenderTarget(renderTarget);
foreach (ModelMesh mesh in this.plateForShadowMap.Meshes)
{
foreach (ModelMeshPart meshPart in mesh.MeshParts)
{
gD.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset);
gD.Indices = meshPart.IndexBuffer;
Effect effect = meshPart.Effect;
effect.CurrentTechnique = effect.Techniques[technique];
this.effect.Parameters["merge1"].SetValue(shadowMap1);
this.effect.Parameters["merge2"].SetValue(shadowMap2);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
gD.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
meshPart.NumVertices, meshPart.StartIndex,
meshPart.PrimitiveCount);
}
}
}
device.SetRenderTarget(null);
return (Texture2D)renderTarget;
}
Both depth1 and depth2 are 0 in the vertex shader, I’ve added a U/V map to the object but I must say that I don’t know if the plane is rotaded right because Blender’s x, y ,z are not the same as when the object is loaded in Monogame.