Unity图形学之法线贴图原理

1.正常贴图:RGBA 4通道 每个通道取值范围 0-255 贴图里面取值是 0-1

2.法线贴图:法线怎么存入正常贴图的过程

cs 复制代码
每个通道里面存储的是一个向量(x,y,z,w) 通常我们会对应xyzw为rgba 存储值的范围也是0-1


向量的取值范围是 -1到1

法线怎么存入正常贴图的过程:法线中的向量取值范围怎么变换为0-1: (-1,1) *0.5 +0.5 ==(0,1)

正常贴图变成法线的过程:(0,1) -0.5 *2 == (-1,1)

3.法线贴图为蓝色:是因为法线经常是朝向Z轴的,法线倾向 Z值 ,Z值映射到贴图里面,对应的是RGBA中的B值,所以呈现蓝色

4.法线贴图从哪里来?

cs 复制代码
1.美术制作
2.U3D里设置 图片类型为 Normal Map

5.法线贴图的作用?

cs 复制代码
1.增加明暗对比度,让凸出的地方看起来更凸

法线计算:

cs 复制代码
Shader "Custom/NormalMap"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _NorTex ("NormalMap (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all  light types
        #pragma surface surf Lambert
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0
        sampler2D _MainTex;
        sampler2D _NorTex;
        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NorTex;
        };
        fixed4 _Color;
        void surf (Input IN, inout SurfaceOutput o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Normal = UnpackNormal(tex2D (_NorTex, IN.uv_MainTex));
            o.Albedo = c.rgb;
            
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
相关推荐
ccloud113 小时前
OpenGL实现场景编辑器
qt·游戏引擎
Octopus20774 小时前
【Godot】实现对话系统
游戏引擎·godot·游戏程序
君莫愁。17 小时前
【Unity】搭建基于字典(Dictionary)和泛型列表(List)的音频系统
数据结构·unity·c#·游戏引擎·音频
唐小墨同学1 天前
Pico 4 Enterprise(企业版)与Unity的交互-打包运行及UI交互篇
ui·unity
虾球xz1 天前
游戏引擎学习第143天
学习·游戏引擎
红黑色的圣西罗1 天前
Unity UGUI下优化需要射线检测类的UI元素的一种方式
unity·游戏引擎
Thomas_YXQ1 天前
Unity3D 图形渲染(Graphics & Rendering)详解
开发语言·unity·图形渲染·unity3d·shader
虾球xz1 天前
游戏引擎学习第145天
学习·游戏引擎
虾球xz1 天前
游戏引擎学习第144天
学习·游戏引擎
虾球xz2 天前
游戏引擎学习第139天
linux·学习·游戏引擎