Jump to content

Greenscreen shader


megaman54

Recommended Posts

So i want to create a shader which takes an image file (.png etc) and checks for specified pixel color and makes those pixels totally transparent. I kinda know how i would write the lua script but the HLSL language for shader is pretty much new to me so i was hoping if someone more experienced in HLSL would guide me a little. Thx 8)

Link to comment
  • MTA Team
texture texture0; 
  
sampler Sampler0 = sampler_state 
{ 
    Texture = (texture0); 
}; 
  
struct PSInput 
{ 
    float2 TexCoord : TEXCOORD0; 
}; 
  
float4 PixelShader_Background(PSInput PS) : COLOR0 
{ 
    float4 colors = tex2D(Sampler0, PS.TexCoord); 
    if (colors.g == 1 && colors.r == 0 && colors.b == 0) { 
        colors.a = 0; 
    } 
    return colors; 
} 
  
technique complercated 
{ 
    pass P0 
    { 
        PixelShader = compile ps_2_0 PixelShader_Background(); 
    } 
} 
  
technique simple 
{ 
    pass P0 
    { 
        Texture[0] = texture0; 
    } 
} 
  

Link to comment
texture texture0; 
  
sampler Sampler0 = sampler_state 
{ 
    Texture = (texture0); 
}; 
  
struct PSInput 
{ 
    float2 TexCoord : TEXCOORD0; 
}; 
  
float4 PixelShader_Background(PSInput PS) : COLOR0 
{ 
    float4 colors = tex2D(Sampler0, PS.TexCoord); 
    if (colors.g == 1 && colors.r == 0 && colors.b == 0) { 
        colors.a = 0; 
    } 
    return colors; 
} 
  
technique complercated 
{ 
    pass P0 
    { 
        PixelShader = compile ps_2_0 PixelShader_Background(); 
    } 
} 
  
technique simple 
{ 
    pass P0 
    { 
        Texture[0] = texture0; 
    } 
} 
  

Thanks for the shader code! Now i can get this script started properly :)

Link to comment
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...