Shader Example

Posted mttnor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shader Example相关的知识,希望对你有一定的参考价值。

技术分享图片

 

//测试viewDir对顶点的影响
Shader "Example/TestViewDir" { Properties{ _RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0) _RimPower("Rim Power", Range(0.5,8.0)) = 3.0 } SubShader{ Tags{ "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert struct Input { float2 uv_MainTex; float2 uv_BumpMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _BumpMap; float4 _RimColor; float _RimPower; float _Test; void surf(Input IN, inout SurfaceOutput o) { half rim = 1 - saturate(dot(o.Normal,normalize(IN.viewDir))); float3 col = _RimColor.rgb * pow(rim, _RimPower); float4 c = float4(col, rim); o.Emission = c; } ENDCG } Fallback "Diffuse" }

  

技术分享图片

 


结果:最终输出颜色*ColorMask后再与屏幕上颜色进行混合叠加
Shader "Example/ColorMask" {
	Properties{
		_Color("Texture to blend", Color) = (1,1,1,1)
	}
	SubShader{
		Tags{ "Queue" = "Transparent" }
		ColorMask B
		Pass{
			Blend SrcColor one
			CGPROGRAM
			#include "UnityCG.cginc"
			#pragma vertex vert
			#pragma fragment frag

			float4 _Color;
			float4 vert(appdata_base v) : POSITION
			{
				return mul(UNITY_MATRIX_MVP, v.vertex);
			}

			float4 frag(float4 pos:POSITION) : COLOR
			{
				return _Color;
			}
			ENDCG
		}
	}
	Fallback Off
}

  



以上是关于Shader Example的主要内容,如果未能解决你的问题,请参考以下文章

Cg入门20:Fragment shader - 片段级模型动态变色(实现汽车动态换漆)

Shader2.0的顶点着色器和片段着色器

Shader HLSL片段说明

Cg入门16:Fragment shader - 片段级光照

Shader Example

shader example