Oh well i just double drew it as jjag and alker suggested before. I didn’t do the rendertarget thing after all. Background is white because i set the show vertex shading bool.
I think i left the depth buffer on for both i guess it doesn’t matter for this as its just a test.
I wish it was possible to get the current buffered pixel i could make a really efficient and basically amazing alpha depth blending shader.
Here is the shader below as it is so far, for anyone using custom vertex data.
Only one technique is actually clipping though because it takes two different kinds of vertex data. The part that’s displayed in shaded white is assumed to be solid and isn’t clipped at all i guess it could be though. Then i drew the normal arrows with the clipped technique. I dunno if that’s proper but it worked.
//_______________________________________________________________
// RtEffects01.fx
// PNCMT PosNormalColorTexture test run game07 multiple techniques with depth alpha or rt
// ______________________________________________________________
#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
//_______________________________________________________________
// common
//_______________________________________________________________
bool displayVertexNormalShading;
float alphaDiscardThreshold;
float3 lightDir;
float4 lightColor;
float ambientColor;
float4x4 gworld;
//float4x4 gview;
float4x4 gworldviewprojection;
Texture2D TextureA;
sampler2D TextureSamplerA = sampler_state
{
Texture = <TextureA>;
};
//_______________________________________________________________
// structs TechniqueA
//_______________________________________________________________
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TexureCoordinateA : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_Position;
float4 Color : COLOR0;
float2 TexureCoordinateA : TEXCOORD0;
float2 Depth : TEXCOORD1;
};
struct PixelShaderOutput
{
float4 Color : COLOR0;
};
//______________________________________________________________
// shader techniques TechniqueA
//______________________________________________________________
VertexShaderOutput VertexShaderFunctionA(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = mul(input.Position, gworldviewprojection);
output.Color = input.Color;
output.TexureCoordinateA = input.TexureCoordinateA;
output.Depth.x = output.Position.z;
output.Depth.y = output.Position.w;
return output;
}
PixelShaderOutput PixelShaderFunctionA(VertexShaderOutput input)
{
PixelShaderOutput output;
output.Color = tex2D(TextureSamplerA, input.TexureCoordinateA) * input.Color;
// example 1
//float depth = input.Depth.x / input.Depth.y;
//output.Color = (float4(depth, depth, depth, 0)); //Draw the depth in gray
// example 2
float depth = input.Depth.x / input.Depth.y;
if (output.Color.a < alphaDiscardThreshold) // .02f
clip(-1); // clip(1);
return output;
}
technique TechniqueA
{
pass
{
VertexShader = compile VS_SHADERMODEL VertexShaderFunctionA();
PixelShader = compile PS_SHADERMODEL PixelShaderFunctionA();
}
}
//_______________________________________________________________
// structs TechniqueB
//_______________________________________________________________
struct VertexShaderInputB
{
float4 Position : POSITION0;
float3 Normal : NORMAL0;
float4 Color : COLOR0;
float2 TexureCoordinateA : TEXCOORD0;
};
struct VertexShaderOutputB
{
float4 Position : SV_Position;
float3 Normal : NORMAL0;
float4 Color : COLOR0;
float2 TexureCoordinateA : TEXCOORD0;
};
struct PixelShaderOutputB
{
float4 Color : COLOR0;
};
//______________________________________________________________
// shader techniques TechniqueB
//______________________________________________________________
VertexShaderOutputB VertexShaderFunctionB(VertexShaderInputB input)
{
VertexShaderOutputB output;
output.Position = mul(input.Position, gworldviewprojection);
output.TexureCoordinateA = input.TexureCoordinateA * input.Color;
float3 normal = normalize(mul(input.Normal, gworld));
output.Normal = normal;
float lightIntensity = dot(normal, lightDir);
lightIntensity = saturate(lightIntensity);
float4 col = input.Color;
float alpha = col.a;
col = ((col *.5 + lightColor *.5) * (lightIntensity * (1 - ambientColor))) + (col * ambientColor);
col.a = alpha;
output.Color = col;
return output;
}
PixelShaderOutputB PixelShaderFunctionB(VertexShaderOutputB input)
{
PixelShaderOutputB output;
float4 A = tex2D(TextureSamplerA, input.TexureCoordinateA) * input.Color;
output.Color = A;
if (displayVertexNormalShading)
{
output.Color = input.Color; // vertex normal shading
}
return output;
}
technique TechniqueB
{
pass
{
VertexShader = compile VS_SHADERMODEL VertexShaderFunctionB();
PixelShader = compile PS_SHADERMODEL PixelShaderFunctionB();
}
}