shader开发_4.Surface shader初探

来源:互联网 发布:单片机定时器工作原理 编辑:程序博客网 时间:2024/06/15 19:43

可编程渲染管线


unity shader==>>Surface shader


Surface shader是 unity 对于顶点和片段着色器的一种封装

下面这是一个unity 默认生成的Surface shader

Shader "Custom/myshader01" {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 200CGPROGRAM// Physically based Standard lighting model, and enable shadows on all light types#pragma surface surf Standard fullforwardshadows// Use shader model 3.0 target, to get nicer looking lighting#pragma target 3.0sampler2D _MainTex;struct Input {float2 uv_MainTex;};half _Glossiness;half _Metallic;fixed4 _Color;void surf (Input IN, inout SurfaceOutputStandard o) {// Albedo comes from a texture tinted by colorfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;o.Albedo = c.rgb;// Metallic and smoothness come from slider variableso.Metallic = _Metallic;o.Smoothness = _Glossiness;o.Alpha = c.a;}ENDCG}FallBack "Diffuse"}

首先卡一下基本结构

Shader "Custom/myshader01" {Properties { }SubShader { }FallBack "Diffuse"}

主要分为3个部分  PropertiesSubShaderFallBack

Properties主要定义了一些需要的属性 纹理贴图 资源

SubShader 自定义的shader代码  (最少有一个SubShaderSubShader内是没有 pass通道的 已经被封装

FallBack  如果所有通道都无法执行  会执行默认的shader(这个shader 在所有平台上基本上是都可用的)



 




0 0
原创粉丝点击