Some blood decal texture:

Based on tips from user mikaelc from this topic about lights mesh volumes (got this working thanks!) i thought to use similar technique for decals.
Debug view of [s]light[/s] decal volume mesh (one sphere):

but when i try to "project" my texture i got this:

(i placed multiple spheres to be able to see decal placement)
Veretex shader:
#pragma pack_matrix(row_major)
float4x4 WorldViewProjection : register(c0);
float4 ScreenParams : register(c4);// x - screen w; y - screen h; z - 1 / (2 *target/screen w); w - 1 / (2 *target/screen h)
struct A2V
{
float3 Position : POSITION;
};
struct V2P
{
float4 Position : POSITION;
float4 TexCoord : TEXCOORD0;
};
void main(in A2V IN, out V2P OUT)
{
float4 oPosition = mul(float4(IN.Position, 1.0f), WorldViewProjection);
OUT.Position = oPosition;
oPosition.x = ((oPosition.x + oPosition.w) * ScreenParams.x + oPosition.w) * ScreenParams.z;
oPosition.y = ((oPosition.w - oPosition.y) * ScreenParams.y + oPosition.w) * ScreenParams.w;
OUT.TexCoord = oPosition;
}
pixel shader (wrong):
#pragma pack_matrix(row_major)
sampler position_samp : register(s0);
sampler decal_samp : register(s1);
float4x4 ViewInv : register(c0);
struct V2P
{
float4 Position : POSITION;
float4 TexCoord : TEXCOORD0;
};
struct P2A
{
float4 Color : COLOR0;
};
void main(in V2P IN, out P2A OUT, in float2 svPos : VPOS)
{
float3 posVS = tex2Dproj(position_samp, IN.TexCoord).xyz;
float4 coord = mul(float4(posVS.xyz, 1.0f), ViewInv);
OUT.Color = tex2Dproj(decal_samp, coord);
}
How to get correct tex. coords for decal textures?
Thanks for your time.