Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3D10: how to increase maxcount of SV_ClipDistance?

Started by mancubit Aug 6, 2010 at 8:57 AM 3 replies 7.3k views
Original Post
mancubit
mancubit
i would need more than 2 clipping planes in my vertex shader, but if I am trying to declare something like "float plane2 : SV_CLIPDISTANCE2;" in my vertex-output-struct, it results in an error saying: "invalid output semantic 'SV_CLIPDISTANCE2': Legal indices are in [0,1]".

So i read in the directx docs that you can increase these value but i dont understand how this can be accomplished:

doc says: "The combined clip and cull distance values are at most D3D#_CLIP_OR_CULL_DISTANCE_COUNT components in at most D3D#_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT registers.
Writable in the Vertex and Geometry shaders."

how exactly can I write these values in vertex shaders?

any help is appreciated!
Hodgman
Hodgman
I'm pretty sure D3D#_CLIP_OR_CULL_DISTANCE_COUNT, etc, are fixed values.

You can however implement your own clipping plane with the clip intrinsic.
mancubit
mancubit
i wanted to save pixel-shader-work so clip doesnt really help in my case.

too bad.. is there any other possibility? i would need 6 clipplanes

edit1:
just found out that there is an [clipplanes(float4, float4, ...)] shader expression which allows me to declare more than 2 clipping planes - i will give it a try
i am just wondering why this function is not really documented in sdk-help :-/

edit2:
seems to work quite well now

[clipplanes(g_clippingPlane0, g_clippingPlane1, g_clippingPlane2, g_clippingPlane3, g_clippingPlane4, g_clippingPlane5)]
VS_OUT VS(VS_IN input)
{
..
}

does the work - i guess they work like d3d9 clipplanes (i never used them but read about)

but if anyone knows how to increase this max clipdistance value - please let me know as i would prefer this method.

thanks for your help!

[Edited by - mancubit on August 6, 2010 10:49:46 AM]
DieterVW
DieterVW
The D3D#_CLIP_OR_CULL_DISTANCE_* values are #defines in the d3d11.h header file. For distance count the value is 8 and for element count the value is 2. This means you can have any number of clip or cull values provide that their sum is 8 or less and that they must be fit into 2 vec4 registers.

In D3D10+ you have to code the math yourself in the shader to put the vertex through the plane equation and then store the resulting distance value in one of the registers. Values greater than or equal to zero should not be clipped/culled. The values you provide will be interpolated so that each pixel is clipped appropriately.

Here is an example, using just cull distance.
cbuffer ClipPlanes{	float4 planes[6];};struct VS_OUT{	float4 pos : SV_Position;	float4 clips[2] : SV_CullDistance;};VS_OUT vsmain( float4 pos : SV_Position ){	VS_OUT vsout = (VS_OUT)0;	vsout.pos = pos;	for( uint i = 0; i < planes.Length; ++i )	{		((float[8])vsout.clips) = dot( planes.xyz, pos.xyz  ) - planes.w;	}	return vsout;}


Compiled with February 2010 SDK.
// Buffer Definitions://// cbuffer ClipPlanes// {////   float4 planes[6];                  // Offset:    0 Size:    96//// }////// Resource Bindings://// Name                                 Type  Format         Dim Slot Elements// ------------------------------ ---------- ------- ----------- ---- --------// ClipPlanes                        cbuffer      NA          NA    0        1//////// Input signature://// Name                 Index   Mask Register SysValue Format   Used// -------------------- ----- ------ -------- -------- ------ ------// SV_Position              0   xyzw        0     NONE  float   xyzw////// Output signature://// Name                 Index   Mask Register SysValue Format   Used// -------------------- ----- ------ -------- -------- ------ ------// SV_Position              0   xyzw        0      POS  float   xyzw// SV_CullDistance          0   xyzw        1  CULLDST  float   xyzw// SV_CullDistance          1   xyzw        2  CULLDST  float   xyzw//vs_4_0dcl_constantbuffer cb0[6], immediateIndexeddcl_input v0.xyzwdcl_output_siv o0.xyzw, positiondcl_output_siv o1.xyzw, cull_distancedcl_output_siv o2.xyzw, cull_distancedcl_temps 1mov o0.xyzw, v0.xyzwdp3 r0.x, cb0[0].xyzx, v0.xyzxadd o1.x, r0.x, -cb0[0].wdp3 r0.x, cb0[1].xyzx, v0.xyzxadd o1.y, r0.x, -cb0[1].wdp3 r0.x, cb0[2].xyzx, v0.xyzxadd o1.z, r0.x, -cb0[2].wdp3 r0.x, cb0[3].xyzx, v0.xyzxadd o1.w, r0.x, -cb0[3].wdp3 r0.x, cb0[4].xyzx, v0.xyzxadd o2.x, r0.x, -cb0[4].wdp3 r0.x, cb0[5].xyzx, v0.xyzxadd o2.y, r0.x, -cb0[5].wmov o2.zw, l(0,0,0,0)ret


[Edited by - DieterVW on August 6, 2010 1:41:35 PM]
mancubit
mancubit
thanks a lot!! works like a charm..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.