Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Blending Textures in Shader Output [SOLVED]

    SDK Help
    0
    5
    541
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post