Quote: "1/ how does the 'clip' command works? if it is true command )"
If the argument is negative then the pixel is not displayed. If it is positive then the pixel is displayed. You'll have to experiment to see what happens when it's zero.
Try the following simple shader and dba code:
// Simple clip shader
// Created 4 February 2009.
float4x4 wvp : WorldViewProjection;
float clipLevel = 0.4;
texture baseTexture < string ResourceName = ""; >;
sampler2D baseSample = sampler_state
{ texture = <baseTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
addressU = wrap;
addressV = wrap;
};
struct VSInput
{ float4 pos : position;
float2 UV : texcoord0;
};
struct VSOutput
{ float4 pos : position;
float2 UV : texcoord0;
};
struct PSInput
{ float2 UV : texcoord0;
};
struct PSOutput { float4 col : Color; };
VSOutput VShader(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV = In.UV;
return Out;
}
PSOutput PShader(PSInput In, PSOutput Out)
{ float4 color = tex2D(baseSample, In.UV);
// only output the pixel if the green component is bright enough
clip(color.g - clipLevel);
Out.col = color;
return Out;
}
technique test
{ pass p0
{ vertexShader = compile vs_2_0 VShader();
pixelShader = compile ps_2_0 PShader();
}
}
` simple demo of shader clip command
set display mode 1024, 768, 32
sync on: sync rate 60: sync
autocam off
position camera 0, 0, -200
point camera 0, 0, 0
` make a simple texture 64x64 pixels
create bitmap 1, 64, 64
cls rgb(128, 128, 0) ` fill it with mid yellow
ink rgb(0, 255, 0), 0
text 12, 24, "Green"
get image 1, 0, 0, 64, 64
set current bitmap 0
load effect "clip.fx", 1, 0
make object plain 1, 50, 50
texture object 1, 0, 1
set object effect 1, 1
clipLevel# = 0.4
repeat
text 20, 20, "clipLevel = "+str$(clipLevel#, 3)
if inkey$()="c"
inc clipLevel#, 0.001
else
if inkey$()="d" then dec clipLevel#, 0.001
endif
set effect constant float 1, "clipLevel", clipLevel#
sync
until spacekey()
end
Press "c" or "d" to change the clipping level.
Notice how the green letters gradually disappear as you increase the clipping level towards 1. Can you see why that happens?