Blending Textures in Shader Output [SOLVED]
-
On 04/09/2016 at 07:27, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;---------
Hi,I am trying to blend 2 textures in shader output, according to a noise function.
I am getting the bitmap textures from shaderlinks.This is the blending code that I am using inside the shader output:
Real noise = Turbulence(cd->vd->p/500, 0, 3, FALSE); if (shaderA) colorA = shaderA->Sample(cd); if (shaderB) colorB = shaderB->Sample(cd); result = Mix(colorA , colorB , noise); return result;
The result that I get is grainy when the noise < 1, resulting in a grainy, jittery render. It's as if each point is sampled twice, instead of once, and the result is different every frame. So my method is obviously wrong.
The question is, what is the proper way to mix 2 textures according to a noise (or any other) function, in the OUTPUT of a shader?
-
On 05/09/2016 at 07:25, xxxxxxxx wrote:
Hi,
can you please try to check, if your problem is in sampling the noise or in mixing of colors?
My (untested) assumption is, that by dividing the sampling position by 500, you may actually run into aliasing or precision problems, leading to more or less random results. -
On 05/09/2016 at 07:47, xxxxxxxx wrote:
Thank you for the reply Andreas.
I'm afraid the problem lies elsewhere. Dividing by 500 is the scale of the noise function.
The problem persists even when I use another function than noise. Whenever the MIX value is between 0 and 1, i.e. where I have the blend between the 2 textures, the problem appears. If you can test it for confirmation it would be great.
-
On 06/09/2016 at 09:31, xxxxxxxx wrote:
Hi,
I haven't had the time for full blown tests, yet. But so far my tests showed no anomaly.
I know you are scaling the noise by dividing by 500, all I wanted to say was, that this scaling might or might not fit the scene/object proportions and you may end up with something pretty much random.
Another thing is setting bAbsolute to false, when calling the Turbulence(), as it will result in mix factors between -1.0 and 1.0. But that may be intended.
I think, we can rule out the Mix() function. It's so simple, I can't believe there's a problem with it, basically: result = a + (b-a) * mix
In order to help me investigating your issue, can you perhaps provide me with some images showing your issues? So I get a better idea, what to look out for. Sorry, for asking, but as I said, I wasn't able to reproduce your issue, yet (or I'm too blind to notice it).
By the way, if anybody is reading this thread using a more recent version of Cinema (>= R15), the Mix() function is called Blend() by now.
-
On 06/09/2016 at 11:50, xxxxxxxx wrote:
Thank you for your time Andreas.
It turns out I needed to clamp the result to remove any artifacts. All is working as it should now.