- Home /
Creating a shader that overlaps a diffuse with a TexGen ObjectLinear cutout
I was wondering how I would superimpose the red blood from this picture onto the soldier UV from this picture:
with
Here is the code I thought would work, but Alpha values don't seem to factor into shaderlab, which makes sense because otherwise transparency would be easy. The problem is I don't know how to combine anything without +/-/*, so I can never get the shader to look correct. I'm not worried about shader efficiency right now, just methodology.
Without further adeu, here's my code:
Shader "A/Blood Thermometer"
{
Properties
{
//_Health ("Health",Range(0,1)) = 1?
//_InvHealth ("Inverse Health",Range(0,1)) = 0?
//_Color ("Color", Color) = (1,0,0,1)? //red?
_MainTex ("Base (RGB)", 2D) = "" //the optimized UV texture for the character
_BloodTex ("Base (RGBA)", 2D) = "" {TexGen ObjectLinear} //the blood texture, which is placed in world space vertically
//_BloodTex is the output from a Substance (.SBSAR filetype) made in Substance Designer 2.
}
SubShader
{
Pass
{
SetTexture [_MainTex]
SetTexture [_BloodTex] {combine texture} //+ or * previous} doesn't work too well with any variation of _BloodTex color combinations
}
}
}
I'd like to see lighting turned on for the _MainTex, if that's easy. It seems like UsePass would work for the Diffuse, but not the Cutout-shader.
[EDIT:] I found this but I don't know how it helps.
/*!
* \file
* \author Stig Olavsen <stig.olavsen@randomrnd.com>
* \author http://www.RandomRnD.com
* \date © 2011-August-05
* \brief The shader definition for the HealthBar/HealthBar Transparent shader
* \details A transparent shader with two texture inputs and a ratio control
* that lets you set the display ratio of the two textures
*/
Shader "HealthBar/HealthBar Transparent" {
Properties {
_MainColor ("Base Color", Color) = (1,0,0,1)
_BackgroundColor ("Background Color", Color) = (0,0,0,0)
_MainTex ("Base (RGB)", 2D) = "white" {}
_BackgroundTex ("Base (RGB)", 2D) = "white" {}
_Health ("Health", Range(0.0, 1.0)) = 1.0
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
sampler2D _BackgroundTex;
fixed4 _MainColor;
fixed4 _BackgroundColor;
float _Health;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c;
if (IN.uv_MainTex.x < _Health)
{
c = tex2D (_MainTex, IN.uv_MainTex) * _MainColor;
}
else
{
c = tex2D (_BackgroundTex, IN.uv_MainTex) * _BackgroundColor;
}
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Comment