srly i dont get it …
my shader code
#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
// Camera settings.
float4x4 WorldViewProjection;
float4x4 World;
float4x4 View;
float4x4 Projection;
float4x4 Model;
// This sample uses a simple Lambert lighting model.
float4 LightDirection;
float4 DiffuseLight;
float4 AmbientLight;
float4 Color;
Texture2D Texture;
sampler CustomSampler = sampler_state
{
Texture = (Texture);
};
struct VertexShaderInput
{
float4 Position : POSITION;
float3 Normal : NORMAL0;
float2 TextureCoordinate : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinate : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input, float4x4 transform : BLENDWEIGHT)
{
VertexShaderOutput output;
// Apply the world and camera matrices to compute the output position.
float4 position = input.Position;
position = mul(position, Model);
position = mul(position, transpose(transform));
position = mul(position, World);
position = mul(position, View);
position = mul(position, Projection);
output.Color = Color;
output.Position = position;
output.TextureCoordinate = input.TextureCoordinate;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
//return tex2D(CustomSampler, input.TextureCoordinate) * input.Color;
return input.Color;
}
// Hardware instancing technique.
technique Instancing
{
pass p0
{
VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
}
}
foreach (InstancedStaticActor actor in actors.Values)
{
if (actor.InstanceBuffer == null) continue;
Model model = actor.Model;
Matrix[] modelBones = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(modelBones);
foreach (var mesh in model.Meshes)
{
foreach (var meshPart in mesh.MeshParts)
{
GraphicsDevice.SetVertexBuffers(new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
new VertexBufferBinding(actor.InstanceBuffer, 0, actor.Count));
GraphicsDevice.Indices = meshPart.IndexBuffer;
Effect effect = instanceeffect;
effect.Parameters["World"].SetValue(world);
effect.Parameters["View"].SetValue(Scen.Camera.View);
effect.Parameters["Projection"].SetValue(Scen.Camera.Projection);
effect.Parameters["Model"].SetValue(modelBones[mesh.ParentBone.Index]);
//effect.Parameters["WorldViewProjection"].SetValue(worldviewprojection);
//effect.Parameters["Texture"].SetValue(((BasicEffect)meshPart.Effect).Texture);
effect.Parameters["Color"].SetValue(Vector4.One);
foreach (var pass in effect.Techniques["Instancing"].Passes)
{
pass.Apply();
GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, meshPart.StartIndex, meshPart.PrimitiveCount, actor.Count);
}
}
}
}
struct InstancedModelVertex : IVertexType
{
private Matrix transform;
public static VertexDeclaration Declaration { get; } = new VertexDeclaration(
new VertexElement(0 * 4 * sizeof(float), VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 0),
new VertexElement(1 * 4 * sizeof(float), VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 1),
new VertexElement(2 * 4 * sizeof(float), VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 2),
new VertexElement(3 * 4 * sizeof(float), VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 3));
public VertexDeclaration VertexDeclaration => Declaration;
public Matrix Transform { get => transform; set => transform = value; }
public InstancedModelVertex(Matrix transform)
{
this.transform = transform;
}
}