1
\$\begingroup\$

Is it possible to draw a model partially (along the X, Y or Z axis) to make an extending barrier or something like that? (Scaling doesn't work because of the textures)

\$\endgroup\$
2
\$\begingroup\$

It is possible. There was a nice feature in XNA pre-4.0 called ClipPlanes. There are several good tutorials on how to use them, I'd recommend this one:

Riemers XNA Tutorial - Clip planes

Now the problem is, ClipPlanes have been removed from XNA 4.0. Developers are supposed to implement it using shaders. I've found the following piece of code to do exactly this:

float4x4 World; 
float4x4 View; 
float4x4 Projection; 

float4 ClipPlane0; 

void vs(inout float4 position : POSITION0, out float4 clipDistances : TEXCOORD0) 
{ 
    clipDistances.x = dot(position, ClipPlane0); 
    clipDistances.y = 0; 
    clipDistances.z = 0; 
    clipDistances.w = 0; 

    position = mul(mul(mul(position, World), View), Projection); 
} 

float4 ps(float4 clipDistances : TEXCOORD0) : COLOR0 
{ 
    clip(clipDistances); 

    return float4(0, 0, 0, 0); // TODO: whatever other shading logic you want 
} 

technique 
{ 
    pass 
    { 
        VertexShader = compile vs_2_0 vs(); 
        PixelShader = compile ps_2_0 ps(); 
    } 
} 

I didn't test it myself, but I hope it helps.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.