顶点色材质

2020-09-17 19:36发布

当3d场景中为了减少性能但是又要有光照效果的时候,经常会用到顶点色材质来弥补这种效果。


顶点色+自发光:

Shader "Unlit/VC"

{

Properties

{

_MainTex ("Texture", 2D) = "white" {}

}

SubShader

{

Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }

LOD 100

Cull off

Lighting Off

Pass

{

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"

struct appdata

{

float4 vertex : POSITION;

float2 uv : TEXCOORD0;

fixed4 color : COLOR; //顶点自身的颜色

};

struct v2f

{

float2 uv : TEXCOORD0;

float4 vertex : SV_POSITION;

fixed4 vertColor : COLOR;

};

sampler2D _MainTex;

float4 _MainTex_ST;

v2f vert (appdata v)

{

v2f o;

o.vertex = UnityObjectToClipPos(v.vertex);

o.uv = TRANSFORM_TEX(v.uv, _MainTex);

o.vertColor = v.color;

return o;

}

fixed4 frag (v2f i) : SV_Target

{

// sample the texture

fixed4 col = tex2D(_MainTex, i.uv)*i.vertColor;

return col;

}

ENDCG

}

}

}

定点色+自发光+黑色透明(加入混合模式:Blend One One)

Shader "Unlit/VCB"

{

Properties

{

_MainTex ("Texture", 2D) = "white" {}

}

SubShader

{

Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }

LOD 100

Cull off

Lighting Off

Blend One One

Pass

{

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"

struct appdata

{

float4 vertex : POSITION;

float2 uv : TEXCOORD0;

fixed4 color : COLOR; //顶点自身的颜色

};

struct v2f

{

float2 uv : TEXCOORD0;

float4 vertex : SV_POSITION;

fixed4 vertColor : COLOR;

};

sampler2D _MainTex;

float4 _MainTex_ST;

v2f vert (appdata v)

{

v2f o;

o.vertex = UnityObjectToClipPos(v.vertex);

o.uv = TRANSFORM_TEX(v.uv, _MainTex);

o.vertColor = v.color;

return o;

}

fixed4 frag (v2f i) : SV_Target

{

// sample the texture

fixed4 col = tex2D(_MainTex, i.uv)*i.vertColor;

return col;

}

ENDCG

}

}

}

本人qq:344810449,欢迎探讨研究。

有unity,shader,小程序等需求也可以联系本人,非常乐于助人。

如果觉得还不错给博主来个小惊喜,纯属自愿,不强求:



作者:unity游侠

链接:https://blog.csdn.net/y90o08u28/article/details/90714137

来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。