1. 程式人生 > >圖形處理之Unity3DShader(一)Vertex and Fragment Shader

圖形處理之Unity3DShader(一)Vertex and Fragment Shader

一、Properties

_MyColor ("Some Color", Color) = (1,1,1,1)

_MyVector ("Some Vector", Vector) = (0,0,0,0)

_MyFloat ("My float", Float) = 0.5

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

_MyCubemap ("Cubemap", CUBE) = "" {}

二、Tags

Possible values for LightMode tag are:

  • Always: Always rendered; no lighting is applied.
  • ForwardBase: Used in Forward rendering, ambient, main directional light, vertex/SH lights and lightmaps are applied.
  • ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light.
  • Deferred: Used in Deferred Shading; renders g-buffer.
  • ShadowCaster: Renders object depth into the shadowmap or a depth texture.
  • PrepassBase: Used in legacy Deferred Lighting, renders normals and specular exponent.
  • PrepassFinal: Used in legacy Deferred Lighting, renders final color by combining textures, lighting and emission.
  • Vertex: Used in legacy Vertex Lit rendering when object is not lightmapped; all vertex lights are applied.
  • VertexLMRGBM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is RGBM encoded (PC & console).
  • VertexLM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is double-LDR encoded (mobile platforms).

Possible values for LightMode tag are:

  • SoftVegetation: Render this pass only if Soft Vegetation is on in Quality Settings.

Possible values for Queue tag are:

  • Background - this render queue is rendered before any others. You’d typically use this for things that really need to be in the background.
  • Geometry (default) - this is used for most objects. Opaque geometry uses this queue.
  • AlphaTest - alpha tested geometry uses this queue. It’s a separate queue from Geometry one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.
  • Transparent - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).
  • Overlay - this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).
  • Possible values for RenderType tag are:

  • Transparent: most semitransparent shaders (Transparent, Particle, Font, terrain additive pass shaders).
  • TransparentCutout: masked transparency shaders (Transparent Cutout, two pass vegetation shaders).
  • Background: Skybox shaders.
  • Overlay: GUITexture, Halo, Flare shaders.
  • TreeOpaque: terrain engine tree bark.
  • TreeTransparentCutout: terrain engine tree leaves.
  • TreeBillboard: terrain engine billboarded trees.
  • Grass: terrain engine grass.
  • GrassBillboard: terrain engine billboarded grass.

DisableBatching tag

True:(always disables batching for this shader) False: (does not disable batching; this is default)  LODFading”:(disable batching when LOD fading is active; mostly used on trees).

ForceNoShadowCasting tag

If ForceNoShadowCasting tag is given and has a value of “True”, then an object that is rendered using this subshader will never cast

shadows. This is mostly useful when you are using shader replacement on transparent objects and you do not wont to inherit a shadow

pass from another subshader.

IgnoreProjector tag

if ignoreProjector tag is given and has a value of “True”, then an object that uses this shader will not be affected by Projectors. This is mostly 

useful on semitransparent objects, because there is no good way for Projectors to affect them.

CanUseSpriteAtlas tag

Set CanUseSpriteAtlas tag to “False” if the shader is meant for sprites, and will not work when they are packed into atlases .

PreviewType tag

PreviewType indicates how the material inspector preview should display the material. By default materials are displayed as 

spheres, but PreviewType can also be set to “Plane” (will display as 2D) or “Skybox” (will display as skybox).

三、測試 1.Cull Back | Front | Off 2.ZWrite On | Off

Controls whether pixels from this object are written to the depth buffer (default is On). If you’re drawng solid objects, leave this on. 

If you’re drawing semitransparent effects, switch to ZWrite Off. For more details read below.

3.ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always

 How should depth testing be performed. Default is LEqual (draw objects in from or at the distance as existing objects; 

hide objects behind them).

4.Offset Factor, Units

Allows you specify a depth offset with two parameters. factor and unitsFactor scales the maximum Z slope, with respect to X or Y of the polygon, 

and units scale the minimum resolvable depth buffer value. This allows you to force one polygon to be drawn on top of another although they are

actually in the same position. For example Offset 0, –1 pulls the polygon closer to the camera ignoring the polygon’s slope, whereas Offset –1, –1 

 will pull the polygon even closer when looking at a grazing angle.

5.Blend

Blend Off;Blend SrcFactor DstFactor;Blend SrcFactor DstFactor, SrcFactorA DstFactorA

