Jump to content

  • Log In with Google      Sign In   
  • Create Account

e3d_ALiVE

Member Since 02 Jul 2008
Offline Last Active Aug 26 2011 01:18 AM

Topics I've Started

[D3D10] Copy mip level from texture to structured buffer

04 February 2011 - 01:17 PM

hello
i'm trying to copy single mip level from texture(R32_FLOAT) with many mip levels(10) into structured buffer(sizeof(float)*Width*Height).
Is there any way to do it, except custom map/unmap?

Is indexing structured buffer in compute shader faster then by simply calling load?
i got these errors
D3D11: ERROR: ID3D11DeviceContext::CopySubresourceRegion: When offset by the destination coordinates, pSrcBox does not fit on the destination subresource. OffsetSrcBox = { {0, 0, 0}, {200, 150, 1} }. DstSubresource = { {0, 0, 0}, {1920000, 1, 1} }. [ RESOURCE_MANIPULATION ERROR #280: COPYSUBRESOURCEREGION_INVALIDSOURCEBOX ]
D3D11: ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same, or castable to each other, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE ]

AngelScript variable decomposition

13 January 2011 - 12:23 PM

hello, i'v got a question :D
for example we have code
int a=5;
int b=a*7;
int c=(a*7)*a-b;
int d=b+c;
and i want to execute this string
int test=c+b;

is there any way to get from angel script information about all variables, that is associated with script string[a,b,c] without accessing private data of angelscript?

[D3D11 & CS]Hierarchical-Z map based occlusion culling

31 October 2010 - 01:59 AM

hello everyone
i decided to add occlusion culling to my little engine, and for test load cs_port map from CSS.
all shaders are based on this http://rastergrid.com/blog/2010/10/hierarchical-z-map-based-occlusion-culling/ and this http://www.nickdarnell.com/?p=942 demos
i decided to make it work with bounding boxes and completly on compute shader
everything went pretty good, i generate hiz map with 10 mip levels, look at it, it was ok
UAV and SRV works i checked by doing BBox/cam test on cpu, results matched more less
here's code for CS shader that perform culling

#pragma pack_matrix( row_major )
cbuffer CB
{
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4 FrustumPlanes[6]; // view-frustum planes in world space (normals face out)
float2 ViewportSize; // Viewport Width and Height in pixels
};

struct BBox
{
float3 Pos;
float3 Extent;
};

// Bounding sphere center (XYZ) and radius (W), world space
StructuredBuffer<BBox> Buffer0;
// Is Visible 1 (Visible) 0 (Culled)
RWStructuredBuffer<float> BufferOut;

Texture2D<float> HizMap;
SamplerState HizMapSampler;

SamplerState g_samHiz
{
AddressU = Clamp;
AddressV = Clamp;
AddressW = Clamp;
Filter = MIN_MAG_MIP_POINT;//MIN_MAG_POINT_MIP_LINEAR;
BorderColor=float4(0,0,0,0);
};


