Re: Help! "Multiply" transparency..?
Posted: 22 May 2013, 09:51
To use the code, copy it in a HLSL Node and put two textures next to it. The first one needs to be the background and the second one your logo.
This means in the hierarchy editor it should look something like this:
[HLSL Node] - [texture node with background] - [texture node with logo] - [e.g. rectangle]
This means in the hierarchy editor it should look something like this:
[HLSL Node] - [texture node with background] - [texture node with logo] - [e.g. rectangle]
Code: Select all
// Photoshop style layer blending - multiply
float4x4 WorldViewProjection : WORLDVIEWPROJECTION;
//Textures
sampler2D tex1Sampler : register (s[0]) = sampler_state
{
//Texture = <tex1>; Unnecessary due to register (s[0]) which binds the sampler to a specific stage ( in this case 0).
};
sampler2D tex2Sampler : register (s[1]) = sampler_state
{
};
//Mapping
float4x4 TexMap[8]
<
string SasBindAddress = "Ventuz.Textures[*].Mapping";
>;
// Vertex shader program input
struct VS_INPUT
{
float4 Position : POSITION;
float2 tex1co : TEXCOORD0;
};
// Vertex shader program output
struct VS_OUTPUT
{
float4 Position : POSITION;
float2 tex1co : TEXCOORD0;
};
// Vertex Shader Program
VS_OUTPUT VS( VS_INPUT Input )
{
VS_OUTPUT Output;
// Transform the vertex from 3D object space to 2D screen space.
Output.Position = mul(Input.Position, WorldViewProjection);
//Pass Texture Coordinates
Output.tex1co = Input.tex1co;
return Output;
}
//Pixel Shader Programs
float4 PS_Normal( VS_OUTPUT Input ) :COLOR
{
//Apply mapping to texture coordinates by multiplying TC as a float4 vector with mapping matrix; get texture from sampler
float4 col1 = tex2D(tex1Sampler, mul(float4(Input.tex1co, 1.0, 0.0), TexMap[0]).xy);
float4 col2 = tex2D(tex2Sampler, mul(float4(Input.tex1co, 1.0, 0.0), TexMap[1]).xy);
return float4((col2.a * (col2) + (1.0f - col2.a) * col1).rgb, col1.a);
}
float4 PS_Multiply( VS_OUTPUT Input ) : COLOR
{
//Apply mapping to texture coordinates by multiplying TC as a float4 vector with mapping matrix; get texture from sampler
float4 col1 = tex2D(tex1Sampler, mul(float4(Input.tex1co, 1.0, 0.0), TexMap[0]).xy);
float4 col2 = tex2D(tex2Sampler, mul(float4(Input.tex1co, 1.0, 0.0), TexMap[1]).xy);
//Multiply blend
//Step by step:
//float3 rgb1 = float3(col1.r,col1.g,col1.b);
//float3 rgb2 = float3(col2.r,col2.g,col2.b);
//float alpha2 = col2.a;
//
//float3 fill;
//fill = alpha2 * ( rgb1 * rgb2 ) + (1.0f-alpha2) * rgb1;
//float4 fin = float4(fill, col1.a);
//
//return fin;
// Same operation in one line:
return float4((col2.a * (col1 * col2) + (1.0f - col2.a) * col1).rgb, col1.a);
}
// Techniques
//
// Techniques are used to support multiple vertex/pixel shader
// implementations in a single shader source file. For example,
// these might be different implementations of the same effect,
// each optimized for a specific hardware. The active technique
// can be switched by changing the "Technique" property in the
// Property Editor.
technique Normal
{
pass pass0
{
vertexshader = compile vs_3_0 VS();
pixelshader = compile ps_3_0 PS_Normal();
}
}
technique Multiply
{
pass pass0
{
vertexshader = compile vs_3_0 VS();
pixelshader = compile ps_3_0 PS_Multiply();
}
}