Vicas
October 23, 2014, 11:48am
1
I’m trying to get the top texture to blend onto the gold bar and make it shine, but I cannot figure out the right combination of blendmode and SetTexture.
I have tried to read up on SubShader but I cannot get it to work. The code:
Shader "Unlit/AlphaWithHighlight"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_DecalTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 200
//ZWrite On
Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
Pass
{
SetTexture[_MainTex]
{
combine texture
}
SetTexture[_DecalTex]
{
combine previous * texture alpha
}
// Add color in the end
}
}
Fallback "Diffuse"
}
_Yash
October 25, 2014, 1:46pm
2
This Fragment Shader should work.
Shader "Custom/Shine" {
Properties {
_Color("Color",Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Detail("Detail(RGB)",2D) = "white" {}
_Speed("speed", Float) = 1
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" }
Blend SrcAlpha OneMinusSrcAlpha
//Cull Off
//ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
Float _Speed;
sampler2D _Detail;
fixed4 _Color;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv: TEXCOORD0;
};
v2f vert(appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy;
o.uv = uv;
return o;
}
fixed4 frag(v2f i) : COLOR {
float2 uv = i.uv;
// scrolls shine texture in x direction
uv.x += _Time.x * _Speed;
// scrolls shine texture in y direction
//uv.y += _Time.x * _Speed;
fixed4 t1 = (tex2D(_MainTex,i.uv)) * _Color;
t1 = (t1 +tex2D(_Detail,uv))*t1.a;
return t1;
}
ENDCG
}
}
FallBack "Unlit/Transparent"
}