Hello everyone it is me again with my eternal shader issues!
This time I am trying to blend the texture of my character with the color of the material in front of him to add a somewhat x-ray effect.
Here is my current scene Imgur: The magic of the Internet . At first look the character may look darker but it is just the lighting affecting the Main camera. The main color of my character is white and if he stands behind a red square (just like in my scene), I want his main color to change accordingly.
So far I think I have coded something that should at least give me some change of texture but nothings happen. Even changing color directly in my inspector doesn’t alter my texture. Anyone can help me on that? Here is my code:
Shader "Outlined/Bumped Diffuse" {
Properties {
_Color ("Main Color", Color) = (.5,.5,.5,0)
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (0.0, 0.03)) = .005
_MainTex ("Base (RGB) Trans. (Alpha)", 2D) = "white" { }
_BumpMap ("Bumpmap", 2D) = "bump" {}
}
CGINCLUDE
#include "UnityCG.cginc"
ENDCG
SubShader {
Tags { "Queue" = "Transparent" }
Pass {
Cull Front
ZTest Always
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct vertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : POSITION;
float4 color : COLOR;
};
uniform float _Outline;
uniform float4 _OutlineColor;
VertexOutput vert(vertexInput v) {
// just make a copy of incoming vertex data but scaled according to normal direction
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
float2 offset = TransformViewToProjection(norm.xy);
o.pos.xy += offset * o.pos.z * _Outline;
o.color = _OutlineColor;
return o;
}
half4 frag(VertexOutput i) :COLOR {
return i.color;
}
ENDCG
}
Pass{
Tags { "Queue" = "Transparent" }
Cull Front
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma fragment frag
struct vertexInput {
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct VertexOutput {
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
VertexOutput vert(vertexInput v) {
VertexOutput k;
k.color = mul(UNITY_MATRIX_MVP,v.color);
return k;
}
half4 frag(VertexOutput i) :COLOR {
return i.color * 2;
}
ENDCG
}
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};
uniform sampler2D _MainTex;
uniform sampler2D _BumpMap;
uniform float3 _Color;
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Diffuse"
}