码迷,mamicode.com
首页 > 其他好文 > 详细

ceshi

时间:2019-10-05 16:44:17      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:class   spec   UNC   计算   multi   像素   ima   编译   reflect   

0x00 Surface Shader Syntax

内置常用的三种输出数据格式:

//Standard output structure of surface shaders is this:
struct SurfaceOutput{
    fixed3 Albedo;  // diffuse color
    fixed3 Normal;  // tangent space normal, if written
    fixed3 Emission;
    half Specular;  // specular power in 0..1 range
    fixed Gloss;    // specular intensity
    fixed Alpha;    // alpha for transparencies
};
//Unity 5版本以上, 支持physically based lighting models.
struct SurfaceOutputStandard{
    fixed3 Albedo;      // base (diffuse or specular) color
    fixed3 Normal;      // tangent space normal, if written
    half3 Emission;
    half Metallic;      // 0=non-metal, 1=metal
    half Smoothness;    // 0=rough, 1=smooth
    half Occlusion;     // occlusion (default 1)
    fixed Alpha;        // alpha for transparencies
};

//镜面高光输出
struct SurfaceOutputStandardSpecular{
    fixed3 Albedo;      // diffuse color
    fixed3 Specular;    // specular color
    fixed3 Normal;      // tangent space normal, if written
    half3 Emission;
    half Smoothness;    // 0=rough, 1=smooth
    half Occlusion;     // occlusion (default 1)
    fixed Alpha;        // alpha for transparencies
};

0x01 Surface Shader compile directives

Surface shader编码在CGPROGRAM...ENDCG块内,

  • 必须在Subshader块内而不能在pass内部,Surface shader将自己编译成多个通道.
  • 必须使用#pragma surface surfaceFunction lightModel [optionalparams] 指令来表明这是surface shader.

拆分#pragma surface surfaceFunction lightmodel [optional params]

蓝色为必要参数:require params

surfaceFunction 格式void surf (Input IN, inout SurfaceOutput o),Input自定义结构常必须包含纹理坐标和其他自需变量
lightModel
Standard lighting 使用SurfaceOutputStandard
StandardSpecular lighting 使用SurfaceOutputStandardSpecular
Lambert and BlinnPhong 不支持基于物理照明,低端设备用

surfaceFunction Input参数详解

struct Input
{
    //纹理坐标必须带uv或uv2前缀,必须!
    float2 uv_MainTex;
    //---以下为可选---
    float3 viewDir;    //视图方向为了计算时差、边缘光照等效果,Input需要包含视图方向
    float4 color;      //每个顶点颜色值
    float4 screenPos;  //屏幕空间位置,为了获得反射效果
    float3 worldPos;   //世界坐标空间
    float3 worldRefl;  //世界空间反射向量,surface shader不能写入o.Normal参数
    float3 worldNormal;//世界空间法向量,surface shader不能写入o.Normal参数

    //世界坐标反射向量,surface shader必须写入o.Normal参数
    //基于逐像素法线贴图获得反射向量,请使用WorldReflectionVector(IN,o.Normal)
    float3 worldRefl;INTERNAL_DATA;

    //世界坐标法线向量,surface shader必须写入o.Normal参数
    //基于逐像素法线贴图获得反射向量,请使用WorldReflectionVector(IN,o.Normal)
    float3 worldNormal;INTERNAL_DATA;
}

橙色为可选参数:optional params

alpha
alpha:auto
fade-transparency或premultiplied transparency



0x02 Surface Shader Light Model

0x03 Example

ceshi

标签:class   spec   UNC   计算   multi   像素   ima   编译   reflect   

原文地址:https://www.cnblogs.com/baolong-chen/p/11624840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!