Home Marmoset

Making metalness detail map masking shader

polycounter lvl 13
Offline / Send Message
Tosyk polycounter lvl 13
Hi, I'm trying to create shader for masking detail texture to multiply with metalness map.Her's my model with albedo, roughness and metalness maps on  - no albedo or detail maps added at this point:


I already have mix pass for albedo and now I'm trying to perform similar to reflectivity map.
here's albedo part (it's working well):
  1. <div>void AlbedoDetailMap( inout FragmentState s )</div><div>{</div><div> #ifdef Albedo</div><div> Albedo(s);</div><div> #endif</div><div><br></div><div> vec4 mm = texture2D( tMaskMap, s.vertexTexCoord );</div><div> vec3 r = texture2D( tRedDetail, s.vertexTexCoord * uRedTileUV).rgb; </div><div> vec3 g = texture2D( tGreenDetail, s.vertexTexCoord * uGreenTileUV).rgb;</div><div> vec3 b = texture2D( tBlueDetail, s.vertexTexCoord * uBlueTileUV).rgb;</div><div> vec3 a = texture2D( tAlphaDetail, s.vertexTexCoord * uAlphaTileUV).rgb;</div><div><br></div><div> vec3 c = mix(vec3 (1, 1, 1), r, mm.r*(float)uRedEnable);</div><div> c = mix(c, g, mm.g*(float)uGreenEnable);</div><div> c = mix(c, b, mm.b*(float)uBlueEnable);</div><div> c = mix(c, a, mm.a*(float)uAlphaEnable);</div><div> </div><div> s.albedo.rgb = s.albedo.rgb * c * 1.2;</div><div>}</div><div><br></div><div>#ifdef Albedo</div><div> #undef Albedo</div><div>#endif</div><div>#define Albedo AlbedoDetailMap</div>
Here's what it looks like if I add albedo detail map:


and here's my attempt to the reflectivity map:
  1. void ReflectivityBlended(inout FragmentState s)
  2. {
  3. #ifdef Reflectivity
  4. Reflectivity(s);
  5. #endif
  6.  
  7. vec4 mm = texture2D( tMaskMap, s.vertexTexCoord );
  8.  
  9. vec3 r = texture2D( tRedPbr, s.vertexTexCoord * uRedTileUV ).rgb;
  10. vec3 g = texture2D( tGreenPbr, s.vertexTexCoord * uGreenTileUV ).rgb;
  11. vec3 b = texture2D( tBluePbr, s.vertexTexCoord * uBlueTileUV ).rgb;
  12. vec3 a = texture2D( tAlphaPbr, s.vertexTexCoord * uAlphaTileUV ).rgb;
  13.  
  14. float spec = 0.04;
  15. vec3 c = mix(vec3 (spec, spec, spec), r, mm.r*(float)uRedEnable);
  16. c = mix(c, g, mm.g*(float)uGreenEnable);
  17. c = mix(c, b, mm.b*(float)uBlueEnable);
  18. c = mix(c, a, mm.a*(float)uAlphaEnable);
  19.  
  20. s.reflectivity = s.albedo.xyz * c;
  21. //s.reflectivity = lerp( vec3( spec, spec, spec ), s.albedo.rgb c );
  22. }
  23.  
  24. #ifdef Reflectivity
  25. #undef Reflectivity
  26. #endif
  27. #define Reflectivity ReflectivityBlended
Here's what it looks like with reflectivity (metalness) detail map and that code from above:


So result is totally grey. I've tried different code swappings but since I don't know about this much all my attempts failed.

Can you guys help me with the code?
Sign In or Register to comment.