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"
}
相关推荐
CreasyChan4 小时前
C# 反射详解
开发语言·前端·windows·unity·c#·游戏开发
IMPYLH6 小时前
Lua 的 Coroutine(协程)模块
开发语言·笔记·后端·中间件·游戏引擎·lua
世洋Blog16 小时前
SiYangUnityEventSystem,一个Unity中的事件系统
观察者模式·unity·c#·游戏引擎·事件系统
呆呆敲代码的小Y16 小时前
【Unity实战篇】| 游戏滑动框添加特殊效果,如实时高亮显示、曲线滑动等
游戏·unity·游戏引擎·实战·u3d·免费游戏·unity实战技巧
Tatalaluola17 小时前
【Quest开发】用unity UI快速实现交互
unity·游戏引擎
技术小甜甜17 小时前
[Godot] 在 Godot 3.1 中配置 ADB 可执行文件的实用指南
游戏·adb·游戏引擎·godot
技术小甜甜17 小时前
【Godot】【入门】Godot 是什么?适合做哪些类型的游戏(附路线图+避坑清单)
游戏·游戏引擎·godot
码界奇点17 小时前
Unity WebGL输入支持终极指南解决浏览器输入难题的完整方案
unity·容器·游戏引擎·鸿蒙系统·webgl
90后小陈老师18 小时前
Unity动画控制
unity·游戏引擎
Miss_SQ1 天前
Webgl打包后删除StreamingAssets文件夹下多余资源
unity·c#·webgl