shader入門15 完整的光照處理

2021-09-24 13:33:12 字數 1685 閱讀 2243

我們已經學習了所有相關的光照處理,嘗試用前幾篇的光照處理組合出乙個標準的光照著色器.

漫反射使用了蘭伯特光照模型

高光反射使用blinn-phong模型

法線紋理是在切線空間計算的

新增了多光照處理,光照衰減,陰影

shader "unity/custom/newsu***ceshader" //貼圖

_bumptex("normalmap", 2d) = "white" {}//法線紋理

_bumpscale("bumpscale",range(0,200)) = 10//凹凸係數

_sepcular("_sepcular",color) = (1,1,1,1)//高光反射顏色

_gloss("_gloss",range(0,100)) = 1//光澤度

} subshader//不透明物體渲染佇列

pass

cgprogram

#pragma multi_compile_fwdbase

#pragma vertex vert

#pragma fragment frag

#include "lighting.cginc"

#include "autolight.cginc"

fixed4 _texcolor;

sampler2d _maintex;

float4 _maintex_st;//縮放與偏移

sampler2d _bumptex;

float4 _bumptex_st;

float _bumpscale;

fixed4 _sepcular;//高光反射顏色

fixed _gloss;//光澤度

struct a2v ;

struct v2f ;

v2f vert(a2v v)

fixed4 frag(v2f f) : sv_target

endcg

} pass

blend one one//希望多光源混合 而不是覆蓋

cgprogram

#pragma multi_compile_fwdadd

#pragma vertex vert

#pragma fragment frag

#include "lighting.cginc"

#include "autolight.cginc"

fixed4 _texcolor;

sampler2d _maintex;

float4 _maintex_st;//縮放與偏移

sampler2d _bumptex;

float4 _bumptex_st;

float _bumpscale;

fixed4 _sepcular;//高光反射顏色

fixed _gloss;//光澤度

struct a2v ;

struct v2f ;

v2f vert(a2v v)

fixed4 frag(v2f f) : sv_target

endcg

} }fallback "diffuse"

}

為了測試其他的光照效果,關閉了平行光,僅使用點光源

shader入門精要讀書筆記11 基礎光照模型

渲染包含了兩大部分 1.決定乙個畫素的可見性 2.決定這個畫素上的光照計算 一 光照模型背後的基本原理 1.光源 在光學中,我們用 輻照度 來量化光 確定乙個光源發出了多少光 光方向為l,光線間距為d 垂直照射時,物體表面光線間距d,垂直時 為0,也可以表示為d cos 斜著照射時,物體表面光線間距...

Phong光照模型的Shader實現

phong用到的是反射向量,計算反射向量的公式是 r 2 n dot n,l l 這個公式是根據向量的投影公式以及平行四邊形法則推導出來的 詳細步驟請看這篇文章,講的非常好 shader phong specular specular range 1,20 1 speccolor speccolor...

Unity全域性光照以及shader的使用方法

unity自帶的shader都是支援光照貼圖的,光照貼圖可以讓unity中的模型在沒有光照的情況下,在物體上產生陰影效果。5.0以後光照貼圖的形式都有一定的改變。而在自己寫的shader中需要對光照貼圖進行相應的設定。光照貼圖準備工作 1.light中baking的模式選為baked,為了檢視效果,...