Search Unity

Transfering 2.X code to a physically based shader

Discussion in 'Shaders' started by MithosKuu, Jun 20, 2015.

  1. MithosKuu

    MithosKuu

    Joined:
    May 12, 2010
    Posts:
    34
    I've got a 2.X shaderlying around that uses an RGB image to change the tint of different parts of the diffuse map, I would like to make it an additional option in the Standard Shader but I'm assuming I can't just drag and drop the code and expect it to work. Any tips on upgrading it? I've included the relevant code section below.


    Code (csharp):
    1.    float4 texcol = tex2D( _MainTex, i.uvK.xy ); //samples the main diffuse texture
    2.  
    3. // ignore black
    4. float4 c = tex2D( _ColorChangeMap, i.uvK.xy ); //samples the RGB texture
    5. if ((c.r==0) && (c.g==0) && (c.b==0))  // checks if all black (this is probably a bad way to check for it)
    6. { /*nothing*/ }
    7. else {    
    8.     float4 cout = c.r*_RedColor + c.g*_GreenColor + c.b*_BlueColor;  // if not all black, multiply the base RBG user texture by custom set user colors in the properties
    9.     texcol = texcol * cout; // multiply the modified color by the original diffuse map
    10. }