One The value of one - use this to let either the source or the destination color come through fully.
Zero The value zero - use this to remove either the source or the destination values.
SrcColor The value of this stage is multiplied by the source color value.
SrcAlpha The value of this stage is multiplied by the source alpha value.
DstColor The value of this stage is multiplied by frame buffer source color value.
DstAlpha The value of this stage is multiplied by frame buffer source alpha value.
OneMinusSrcColor The value of this stage is multiplied by (1 - source color).
OneMinusSrcAlpha The value of this stage is multiplied by (1 - source alpha).
OneMinusDstColor The value of this stage is multiplied by (1 - destination color).
OneMinusDstAlpha The value of this stage is multiplied by (1 - destination alpha).
BlendOp
Add Add source and destination together.
Sub Subtract destination from source.
RevSub Subtract source from destination.
Min Use the smaller of source and destination.
Max Use the larger of source and destination.

6.Stencil

Ref

    Ref referenceValue

The value to be compared against (if Comp is anything else than always) and/or the value to be written to the buffer (if either Pass, Fail or ZFail is set to replace). 0–255 integer.

ReadMask

    ReadMask readMask

An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer (referenceValue & readMaskcomparisonFunction (stencilBufferValue & readMask). Default: 255.

WriteMask

    WriteMask writeMask

An 8 bit mask as an 0–255 integer, used when writing to the buffer. Default: 255.

Comp

    Comp comparisonFunction

The function used to compare the reference value to the current contents of the buffer. Default: always.

Pass

    Pass stencilOperation

What to do with the contents of the buffer if the stencil test (and the depth test) passes. Default: keep.

Fail

    Fail stencilOperation

What to do with the contents of the buffer if the stencil test fails. Default: keep.

ZFail

    ZFail stencilOperation

What to do with the contents of the buffer if the stencil test passes, but the depth test fails. Default: keep.

Comp, Pass, Fail and ZFail will be applied to the front-facing geometry, unless Cull Front is specified, in which case it’s back-facing geometry. You can also explicitly specify the two-sided stencil state by defining CompFront, PassFront, FailFront, ZFailFront (for front-facing geometry), and CompBack, PassBack, FailBack, ZFailBack (for back-facing geometry).

Comparison Function

Comparison function is one of the following:

Greater Only render pixels whose reference value is greater than the value in the buffer.
GEqual Only render pixels whose reference value is greater than or equal to the value in the buffer.
Less Only render pixels whose reference value is less than the value in the buffer.
LEqual Only render pixels whose reference value is less than or equal to the value in the buffer.
Equal Only render pixels whose reference value equals the value in the buffer.
NotEqual Only render pixels whose reference value differs from the value in the buffer.
Always Make the stencil test always pass.
Never Make the stencil test always fail.

Stencil Operation

Stencil operation is one of the following:

Keep Keep the current contents of the buffer.
Zero Write 0 into the buffer.
Replace Write the reference value into the buffer.
IncrSat Increment the current value in the buffer. If the value is 255 already, it stays at 255.
DecrSat Decrement the current value in the buffer. If the value is 0 already, it stays at 0.
Invert Negate all the bits.
IncrWrap Increment the current value in the buffer. If the value is 255 already, it becomes 0.
DecrWrap Decrement the current value in the buffer. If the value is 0 already, it becomes 255.
7.AlphaTest

AlphaTest off; AlphaTest comparison AlphaValue;

Greater Only render pixels whose alpha is greater than AlphaValue.
GEqual Only render pixels whose alpha is greater than or equal to AlphaValue.
Less Only render pixels whose alpha value is less than AlphaValue.
LEqual Only render pixels whose alpha value is less than or equal to from AlphaValue.
Equal Only render pixels whose alpha value equals AlphaValue.
NotEqual Only render pixels whose alpha value differs from AlphaValue.
Always Render all pixels. This is functionally equivalent to AlphaTest Off.
Never Don’t render any pixels.
8.Fog

Mode Off | Global | Linear | Exp | Exp2

Color ColorValue

Density FloatValue

Range FloatValue, FloatValue

四、#pragma

  • #pragma vertex name - compile function name as the vertex shader.
  • #pragma fragment name - compile function name as the fragment shader.
  • #pragma geometry name - compile function name as DX10 geometry shader. Having this option automatically turns on #pragma target 4.0, described below.
  • #pragma hull name - compile function name as DX11 hull shader. Having this option automatically turns on #pragma target 5.0, described below.
  • #pragma domain name - compile function name as DX11 domain shader. Having this option automatically turns on #pragma target 5.0, described below.

Other compilation directives:

  • #pragma target name - which shader target to compile to. See Shader targets below for details.
  • #pragma only_renderers space separated names - compile shader only for given renderers. By default shaders are compiled for all renderers. See Renderers below for details.
  • #pragma exclude_renderers space separated names - do not compile shader for given renderers. By default shaders are compiled for all renderers. See Renderers below for details.
  • #pragma multi_compile …_ - for working with multiple shader variants.
  • #pragma enable_d3d11_debug_symbols - generate debug information for shaders compiled for DirectX 11, this will allow you to debug shaders via Visual Studio 2012 (or higher) Graphics debugger.
5.Built-in shader variables
Name Value
UNITY_MATRIX_MVP Current model * view * projection matrix.
UNITY_MATRIX_MV Current model * view matrix.
UNITY_MATRIX_V Current view matrix.
UNITY_MATRIX_P Current projection matrix.
UNITY_MATRIX_VP Current view * projection matrix.
UNITY_MATRIX_T_MV Transpose of model * view matrix.
UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix.
_Object2World Current model matrix.
_World2Object Inverse of current world matrix.
Name Type Value
_WorldSpaceCameraPos float3 World space position of the camera.
_ProjectionParams float4 x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane.
_ScreenParams float4 x is the camera’s render target width in pixels, y is the camera’s render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.
_ZBufferParams float4 Used to linearize Z buffer values. x is (1-far/near), yis (far/near), z is (x/far) and w is (y/far).
unity_OrthoParams float4 x is orthographic camera’s width, y is orthographic camera’s height, z is unused and w is 1.0 when camera is orthographic, 0.0 when perspective.
unity_CameraProjection float4x4 Camera’s projection matrix.
unity_CameraInvProjection float4x4 Inverse of camera’s projection matrix.
unity_CameraWorldClipPlanes[6] float4 Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.
Name Type Value
_Time float4 Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders.
_SinTime float4 Sine of time: (t/8, t/4, t/2, t).
_CosTime float4 Cosine of time: (t/8, t/4, t/2, t).
unity_DeltaTime float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).

