I’ve been using this shader on my mobile app:
Shader "Mobile/Reflective/Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_DecalTex ("Decal (RGB) Transparency (A)", 2D) = "" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
SubShader {
LOD 200
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _DecalTex;
samplerCUBE _Cube;
fixed4 _Color;
fixed4 _ReflectColor;
struct Input {
float2 uv_MainTex;
float2 uv_DecalTex;
float3 worldRefl;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 c = tex * _Color;
o.Albedo = c.rgb;
fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
reflcol *= tex.a;
o.Emission = reflcol.rgb * _ReflectColor.rgb;
o.Alpha = reflcol.a * _ReflectColor.a;
}
ENDCG
}
FallBack "Mobile/Reflective/VertexLit"
}
I haven’t actually started using the _Decal Property because I reall am not sure how. If I try to change it out with MainText (Which I don’t use) in void surf it will have a tint on the texture. I would like to add the texture on top with the same reflect it gets from the cubemap.
So the results I have right now are:
- replace _MainTex with _Decal
Result: Applies the texture, but tints it with _Color
- replace _MainTex with _Decal and change fixed4 c = tex * _Color; to fixed4 c = tex;
Result: This will work with the texture and apply the cubemap for reflection, but the color is gone.
What I want is for it to apply the texture with the reflection from the cubemap, but not affect the existing _Color property which also has the cubemap reflection.
Any help would be appreciated. Thanks in advance.
In the pass I’ve added decals to the VertexLit shader by just adding a new Pass, but this shader has less code than that one and has no spot where I can find to add a pass.
I figured it out. Had to add “Category”, then from there I was able to add a pass in the shader away from “void surf”
I’m back at this. I didn’t realize that this actually adds an additional draw call because I added a new Pass.
Does anyone have any suggestions on how to add a second transparent texture without having to do another pass? Is that even possible?
This is my current shader which generates 2 draw calls. Removing the second pass would just call one draw call, but we lose the decal.
Shader "Mobile/Reflective/Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_DecalTex ("Decal (RGB) Transparency (A)", 2D) = "" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
Category {
Tags { "RenderType"="Opaque" }
LOD 200
SubShader {
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _DecalTex;
samplerCUBE _Cube;
fixed4 _Color;
fixed4 _ReflectColor;
struct Input {
float2 uv_MainTex;
float2 uv_DecalTex;
float3 worldRefl;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 c = tex * _Color;
o.Albedo *= c.rgb;
fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
reflcol *= tex.a;
o.Emission = reflcol.rgb * _ReflectColor.rgb;
o.Alpha = reflcol.a * _ReflectColor.a;
}
ENDCG
Pass{
Name "DECAL"
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest Greater 0.9
SetTexture [_DecalTex] {
}
}
}
}
FallBack "Mobile/Reflective/VertexLit"
}
??? Anyone? I just want to know if its possible so I can look more into it.
I’m having difficulty understanding what kind of effect you’re trying to achieve, and what exactly you’re stuck on.
Can’t you just Sample the Decal Texture in the surf function, and mix it manually with the Main Texture, before feeding it to the surface shader Albedo output?