//#ifdef SM4
//#define NUM_THREADS_X 768
//#else
//#define NUM_THREADS_X 1024
//#endif
//[numthreads(NUM_THREADS_X, 1, 1)]
[numthreads(1, 1, 1)]
void CSMain( uint3 GroupId : SV_GroupID,
uint3 DispatchThreadId : SV_DispatchThreadID,
uint GroupIndex : SV_GroupIndex)
{

int index = DispatchThreadId.x;
BBox bb=Buffer0[index];
float3 Pos=bb.Pos;
float3 Extent=bb.Extent;

float4 BoundingBox[8];
BoundingBox[0] = float4( Pos + float3( Extent.x, Extent.y, Extent.z), 1.0 );
BoundingBox[1] = float4( Pos + float3(-Extent.x, Extent.y, Extent.z), 1.0 );
BoundingBox[2] = float4( Pos + float3( Extent.x,-Extent.y, Extent.z), 1.0 );
BoundingBox[3] = float4( Pos + float3(-Extent.x,-Extent.y, Extent.z), 1.0 );
BoundingBox[4] = float4( Pos + float3( Extent.x, Extent.y,-Extent.z), 1.0 );
BoundingBox[5] = float4( Pos + float3(-Extent.x, Extent.y,-Extent.z), 1.0 );
BoundingBox[6] = float4( Pos + float3( Extent.x,-Extent.y,-Extent.z), 1.0 );
BoundingBox[7] = float4( Pos + float3(-Extent.x,-Extent.y,-Extent.z), 1.0 );


/* check how the bounding box resides regarding to the view frustum */
int outOfBound[6];
int i;

for (i=0; i<8; i++)
{
BoundingBox[i]=mul(BoundingBox[i],ViewProjection);
if ( BoundingBox[i].x > BoundingBox[i].w ) outOfBound[0]++;
if ( BoundingBox[i].x < -BoundingBox[i].w ) outOfBound[1]++;
if ( BoundingBox[i].y > BoundingBox[i].w ) outOfBound[2]++;
if ( BoundingBox[i].y < -BoundingBox[i].w ) outOfBound[3]++;
if ( BoundingBox[i].z > BoundingBox[i].w ) outOfBound[4]++;
if ( BoundingBox[i].z < -BoundingBox[i].w ) outOfBound[5]++;
}

float inFrustum = 1;

for (i=0; i<6; i++)
if ( outOfBound[i] == 8 ) inFrustum = 0;

if(inFrustum==0)
{
BufferOut[index]=0;
return;
}



/* perform perspective division for the bounding box */
for (i=0; i<8; i++)
BoundingBox[i].xyz /= BoundingBox[i].w;

/* calculate screen space bounding rectangle */
float2 BoundingRect[2];
BoundingRect[0].x = min( min( min( BoundingBox[0].x, BoundingBox[1].x ),
min( BoundingBox[2].x, BoundingBox[3].x ) ),
min( min( BoundingBox[4].x, BoundingBox[5].x ),
min( BoundingBox[6].x, BoundingBox[7].x ) ) ) / 2.0 + 0.5;
BoundingRect[0].y = min( min( min( BoundingBox[0].y, BoundingBox[1].y ),
min( BoundingBox[2].y, BoundingBox[3].y ) ),
min( min( BoundingBox[4].y, BoundingBox[5].y ),
min( BoundingBox[6].y, BoundingBox[7].y ) ) ) / 2.0 + 0.5;
BoundingRect[1].x = max( max( max( BoundingBox[0].x, BoundingBox[1].x ),
max( BoundingBox[2].x, BoundingBox[3].x ) ),
max( max( BoundingBox[4].x, BoundingBox[5].x ),
max( BoundingBox[6].x, BoundingBox[7].x ) ) ) / 2.0 + 0.5;
BoundingRect[1].y = max( max( max( BoundingBox[0].y, BoundingBox[1].y ),
max( BoundingBox[2].y, BoundingBox[3].y ) ),
max( max( BoundingBox[4].y, BoundingBox[5].y ),
max( BoundingBox[6].y, BoundingBox[7].y ) ) ) / 2.0 + 0.5;


/* then the linear depth value of the front-most point */
float InstanceDepth = min( min( min( BoundingBox[0].z, BoundingBox[1].z ),
min( BoundingBox[2].z, BoundingBox[3].z ) ),
min( min( BoundingBox[4].z, BoundingBox[5].z ),
min( BoundingBox[6].z, BoundingBox[7].z ) ) );

/* now we calculate the bounding rectangle size in viewport coordinates */
float ViewSizeX = (BoundingRect[1].x-BoundingRect[0].x) * ViewportSize.x;//they use different kind
float ViewSizeY = (BoundingRect[1].y-BoundingRect[0].y) * ViewportSize.y;

/* now we calculate the texture LOD used for lookup in the depth buffer texture */
float LOD = ceil( log2( max( ViewSizeX, ViewSizeY ) / 2.0 ) );

float4 Samples;
Samples.x = HizMap.SampleLevel( g_samHiz, float2(BoundingRect[0].x, BoundingRect[0].y), LOD ).x;
Samples.y = HizMap.SampleLevel( g_samHiz, float2(BoundingRect[0].x, BoundingRect[1].y), LOD ).x;
Samples.z = HizMap.SampleLevel( g_samHiz, float2(BoundingRect[1].x, BoundingRect[1].y), LOD ).x;
Samples.w = HizMap.SampleLevel( g_samHiz, float2(BoundingRect[1].x, BoundingRect[0].y), LOD ).x;

float MaxDepth = max( max( Samples.x, Samples.y ), max( Samples.z, Samples.w ) );
float Final=1;
if( InstanceDepth > MaxDepth ) Final=0;
BufferOut[index]=Final;
}




the first part performs frustum culling, the second occlusion, i'v checked all data set all good, hiz map has 10 mips, but errors shows as i move camera on Y axis up or down whole occlusion get wrong results, i seem to get right results only when LOD=9 - last mip level, i'm trying to get this work for 5 hours with no luck
it seems that i compute bounding rect wrong or there is something with depth

i output depth from pixel shader as just Output.vPosition.z for hiz map

i generate MipMap using that shader, by drawing quad


Texture2D<float> LastMip;