Forward rendering (ForwardBase and ForwardAdd pass types):

Name Type Value
_LightColor0 (declared in Lighting.cginc) fixed4 Light color.
_WorldSpaceLightPos0 float4 Directional lights: (world space direction, 0). Other lights: (world space position, 1).
_LightMatrix0 (declared in AutoLight.cginc) float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase pass only) world space positions of first four non-important point lights.
unity_4LightAtten0 float4 (ForwardBase pass only) attenuation factors of first four non-important point lights.
unity_LightColor half4[4] (ForwardBase pass only) colors of of first four non-important point lights.

Deferred shading and deferred lighting, used in the lighting pass shader (all declared in UnityDeferredLibrary.cginc):

Name Type Value
_LightColor float4 Light color.
_LightMatrix0 float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.

LOD

  • VertexLit kind of shaders = 100
  • Decal, Reflective VertexLit = 150
  • Diffuse = 200
  • Diffuse Detail, Reflective Bumped Unlit, Reflective Bumped VertexLit = 250
  • Bumped, Specular = 300
  • Bumped Specular = 400
  • Parallax = 500
  • Parallax Specular = 600

相關推薦

圖形處理Unity3DShaderVertex and Fragment Shader

一、Properties _MyColor ("Some Color", Color) = (1,1,1,1) _MyVector ("Some Vector", Vector) = (0,0,0,0) _MyFloat ("My float", Float) = 0.

Linux文本處理三劍客awk

awk變量 信息 tro 不同 當前 block 文件中 是否 定義變量   AWK是一個優良的文本處理工具,Linux及Unix環境中現有的功能最強大的數據處理引擎之一。其名稱得自於它的創始人阿爾佛雷德·艾侯、彼得·溫伯格和布萊恩·柯林漢姓氏的首個字母

SpringMVC_9_ 處理模型資料ModelAndView、Map、@SessionAttributes

SpringMVC提供了以下幾種途徑輸出模型資料: ModelAndView:處理方法返回值型別為ModelAndView時,方法體即可通過該物件新增模型資料 Map 及 Model:入參為org.springframework.ui.Model、org.springfra

JavaWebDBUtilsQueryRunner類對資料表的增、刪、查8種結果集處理方式、改操作

一、使用QueryRunner類,實現對資料表的 insert delete update  package com.shuhuadream.queryrunner; import java.sql.Connection; import java.sql.SQLExce

星際

輸出 detail return 技術 gin ace problem pau ans 星際之門(一) 時間限制:3000 ms | 內存限制:65535 KB 難度:3 描寫敘述 公元3000年。子虛帝國統領著N個星系,

spring註解概述

