Help! "Multiply" transparency..?

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

User avatar
Götz_B
Posts: 180
Joined: 21 May 2013, 13:01

Re: Help! "Multiply" transparency..?

Post by Götz_B » 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]

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();
	}
}


Christian Krix Schmidt
Posts: 290
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates
Contact:

Re: Help! "Multiply" transparency..?

Post by Christian Krix Schmidt » 22 May 2013, 14:12

This is great. I played around with a few settings and got it to work without a Shader node. Attached is a Ventuz archive.
Attachments
TextureBlend.vza
Texture Blending Example (Ventuz 3.08.01)
(434.76 KiB) Downloaded 292 times

User avatar
Karol
Posts: 605
Joined: 10 Jan 2012, 12:07

Re: Help! "Multiply" transparency..?

Post by Karol » 22 May 2013, 14:39

Hi Chriss!

Is it possible that you posted the wrong scene?
Your scene demonstrates only simple alpha blending!

Cheers!
Karol

Christian Krix Schmidt
Posts: 290
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates
Contact:

Re: Help! "Multiply" transparency..?

Post by Christian Krix Schmidt » 23 May 2013, 08:13

Nope. Just recreated the Shader. Should have checked the Photoshop picture posted earlier. No blending in this one. So I made a second one. The Fixed Funtion Pipeline could maybe solve that problem with a few Stages but that could be really complicated and take ages to figure out. The best solution without using a Shader would be to use a RenderTarget in which you create the blending first. Attached is a scene with just that. (TextureBlend2) Bonus is that you could also use a Blur Texture Node with the Logo texture.I also added an example. (TextureBlend3) There are a lot of combinations you could use. Those are just examples. But yeah in order to get it done without a Shader i guess you need a Render Target. Not ideal but if it is important to get that look and feel there you go.
Attachments
TextureBlend3.vza
TextureBlend3 - Ventuz 3.08.01
(443.47 KiB) Downloaded 295 times
TextureBlend2.vza
TextureBlend2 - Ventuz 3.08.01
(443.39 KiB) Downloaded 276 times

mrmacmusic
Posts: 43
Joined: 03 Apr 2013, 09:34

Re: Help! "Multiply" transparency..?

Post by mrmacmusic » 23 May 2013, 08:27

Sincere thanks Götz_B and Christian – most helpful!

The project that I needed the multiplication blend for went well with my bodged solution, but I've downloaded these files and will give the HLSL code a bash :)

Having a busy old time right now with non-Ventuz stuff, but I've finally bit the bullet and got the boss to invest in Cinema4D and am trying to make time to get to grips with my new toolset... looking forward to exploring a whole new 3D world with C4D and Ventuz 8-)

Post Reply