- Home /
Question by
phxvyper · May 17, 2016 at 09:13 PM ·
shadertransparencyvertexcgvertex shader
Adding transparency to vertex shader?
After googling around for a couple hours, I've concluded that I need to post a question about this.
I have a very limited knowledge of CG programming, so I'm not sure how to do this. How do I add transparency to the following vertex Shader? Such that two objects that are immediately next to eachother both have transparency, but the saturation or brightness of one object when viewed through the other does not increase? (Example of this happening in the linked video below)
My current vertex shader, taken off the internet:
Shader "Custom/VertexShader" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
}
SubShader{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard vertex:vert fullforwardshadows
#pragma target 3.0
struct Input {
float2 uv_MainTex;
float3 vertexColor; // Vertex color stored here by vert() method
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
o.vertexColor = v.color; // Save the Vertex Color in the Input for the surf() method
}
sampler2D _MainTex;
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb * IN.vertexColor; // Combine normal color with the vertex color
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Here is an example of that increasing brightness when viewed through other objects: https://dl.dropboxusercontent.com/u/65209053/ShareX/2016/05/2016-05-17_14-10-25.mp4
Comment