dsm 的人 src article service 優缺點 中一 auto 數據 Spring的核心是依賴註入(DI),而依賴註入的基礎是依賴信息的配置。這些配置稱之為元數據。在之前的的學習中。一直採用的是基於xml的配置,這些元數據配置在spring內部被註冊成為B

css重構

rdquo lan set 變化 部分 網站 一個 寬度 lang css重構之旅 >前言: 今年我大一,馬上就要大二了。從高三畢業暑假到大學的這一年馬上過去,馬上迎來大二生活.學習前端也有將近一年了。一昧去追求那些視覺的效果和相對高端和新穎的技術,反而忽略了最基礎

用SQL玩轉數據挖掘MADlib——安裝

system wan 商品 ase 關聯規則挖掘 樹模型 ats 調用 ability   一、MADlib簡介    MADlib是Pivotal公司與伯克利大學合作的一個開源機器學習庫,提供了精確的數據並行實現、統計和機器學習方法對結構化和非結構化數據進行分析,主要目的

Hadoop源碼學習HDFS

-a node bsp ima 數據 layout 版本號 name 技術   Hadoop的HDFS可以分為NameNode與DataNode,NameNode存儲所有DataNode中數據的元數據信息。而DataNode負責存儲真正的數據(數據塊)信息以及數據塊的ID。

前端 —— node.js摸爬打滾

turn lan name resp function oba ack val 括號 安裝: window下的安裝,node.js直接上官網下載:https://nodejs.org/en/ 選擇LTS,也就是版本號比較低的穩定版,下載下來後運行下載的文件進行安裝; 通

我的學習SQL盲註學習篇

網絡安全 dvwa sql盲註 我的學習之路,現在零基礎,是一個小白,請各位大牛批評指正!寫下這篇,是對自己的一個思路的整理,僅供參考。 Dvwa中登錄進入,首先在DVWA Security中設置等級為low,然後進入SQL Injection(blind),隨意輸入一個數字進行抓包,然後找

成長 GridLayout 布局

bsp ren 1.0 androi enc 代碼區 andro XML orien 效果圖 代碼區 <?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="htt

Java面向對象編程繼承

col end 分情況討論 讓我 重要 san 封裝 pub void 前言 Java語言有三大重要的特性,分別是繼承、多態和封裝。今天我們就來聊聊繼承,繼承是復用程序代碼的有力手段,使用繼承我們會少寫許多代碼,也可以讓我們在寫代碼的時候邏輯變得更加清楚。 繼承的基本語法

2017年最新企業面試題shell

2017年最新企業面試題之shell2017年最新企業面試題之shell(一)**********************************************企業Shell面試題1:批量生成隨機字符文件名案例 ********************************************

Mybbatis學習

org unit primary sas oca manage result ava namespace 本例子為采用的mysql+maven+mybatis構建。   初步學習mybatis:     mybatis為一個半自動框架,相對於hibernate來說他更加輕巧

linux下源代碼搭建php環境mysql

運行程序 google chcon 系統環境 ncurses con 軟件 func ets 如今已經大半夜了,五一勞動節挺無聊的。 折騰一下吧。實在是睡不著。於是乎在電腦上安裝個虛擬機,然後呢,在虛擬機上搭建一個php環境。 首先我得安裝MYSQL吧。發現遇到

Hadoop2.6.0版本號MapReudce演示樣例WordCount

set pat -m 代碼 分享 ont extends gravity csdn 一、準備測試數據 1、在本地Linux系統/var/lib/hadoop-hdfs/file/路徑下準備兩個文件file1.txt和file2.tx

nsq源碼閱讀筆記nsqd——nsqd的配置解析和初始化

con views pos 直接 rgba 函數調用 程序 spa 重命名 配置解析nsqd的主函數位於apps/nsqd.go中的main函數首先main函數調用nsqFlagset和Parse進行命令行參數集初始化, 然後判斷version參數是否存在,若存在,則打印版

基礎篇集合List總結

intern ansi [] 集合 add 引用 public log ++ 1. List集合下常用的集合(ArrayList,LinkedList,Vector);   JVM垃圾回收GC,Java中采取了可達性分析法,標記所有從根節點開始的可達對象,未被標記的對象就

Hyperledger Fabric密碼模塊系列BCCSP

服務 編碼轉換 簡單 fabric 實現 支持 模塊 store block Fabric作為IBM主導的區塊鏈平臺,可謂是聯盟鏈中的一枝獨秀,現如今已經有100多個大型國際銀行、金融以及科技公司的加盟。與其說Fabric是區塊鏈的一種平臺,倒不如說是一個區塊鏈框架更