Operating System: :Win10x64:
Render System: :DirectX11:
Hi,
what do I have to do to make instancing work with my own model, when it is working with the robot.mesh?
I tried to get instancing working on DirectX11. I started from the sample browser's New Instancing part. It was broken because it tried to work on tangents which are not present in the model. After I changed that, I was able to use the sample.
Code: Select all
InstanceManager* inMa = scnMgr->createInstanceManager("instanceManager", "robot.mesh", RGN_DEFAULT, InstanceManager::InstancingTechnique::TextureVTF, 4, InstanceManagerFlags::IM_VTFBESTFIT);
std::vector<InstancedEntity*> InstancedEntityList;
int mesh_x = 2;
int nrOfMeshes = mesh_x * mesh_x;
for (int i = 0; i < nrOfMeshes; i++)
{
InstancedEntity* E_robot = scnMgr->createInstancedEntity("Examples/Instancing/VTF/Robot", "instanceManager");
InstancedEntityList.push_back(E_robot);
NodeList.push_back(scnMgr->getRootSceneNode()->createChildSceneNode());
NodeList[i]->attachObject(InstancedEntityList[i]);
NodeList[i]->setPosition(j, 0, k); // j and k get defined by a loop and result in coordinates (-4 0 -2, 0 0 -2, -4 0 0, 0 0 0)
}
Code: Select all
vertex_program Ogre/Instancing/VTF_hlsl_vs hlsl
{
source VTFInstancing.hlsl
entry_point main_vs_tata
target vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3
uses_vertex_texture_fetch true
}
vertex_program Ogre/Instancing/VTF_vs unified
{
delegate Ogre/Instancing/VTF_hlsl_vs
default_params
{
param_named_auto viewProjMatrix viewproj_matrix
}
}
abstract material Examples/Instancing/VTF
{
technique
{
shadow_caster_material Examples/Instancing/VTF/shadow_caster
pass
{
vertex_program_ref Ogre/Instancing/VTF_vs
{
}
fragment_program_ref Ogre/Instancing_ps
{
}
texture_unit Diffuse
{
texture_alias DiffuseMap
}
texture_unit InstancingVTF
{
binding_type vertex
filtering none
}
}
}
}
material Examples/Instancing/VTF/Robot : Examples/Instancing/VTF
{
set_texture_alias DiffuseMap r2skin.jpg
}
Code: Select all
fragment_program Ogre/Instancing_hlsl_ps hlsl
{
source Instancing_ps.hlsl
entry_point main_ps_tata
target ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
}
fragment_program Ogre/Instancing_ps unified
{
delegate Ogre/Instancing_hlsl_ps
}
Code: Select all
struct VS_INPUT
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 uv0 : TEXCOORD0;
float4 m01 : TEXCOORD1;
float4 m23 : TEXCOORD2;
};
struct PS_INPUT
{
float2 uv0 : TEXCOORD0;
float3 Normal : TEXCOORD1;
float3 vPos : TEXCOORD2;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
PS_INPUT ps;
};
#define LOD 0
SamplerState SampleType;
VS_OUTPUT main_vs_tata( VS_INPUT input,
uniform float4x4 viewProjMatrix,
uniform Texture2D matrixTexture : register(t1)
)
{
VS_OUTPUT output;
float4 worldPos = 0;
float3 worldNorm = 0;
float3x4 worldMatrix;
worldMatrix[0] = matrixTexture.SampleLevel(SampleType, float2(input.m01.xy), LOD );
worldMatrix[1] = matrixTexture.SampleLevel(SampleType, input.m01.zw, LOD );
worldMatrix[2] = matrixTexture.SampleLevel(SampleType, input.m23.xy, LOD );
worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
//Transform the position
output.Position = mul( viewProjMatrix, worldPos );
output.ps.uv0 = input.uv0;
//Pass Normal and position for Blinn Phong lighting
output.ps.Normal = normalize(worldNorm);
output.ps.vPos = worldPos.xyz;
return output;
}
Code: Select all
struct VS_INPUT
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 uv0 : TEXCOORD0;
float4 m01 : TEXCOORD1;
float4 m23 : TEXCOORD2;
};
struct PS_INPUT
{
float2 uv0 : TEXCOORD0;
float3 Normal : TEXCOORD1;
float3 vPos : TEXCOORD2;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
PS_INPUT ps;
};
#define LOD 0
SamplerState SampleType;
VS_OUTPUT main_vs_tata( VS_INPUT input,
uniform float4x4 viewProjMatrix,
uniform Texture2D matrixTexture : register(t1)
)
{
VS_OUTPUT output;
float4 worldPos = 0;
float3 worldNorm = 0;
float3x4 worldMatrix;
worldMatrix[0] = matrixTexture.SampleLevel(SampleType, float2(input.m01.xy), LOD );
worldMatrix[1] = matrixTexture.SampleLevel(SampleType, input.m01.zw, LOD );
worldMatrix[2] = matrixTexture.SampleLevel(SampleType, input.m23.xy, LOD );
worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
//Transform the position
output.Position = mul( viewProjMatrix, worldPos );
output.ps.uv0 = input.uv0;
//Pass Normal and position for Blinn Phong lighting
output.ps.Normal = normalize(worldNorm);
output.ps.vPos = worldPos.xyz;
return output;
}
Code: Select all
red green blue alpha
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 0.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 0.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
0.0100 0.0000 0.0000 -4.0000
0.0000 0.0100 0.0000 0.0000
0.0000 0.0000 0.0100 -2.0000
Hilarius86