- Home /
Shader: Add one image's alpha to the other while keeping it unlit
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"
}
It looks as if your shine texture isn't set as transparent. It should look ok if the black is set as transparent and the shine brighten up a bit and just alpha blended on top.
Do you mean that I have to edit the shine in a photo editing tool or how do I "set it as transparent"? :-)
What i mean is, open that shine texture in Photoshop or any other graphics editing software you like, set the black as transparent, and then in Unity's import panel for that texture, tick the box about reading the file's alpha channel.
Answer by _Yash_ · Oct 25, 2014 at 01:46 PM
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"
}
Well I don't know, but my point is that it seems perfectly possible to make it without using a CGProgram, so that is really my question. I already have a working fragment shader, but I wanted to port it.
Since I don't know more about surface shader. this is what i did in fragment shader.
ColorOfGoldBar + ColorOfShintDetailImage
Animate UV of that black image with time.
As far as i know Surface shader is converted into vertex and fragment shaders, so writing vertex and fragment shder directly is more efficient.
Refer:http://docs.unity3d.com/$$anonymous$$anual/ShadersOverview.html
Your answer
Follow this Question
Related Questions
Blending parts of texture on 3d object with skinned mesh 0 Answers
Blending normal texture and texture made with shader 0 Answers
How can I make rim lighting appear in front of everything? 1 Answer
shader cg blending two textures 1 Answer
Additional blending when using properties rather than hard-coded values for colors 0 Answers