Jump to content

Applying colors to masked textures


Recommended Posts

Using 50p's Masked Texture creator, I was trying to mess with it a little and was wondering if you could apply solid colors over the textures? I've given it a try below, but it doesn't work so therefore it's wrong. Can anyone help out? 

Lua File

float red;
float green;
float blue;
float alpha;

texture ScreenTexture;
sampler implicitInputTexture = sampler_state
{
    Texture = <ScreenTexture>;
};

texture MaskTexture;
sampler implicitMaskTexture = sampler_state
{
    Texture = <MaskTexture>;
};

float4 MaskTextureMain( float2 uv : TEXCOORD0 ) : COLOR0
{
    float4 sampledTexture = tex2D( implicitInputTexture, uv );
    float4 maskSampled = tex2D( implicitMaskTexture, uv );
    sampledTexture.a = (maskSampled.r + maskSampled.g + maskSampled.b) / 3.0f;
    return sampledTexture;
}

technique Technique1
{
    pass Pass1
    {
        MaterialAmbient = float4(red, green, blue, alpha);
        AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;
        PixelShader = compile ps_2_0 MaskTextureMain();
    }
}

Shader

CMasker = { }; 
CMasker.__index = CMasker; 
  
function CMasker: create( texture, mask ) 
    local cShader = {  
        shader = dxCreateShader( "/files/50masktexture.fx" ), 
        texture = dxCreateTexture( texture, "argb", true, "clamp" ), 
        maskTexture = dxCreateTexture( mask, "argb", true, "clamp" ), 
    }; 
         
    dxSetShaderValue( cShader.shader, "ScreenTexture", cShader.texture ); 
    dxSetShaderValue( cShader.shader, "MaskTexture", cShader.maskTexture ); 
    self.__index = self; 
    setmetatable( cShader, self ); 
    return cShader; 
end 
  
  
function CMasker: draw( x, y, width, height ) 
    if self.shader then 
        dxDrawImage( x, y, width, height, self.shader ); 
    end 
end 
  
function CMasker: color ( r, g, b )
    if self.shader then
        dxSetShaderValue ( self.shader, 'red', r/255 )
        dxSetShaderValue ( self.shader, 'green', g/255 )
        dxSetShaderValue ( self.shader, 'blue', b/255 )
        dxSetShaderValue ( self.shader, 'alpha', 255/255 )
    end
end
  
function CMasker: destroy( ) 
    if self.shader then 
        destroyElement( self.shader ); 
    end 
    if self.texture then 
        destroyElement( self.texture ); 
    end 
    if self.maskTexture then 
        destroyElement( self.maskTexture ); 
    end 
end 

 

Edited by ℓιgнт
Link to comment

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...