ich habe wieder ein neues Problem. Folgender Sacherverhalt:
Ich berechne im CS die neue Position eines Particles und speicher das ganze in einem RWStructuredBuffer:
Code: Alles auswählen
D3D11_BUFFER_DESC desc;
ZeroMemory( &desc, sizeof(desc) );
desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
desc.ByteWidth = size * count;
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
desc.StructureByteStride = size;
Versuche ich nun das ganze im Vertex Shader über die folgenden View auszulesen scheine ich immer nur Nullwerte zubekommen:
Code: Alles auswählen
D3D11_BUFFER_DESC descBuf;
ZeroMemory( &descBuf, sizeof(descBuf) );
buffer->GetDesc( &descBuf );
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
ZeroMemory( &desc, sizeof( desc ) );
desc.Format = DXGI_FORMAT_UNKNOWN;
desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
//desc.Buffer.ElementWidth = descBuf.StructureByteStride;
desc.Buffer.FirstElement = 0;
desc.Buffer.NumElements = descBuf.ByteWidth / descBuf.StructureByteStride;
HRESULT hres= _pd3dDevice->CreateShaderResourceView( buffer, &desc, view );
Compute Shader code:
Code: Alles auswählen
struct PARTICLE
{
float3 position;
float3 velocity;
float3 acceleration;
float3 color;
};
RWStructuredBuffer<PARTICLE> particle;
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
float dt=0.01;
//new position
particle[DTid.x].position = particle[DTid.x].position + dt*particle[DTid.x].velocity;
//new velocity [asume mass=1.0 & g=10]
particle[DTid.x].velocity = float3(0.0,-.1,0.0)+particle[DTid.x].velocity;
}
Code: Alles auswählen
struct VS_INPUT
{
float4 pos : POSITION;
float4 color : COLOR;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
float2 tex0 : TEXCOORD0;
float3 tex1 : TEXCOORD1;
float3 tex2 : TEXCOORD2;
float3 tex3 : TEXCOORD3;
};
struct VS_OUTPUT
{
float4 position : SV_Position;
float2 tex0 : TEXCOORD0;
float3 pos : TEXCOORD1;
float3 norm : TEXCOORD2;
float3 tex3 : TEXCOORD3;
};
struct PARTICLE
{
float3 position;
float3 velocity;
float3 acceleration;
float3 color;
};
cbuffer MatrixBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Proj;
float4 Sun;
};
StructuredBuffer<PARTICLE> particle;
VS_OUTPUT main(VS_INPUT v)
{
VS_OUTPUT output;
float4 pos = v.pos + float4(particle[0].position,0.0);
output.position = mul( pos, World );
output.position = mul( output.position, View );
output.position = mul( output.position, Proj );
output.pos = mul(pos,World);
output.norm = mul(v.normal,(float3x3)World);
return output;
};
Manuel