- Home /
Adding transparency to a 2 texture blending shader...noobie.
Im new to messing with shaders and pieced this one together, but now im having trouble adding translucency to this....How would I get the 2 textures to be blendable but also have a slider or something that makes the blended outcome translucent?
Shader "Custom/My ToonShader Test1" {
Properties {
_Lookup ("BRDF Color Ramp", 2D) = "gray" {}
_MainTex ("Texture", 2D) = "white" {}
_Detail ("Texture", 2D) = "white" {}
_Blend ( "Blend", Range ( 0, 1 ) ) = 0.5
_RimPower ("Rim Power", Float) = 1.4
_RimColor ("Rim Color (RGB) + Intensity (A)", Color) = (0.0,0.0,0.0,1.0)
_SColor ("Shadow Color", Color) = (0.0,0.0,0.0,1)
_LColor ("Highlight Color", Color) = (0.5,0.5,0.5,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
SetTexture[_MainTex]
SetTexture[_Detail]
{
ConstantColor ( 0, 0, 0, [_Blend] )
Combine texture Lerp( constant ) previous
}
}
CGPROGRAM
#pragma surface surf Lookup
sampler2D _MainTex;
sampler2D _Lookup;
float _Blend;
sampler2D _Detail;
float4 _LColor;
float4 _SColor;
float _RimPower;
float4 _RimColor;
struct Input
{
float2 uv_MainTex;
float4 screenPos;
float2 uv_Detail;
float3 pos : POSITION0;
float3 viewDir;
};
half4 LightingLookup (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
float NdotL = dot(s.Normal, lightDir);
float NdotV = dot(s.Normal, viewDir);
float2 lookupUV = float2(NdotV*.8, NdotL * 0.5 + 0.5);
float3 exitRadiance = tex2D(_Lookup, lookupUV).rgb;
float4 c;
c.a = s.Alpha;
#ifndef USING_DIRECTIONAL_LIGHT
lightDir = normalize(lightDir);
#endif
half d = dot (s.Normal, lightDir)*0.5 + 0.5;
half3 ramp = tex2D(_Lookup, float2(d,d)).rgb;
ramp = lerp(_SColor, _LColor, ramp);
c.rgb = s.Albedo * _LightColor0.rgb * ramp * (exitRadiance * (atten * 2));
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV *= float2(1,1);
half4 mainTex = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = mainTex.rgb;
o.Alpha = mainTex.a;
fixed4 t1 = tex2D( _MainTex, IN.uv_MainTex);
fixed4 t2 = tex2D( _Detail, screenUV)*2;
o.Albedo = lerp( t1, t2, _Blend);
//Rim Outline
half rim = saturate( dot(normalize(IN.viewDir), o.Normal) );
o.Albedo *= 1.0f - (step(rim, _RimPower) * (1.0f-_RimColor) * _RimColor.a);
}
ENDCG
}
Fallback "Diffuse"
}
Answer by kapstok666 · Dec 16, 2014 at 11:42 AM
I don't know wether you're familiar with scripting but I suggest to use the Strumpy Shader Editor: https://www.assetstore.unity3d.com/en/#!/content/456 It is a way to 'visually' script a shader. This shader editor is another extension to your Unity editor and generates the code for you. Maybe this'll help you out ;)
I need the code...but I will try strumpy. I'll just have to rebuild my shader in strumpy.
@kapstok666 (+1) thank you for the info and link, and it's free, fantastic!!!
ohlin, you know the code is being generated by the shader editor right? So you have the shader code in a file in unity anyway.
You're welcome, $$anonymous$$rSoad :)