Welcome, Guest.
Username: Password: Remember me

TOPIC: Outside VS triangle

Outside VS triangle 10 months 1 week ago #1

content out of the triangle always return 0 regardless of previous input?
trying to update texture sprites in single pass but didn't work.

and how about discard; ? it also returns 0.

demo code
texture2D SpriteTex     { Width   = 300; Height = 1; Format = R16F;};
sampler2D SpriteSampler { Texture = SpriteTex;  };

void VS_Sprite(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
{
    float2 vpos = float2(-1, 1);
    vpos.y = (id == 1)? -3 : vpos.y;
    vpos.x = (id == 2)?  3 : vpos.x;
    vpos.x = vpos.x / 30 + (frac(RFX_timer * 0.001 / 20) * 2 - 1);
    texcoord = 0.5;
    pos      = float4(vpos.xy, 0.0, 1.0);
}

float PS_Sprite(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0)  : SV_Target0
{   return 1;   }

// Fullscreen Triangle Vertex Shader
void VS_PostProcess(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
{
    texcoord.x = (id == 2) ? 2.0 : 0.0;
    texcoord.y = (id == 1) ? 2.0 : 0.0;
    pos = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

float PS_SpriteTest(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0)  : SV_Target0
{   
    if(texcoord.y > 0.5) discard;
    return tex2D(SpriteSampler, texcoord);   
}

technique Sprite < enabled = true;>
{
    pass 
    {
        VertexShader = VS_Sprite;
        PixelShader  = PS_Sprite;
        RenderTarget = SpriteTex;
    }
    
    pass 
    {
        VertexShader = VS_PostProcess;
        PixelShader  = PS_SpriteTest;
    }    
}
Last Edit: 10 months 1 week ago by kingeric1992.
The administrator has disabled public write access.

Outside VS triangle 10 months 1 week ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
All bound rendertargets are cleared to zero before the pixelshader is executed, so this is expected.
Cheers, crosire =)
The administrator has disabled public write access.

Outside VS triangle 10 months 1 week ago #3

ok.
The administrator has disabled public write access.