Hey Guys,
i saw the idea from nkast to use more than one Texture on the GPU: Dictionary and Texture2D instances as a key.
I implemented all of it with a Cloned Monogame Repo but i don’t get the Shader to work, if i apply my Shader it Shows nothing:
Here is my 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
float4x4 MatrixTransform;
sampler Texture : register(s0);
sampler Texture1 : register(s1);
sampler Texture2 : register(s2);
sampler Texture3 : register(s3);
sampler Texture4 : register(s4);
sampler Texture5 : register(s5);
sampler Texture6 : register(s6);
sampler Texture7 : register(s7);
sampler Texture8 : register(s8);
sampler Texture9 : register(s9);
sampler Texture10 : register(s10);
sampler Texture11 : register(s11);
sampler Texture12 : register(s12);
sampler Texture13 : register(s13);
sampler Texture14 : register(s14);
sampler Texture15 : register(s15);
struct VertexShaderInput
{
float4 position : POSITION0;
float4 color : COLOR0;
float3 texCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 position : SV_Position;
float4 color : COLOR0;
float3 texCoord : TEXCOORD0;
};
VertexShaderOutput SpriteVertexShader(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.position = mul(input.position, MatrixTransform);
output.color = input.color;
output.texCoord = input.texCoord;
return output;
}
float4 SpritePixelShader(VertexShaderOutput input) : COLOR0
{
if (input.texCoord.z <= 7)
{
if (input.texCoord.z <= 3)
{
if (input.texCoord.z <= 1)
{
if (input.texCoord.z == 0)
return tex2D(Texture, input.texCoord.xy) * input.color;
else
return tex2D(Texture1, input.texCoord.xy) * input.color;
}
else
{
if (input.texCoord.z == 2)
return tex2D(Texture2, input.texCoord.xy) * input.color;
else
return tex2D(Texture3, input.texCoord.xy) * input.color;
}
}
else
{
if (input.texCoord.z <= 5)
{
if (input.texCoord.z == 4)
return tex2D(Texture4, input.texCoord.xy) * input.color;
else
return tex2D(Texture5, input.texCoord.xy) * input.color;
}
else
{
if (input.texCoord.z == 6)
return tex2D(Texture6, input.texCoord.xy) * input.color;
else
return tex2D(Texture7, input.texCoord.xy) * input.color;
}
}
}
else
{
if (input.texCoord.z <= 11)
{
if (input.texCoord.z <= 1)
{
if (input.texCoord.z == 8)
return tex2D(Texture8, input.texCoord.xy) * input.color;
else
return tex2D(Texture9, input.texCoord.xy) * input.color;
}
else
{
if (input.texCoord.z == 10)
return tex2D(Texture10, input.texCoord.xy) * input.color;
else
return tex2D(Texture11, input.texCoord.xy) * input.color;
}
}
else
{
if (input.texCoord.z <= 13)
{
if (input.texCoord.z == 12)
return tex2D(Texture12, input.texCoord.xy) * input.color;
else
return tex2D(Texture13, input.texCoord.xy) * input.color;
}
else
{
if (input.texCoord.z == 14)
return tex2D(Texture14, input.texCoord.xy) * input.color;
else
return tex2D(Texture15, input.texCoord.xy) * input.color;
}
}
}
}
technique BasicColorDrawing
{
pass Pass0
{
VertexShader = compile VS_SHADERMODEL SpriteVertexShader();
PixelShader = compile PS_SHADERMODEL SpritePixelShader();
}
}
My new Spritebatch:
public SpriteBatch(GraphicsDevice graphicsDevice,Effect effect)
{
if (graphicsDevice == null)
{
throw new ArgumentNullException("graphicsDevice", FrameworkResources.ResourceCreationWhenDeviceIsNull);
}
this.GraphicsDevice = graphicsDevice;
_spriteEffect = new SpriteEffect(graphicsDevice);
_spriteEffect.CurrentTechnique = effect.CurrentTechnique;
_spritePass = _spriteEffect.CurrentTechnique.Passes[0];
_batcher = new SpriteBatcher(graphicsDevice, 0);
_beginCalled = false;
}
And my new Draw is like in the link from nkast: https://github.com/MonoGame/MonoGame/compare/develop...nkast:tnc_SpriteBatch_Texturebatch