Search Unity

3 issues - cubemap to toonramp, alpha and load default texture

Discussion in 'Shaders' started by mcunha98, Aug 31, 2019.

  1. mcunha98

    mcunha98

    Joined:
    Jun 13, 2010
    Posts:
    261
    Hello,

    I'm trying to adapt my toon lit shader and need some help.

    1) How I move from cube map to toon ramp ? I put the variable, but actually don't have idea how implement it
    2) The alpha texture not work correctly, probably I need to use other operator
    3) When I define a default value for property (like gray on ramp, can I use a file path for default value, like /assets/shader/toon-ramp1.png) ???


    Code (CSharp):
    1.  
    2. Shader "Piglet/Toon Lit Alpha" {
    3.      Properties {
    4.          _Color ("Main Color", Color) = (.5,.5,.5,1)
    5.          _MainTex ("Base (RGB)", 2D) = "white" {}
    6.          _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal }
    7.          _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    8.      }
    9. SubShader {
    10.      Tags { "RenderType"="Opaque" "Queue"="Transparent" }
    11.      Pass {
    12.          Name "BASE"
    13.          Blend SrcAlpha OneMinusSrcAlpha
    14.          CGPROGRAM
    15.          #pragma vertex vert
    16.          #pragma fragment frag
    17.          #pragma fragmentoption ARB_precision_hint_fastest
    18.          #include "UnityCG.cginc"
    19.          sampler2D _MainTex;
    20.          samplerCUBE _ToonShade;
    21.          float4 _MainTex_ST;
    22.          float4 _Color;
    23.          struct appdata {
    24.              float4 vertex : POSITION;
    25.              float2 texcoord : TEXCOORD0;
    26.              float3 normal : NORMAL;
    27.          };
    28.        
    29.          struct v2f {
    30.              float4 pos : POSITION;
    31.              float2 texcoord : TEXCOORD0;
    32.              float3 cubenormal : TEXCOORD1;
    33.          };
    34.          v2f vert (appdata v)
    35.          {
    36.              v2f o;
    37.              o.pos = UnityObjectToClipPos (v.vertex);
    38.              o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    39.              o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));
    40.              return o;
    41.          }
    42.          float4 frag (v2f i) : COLOR
    43.          {
    44.              float4 col = _Color * tex2D(_MainTex, i.texcoord);
    45.              float4 cube = texCUBE(_ToonShade, i.cubenormal);
    46.              return float4(2.0f * cube.rgb * col.rgb, col.a);
    47.          }
    48.          ENDCG          
    49.      }
    50. }
    51. SubShader {
    52.      Tags { "RenderType"="Opaque" "Queue"="Transparent"}
    53.      Pass {
    54.          Name "BASE"
    55.          SetTexture [_MainTex] {
    56.              constantColor [_Color]
    57.              Combine texture * constant
    58.          }
    59.          SetTexture [_ToonShade] {
    60.              combine texture * previous DOUBLE, previous
    61.          }
    62.      }
    63. }
    64. Fallback "VertexLit"
    65. }
    66.  
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Last edited: Aug 31, 2019
  3. mcunha98

    mcunha98

    Joined:
    Jun 13, 2010
    Posts:
    261
    First of all, thanks for reply, but I really don't understand what exactly I need to do and about which of 3 points you reply