Announcement

Collapse
No announcement yet.

Mixing Normal Maps

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mixing Normal Maps

    Hi,
    I'm trying to shade a used electric guitar.
    To get the micro scraches I followed this tutorial: http://viscorbel.com/microscratches-...vray-tutorial/
    After some days of tweaking I decided to use 4 normal maps with different tiling and different kind of scraches, to get very thin small scraches and very long not so thin scraches.
    But how to blend them together?
    I used a Composite map with overlay mode, this looks quite right but on a secound look there are some scraches that look like they are pushed out and not in like they should be looking.
    I know that overlay isnĀ“t the right way and Composite maps are quite slow.
    Is there a way to do this inside of 3ds max?

    The only thing i could imagine is to copy this blend mtl with its three bumped materials from the tutorial, 4 times.
    One for every normal map and then blend them together in a 5th blend mtl which has to be blended on top of the wood mtl of the guitar (bend mtl no.6).
    If I then want to make a multi glossines effect, with, let's say 3 glossines layers i'll have to copy the 5th Blend Mtl and its sub tree 3 times, set up the glossines and blend it in another blend mtl.
    Then i get this Monster mtl:
    Click image for larger version

Name:	Monster-mtl.jpg
Views:	1
Size:	134.8 KB
ID:	883401
    I didn't try to render that jet but everything in me says: No! don't do that! It will be a nightmare to tweak. And i think it will be very slow.
    What would you guys suggest?
    Last edited by Ihno; 19-01-2016, 09:20 AM.
    German guy, sorry for my English.

  • #2
    You can try using nested VRayBumpMtl materials...

    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      I just finished an OSL shader that blends together normal maps in a better way than standard overlaying.

      Like so: http://blog.selfshadow.com/publicati...ing-in-detail/

      Save the code below as mixNormalMaps_tx_v001.osl or unpack the attached ZIP. Then create a VRayOSLTex (not Mat) and load in the OSL file, then plug in your maps.
      If you need to blend in more maps you can just duplicate the OSL node.

      That, or use Vlado's suggestion.

      Code:
      /*
      mixNormalMaps_tx_v001
      Created 2016-01-10 by Rens Heeren
      mail [at] rensheeren [dot] com
      www.rensheeren.com
      
      A shader for mixing together normal maps as outlined on this page
      http://blog.selfshadow.com/publications/blending-in-detail/
      
      It uses Reoriented Normal Mapping as described in the article as well as
      the idea from the second comment by "jarkko" in that article, which I have
      named Displacement Vector Normal Blending just to give it a name...
      
      Versions:
      v001 - First version.
      
      Use:
      Use as an OSL texture node, not a material node.
      Plug in two normal maps, and set the mode to either RNM or DVNB. Mix amount
      mixes back to to base input, meaning 1 is the result and 0 is the base as output.
      
      */
      
      
      
      // Reoriented Normal Mapping
      vector fn_rnm(vector v_n1, vector v_n2)
      {
      	vector v_t = v_n1 * vector(2, 2, 2) + vector(-1, -1, 0);
      	vector v_u = v_n2 * vector(-2, -2, 2) + vector(1, 1, -1);
      	vector v_r = v_t * dot(v_t, v_u) - v_u * v_t[2];
      	v_r = normalize(v_r);
      	v_r = (v_r + 1) * 0.5;
      	return v_r;
      }
      
      // Displacement Vector Normal Blending
      vector fn_disp(vector v_n1, vector v_n2)
      {
      	v_n1 = v_n1 * 2 - 1;
      	v_n2 = v_n2 * 2 - vector(1, 1, 2);
      	vector v_r = v_n1 + v_n2;
      	v_r = normalize(v_r);
      	v_r = (v_r + 1) * 0.5;
      	return v_r;
      }
      
      
      shader
      mixNormalMaps_tx_v001
      (
      	string input_base_map_1 = "",
      	color input_base_color_1 = color(0.5, 0.5, 1),
      	int use_texture_1 = 1
      		[[ string widget = "checkBox",
      		string description = "Use the texture instead of the colour."]],
      		
      	string input_detail_map_2 = "",
      	color input_detail_color_2 = color(0.5, 0.5, 1),
      	int use_texture_2 = 1
      		[[ string widget = "checkBox",
      		string description = "Use the texture instead of the colour."]],
      		
      	int mix_mode = 1
      		[[ string widget = "mapper",
      		string description = "The blending method to use.",
      		string options = "Reoriented_Normal_Mapping:1|Displacement_Vector:2" ]],
      	
      	float mix_amt = 1
      		[[string description = "Blend/Mix/Strength amount, 0 is the base input as output and 1 is the result of both maps." ]],
      	
      	output color out_mixed = color(0),
      	output color out_inputBase = color(0),
      	output color out_inputDetail = color(0),
      	
      	//output float out_alpha_mixed = 0,
      	output float out_alpha_inputBase = 0,
      	output float out_alpha_inputDetail = 0,
      	output float out_alpha_mixAmt = 0
      )
      {
      	// Declare Inputs
      	
      	float f_in1 = 1;
      	color c_in1 = color(0);
      	if (use_texture_1)
      	{
      		c_in1 = texture(input_base_map_1, u, v, "alpha", f_in1);
      	}
      	else
      	{
      		c_in1 = input_base_color_1;
      	}
      	
      	float f_in2 = 1;
      	color c_in2 = color(0);
      	if (use_texture_2)
      	{
      		c_in2 = texture(input_detail_map_2, u, v, "alpha", f_in2);
      	}
      	else
      	{
      		c_in2 = input_detail_color_2;
      	}
      	
      	int i_mixMode = mix_mode;
      	
      	float f_mixAmt = clamp(mix_amt, 0, 1);
      	
      	color c_out = color(0);
      	
      	
      	// Shader
      	
      	if (f_mixAmt > 0)
      	{
      		c_in2 = mix(color(0.5, 0.5, 1), c_in2, f_mixAmt);
      		
      		vector v_in1 = vector(c_in1[0], c_in1[1], c_in1[2]);
      		vector v_in2 = vector(c_in2[0], c_in2[1], c_in2[2]); 
      		vector v_out = vector(0, 0, 0);
      		
      		if (i_mixMode == 1)
      		{
      			v_out = fn_rnm(v_in1, v_in2);
      		}
      		if (i_mixMode == 2)
      		{
      			v_out = fn_disp(v_in1, v_in2);
      		}
      		c_out = color(v_out[0], v_out[1], v_out[2]);
      	}
      	else 
      	{
      		c_out = c_in1;
      
      	}
      	
      	
      	// Outputs
      	
      	out_mixed = c_out;
      	out_inputBase = c_in1;
      	out_inputDetail = c_in2;
      	
      	//out_alpha_mixed = 
      	out_alpha_inputBase = f_in1; 
      	out_alpha_inputDetail = f_in2;
      	out_alpha_mixAmt = f_mixAmt;
      }
      Attached Files
      Rens Heeren
      Generalist
      WEBSITE - IMDB - LINKEDIN - OSL SHADERS

      Comment


      • #4
        Great i think this will work.
        Unfortunetly there is no map input for the mix amount.
        But I could use a simple mix map for each normal map in which I mix the bitmap with the normal map base color (128,128,255) and pug this in your osl Map to blend the different normal maps.
        That would not destroy the normal map right?
        Last edited by Ihno; 20-01-2016, 04:30 AM.
        German guy, sorry for my English.

        Comment


        • #5
          Yep, that works, but that's easy to add, I'll try to post an update later on.
          Rens Heeren
          Generalist
          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

          Comment


          • #6
            That would assure you an entry in my imaginary book of cool People
            Last edited by Ihno; 20-01-2016, 05:01 AM.
            German guy, sorry for my English.

            Comment


            • #7
              Haha, well then I'd better get started!
              Rens Heeren
              Generalist
              WEBSITE - IMDB - LINKEDIN - OSL SHADERS

              Comment


              • #8
                OK, here we go!
                Attached Files
                Rens Heeren
                Generalist
                WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                Comment


                • #9
                  Thanks, you've got your entry.

                  But there is a little bug, swiching to displacement vector mode works well but the dropdown dosen't remember it.
                  If you swich to displacement vector mode, select another map and than go back to the mix normal map the dropdown showes reoriented mode.
                  It renders in DispVec mode anyway, so it just shows the wrong mode.

                  But that doesn't bother me. Thanks again
                  German guy, sorry for my English.

                  Comment


                  • #10
                    Originally posted by Ihno View Post
                    But there is a little bug, swiching to displacement vector mode works well but the dropdown dosen't remember it.
                    If you swich to displacement vector mode, select another map and than go back to the mix normal map the dropdown showes reoriented mode.
                    It renders in DispVec mode anyway, so it just shows the wrong mode.
                    That would be on our side. Will make a note to look into it.

                    Best regards,
                    Vlado
                    I only act like I know everything, Rogers.

                    Comment

                    Working...
                    X