void MipMapVS(in float4 iPos: POSITION,
out float4 PositionSS : SV_POSITION)
{
PositionSS=float4(iPos.x, iPos.y, 0.5f, 1.0f);
}
float4 MipMapPS( float4 PositionSS : SV_POSITION ) : SV_TARGET
{
uint lastMipWidth, lastMipHeight;
LastMip.GetDimensions(lastMipWidth, lastMipHeight);

// get integer pixel coordinates
uint3 nCoords = uint3( PositionSS.xy, 0 );

// fetch a 2x2 neighborhood and compute the max
nCoords.xy *= 2;


float4 vTexels;
vTexels.x = LastMip.Load( nCoords );
vTexels.y = LastMip.Load( nCoords, uint2(1,0) );
vTexels.z = LastMip.Load( nCoords, uint2(0,1) );
vTexels.w = LastMip.Load( nCoords, uint2(1,1) );


// Determine the largest depth value and use it as the new down sampled
// color.
float fMaxDepth = max( max( vTexels.x, vTexels.y ), max( vTexels.z, vTexels.w ) );

// if we are reducing an odd-sized texture,
// then the edge pixels need to fetch additional texels
float2 vExtra;
if( (lastMipWidth & 1) && nCoords.x == lastMipWidth-3 )
{
vExtra.x = LastMip.Load( nCoords, uint2(2,0) );
vExtra.y = LastMip.Load( nCoords, uint2(2,1) );
fMaxDepth = max( fMaxDepth, max( vExtra.x, vExtra.y ) );
}

if( (lastMipHeight & 1) && nCoords.y == lastMipHeight-3 )
{
vExtra.x = LastMip.Load( nCoords, uint2(0,2) );
vExtra.y = LastMip.Load( nCoords, uint2(1,2) );
fMaxDepth = max( fMaxDepth, max( vExtra.x, vExtra.y ) );
}

// extreme case: If both edges are odd, fetch the bottom-right corner texel
if( ( ( lastMipWidth & 1 ) && ( lastMipHeight & 1 ) ) &&
nCoords.x == lastMipWidth-3 && nCoords.y == lastMipHeight-3 )
{
fMaxDepth = max( fMaxDepth, LastMip.Load( nCoords, uint2(2,2) ) );
}


return fMaxDepth;
}




i'v tried outputing depth as VS(z/w) as PS(z/w) but it get's me nothing, the only thing that works is pure PS z.
this shader is combining these two articles sources together, i'm new to compute shaders, but it definetly executes and all params are set
dx render: dx11
objects for occlusion map exists and it's ok, so the error must be somewhere in the shader
or maybe this alghorytm just can't work with any bboxes like occlusion querys can
maybe i'm missing something

p.s. i visualize depth by using this snippet

float LinearizeDepth(float z)
{
float n = 1.0; // camera z near
float f = 1000.0; // camera z far
return (2.0 * n) / (f + n - z * (f - n));
}




[Edited by - e3d_ALiVE on October 31, 2010 10:53:06 AM]

Animation Controller & Weights

18 September 2010 - 12:13 AM

i'v been implementing my own animation controller, based off id3dxanimationcontroller, my problem is that i can't completly understood how weights work
so far i'v come up with

[original_position or identity] ->weight0 -> anim0-> weight1 ->anim1 ->result
which for 2 tracks go like this

result=Lerp( Lerp(original,anim0,weight0), anim1,weight1)

which i for now implemented by decomposing matrix from previous frame


D3DXVECTOR3 LerpV(D3DXVECTOR3 a,D3DXVECTOR3 b,float weight)
{
D3DXVECTOR3 res;
res=a * (1.0f - weight) + b * weight;
return res;
}
D3DXQUATERNION LerpQ(D3DXQUATERNION a,D3DXQUATERNION b,float weight)
{
D3DXQUATERNION res;
D3DXQuaternionSlerp(&res,&a,&b,weight);//will be replaced by nlerp
return res;
}
...

D3DXVECTOR3 s0,t0;
D3DXQUATERNION quat0;
s0=D3DXVECTOR3(1,1,1);
t0=D3DXVECTOR3(0,0,0);
quat0=qid;

D3DXMatrixDecompose(&s0,&quat0,&t0,pMatrix);

t=LerpV(t0,t,track.weight);
s=LerpV(s0,s,track.weight);
quat=LerpQ(quat0,quat,track.weight);

D3DXMatrixTransformation(&result, NULL, NULL, &s, NULL, &quat, &t);

*pMatrix = result;




my question is how real world weights in animation controller are working and implemented?

[DX11/10]Premultiplied Alpha

25 June 2010 - 12:27 AM

i wanted to try using premultiplied alpha with CSS map
here's settings for it in FX

BlendState AlphaBlending
{
AlphaToCoverageEnable = TRUE;
BlendEnable[0] = TRUE;
SrcBlend = ONE;
DestBlend = INV_SRC_ALPHA;
BlendOp = ADD;
SrcBlendAlpha = ONE;
DestBlendAlpha = ZERO;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0F;
};
i sample it like that
g_txDiffuse.Sample(g_samRender,Input.vTexcoord.xy).rgba;

SamplerState g_samRender
{
AddressU = Wrap;
AddressV = Wrap;
Filter = ANISOTROPIC;
MaxAnisotropy=16;
};








i set in in technique like that SetBlendState( AlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
but instead of alpha image i get just the standart premultiplied texture


Bigger image
Does anyone knows what settings i'v set wrong?
p.s. Standart alpha mapping[setting alpha to 0.65f] works

[Edited by - e3d_ALiVE on June 25, 2010 9:34:32 AM]

PARTNERS