Hi,
im trying to achieve a shader that makes any texture that is in front of the player see-through.
but i do not understand how to access the Z coor of any pixel that is processed by my shader to determine if it has to be see through or not.
from what i understood is that float4 has 4 indizes but i can only access the 1st and 2nd. any index beyond that generates errors while compiling.
I started with editing the basic shader that the content pipeline gives you when you created a new shader.
#if OPENGL
// #define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
Texture2D SpriteTexture;
sampler s0;
sampler2D SpriteTextureSampler = sampler_state {
Texture = <SpriteTexture>;
};
struct VertexShaderOutput {
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
float4 MainPS(VertexShaderOutput input) : COLOR {
float4 color = tex2D(s0, input.TextureCoordinates);
int dx = input.Position.x - 200;
int dy = input.Position.y - 200;
float dist = dx * dx + dy * dy;
if (dist < 10000) {
discard;
}
return color;
}
technique SpriteDrawing {
pass P0 {
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
when i assign input.Position.z or input.Position[2] to an int or float it still compiles and runs.
but when i try to use that variable for anything then it doesnt compile anymore without any error messages.
(i use 2D but use Z to give my tiles on my tilemap the ability to be above or below the player and other objects.)