Page 2 of 2

Re: Help! "Multiply" transparency..?

Posted: 22 May 2013, 09:51
by Götz_B
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();
	}
}


Re: Help! "Multiply" transparency..?

Posted: 22 May 2013, 14:12
by Christian Krix Schmidt
This is great. I played around with a few settings and got it to work without a Shader node. Attached is a Ventuz archive.

Re: Help! "Multiply" transparency..?

Posted: 22 May 2013, 14:39
by Karol
Hi Chriss!

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

Cheers!
Karol

Re: Help! "Multiply" transparency..?

Posted: 23 May 2013, 08:13
by Christian Krix Schmidt
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.

Re: Help! "Multiply" transparency..?

Posted: 23 May 2013, 08:27
by mrmacmusic
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-)