IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> Unity SRP初识之URP -> 正文阅读

[游戏开发]Unity SRP初识之URP

URP是Unity基于SRP提供的兼顾表现与性能的渲染管线。URP前身命名为LWRP(轻量级渲染管线),后更名为URP。

URP已包含在新建工程的工程模板中

  • URP使用简化的基于物理的照明和材质来实现高质量的快速渲染。
  • URP使用单遍正向渲染,以在多个平台上优化实时性能

官方配置说明文档:

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/universalrp-asset.html

BaseCamera与Overlay相机

  • URP支持两种RenderType不同的相机类型:Base与Overlay
  • Overlay相机渲染在Base相机在上,用于实现UI上的3D显示
  • Overlay相机必须加到BaseCamera上的Stack上,才能生效
  • Overlay相机不能应用post-processing

Post-processing

  • UPR实现了自己的后处理:Volume组件
  • 手机友好的后处理
    • Bloom (with High Quality Filtering disabled)
    • Chromatic Aberration 色差
    • Color Grading
    • Lens Distortion 镜头失真
    • Vignette 插图
  • 景深:
    • 在低端机上使用高斯景深( Gaussian Depth of Field)
    • 在桌面平台使用散景景深(Bokeh Depth of Field)
  • 抗锯齿:建议使用FXAA

Shader与材质球

官方文档

  • URP使用与内置渲染管线不一致的着色方法,因此内置光照与自定义光照着色器(Lit Shader)不能在URP中使用。URP有自己一套Lit Shader。
  • 内置管线的Unlit Shader(非光照Shader)仍然可以在URP中使用
  • 可以在所有平台使用URP的Lit Shader。Lit Shader基于PBR。在URP中,Standard Shader和Standard (Specular setup) Shaders 会被指向URP的Lit Shader
  • 非PBR可以使用Simple Lit shader,
  • 不需要实时光照,可以使用Baked Lit Shader

// This shader draws a texture?on?the mesh.

Shader?"Example/URPUnlitShaderTexture"

{

????// The _BaseMap variable is visible in the Material's Inspector,?as a field

????// called Base Map.

????Properties

????{

????????_BaseMap("Base Map",?2D) =?"white"

????}

????SubShader

????{

????????Tags?{?"RenderType"?=?"Opaque"?"RenderPipeline"?=?"UniversalPipeline"?}

????????Pass

????????{

????????????HLSLPROGRAM

????????????#pragma vertex vert

????????????#pragma fragment frag

????????????#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"???????????

????????????struct Attributes

????????????{

????????????????float4 positionOS???:?POSITION;

????????????????// The uv variable contains the UV coordinate?on?the texture for the

????????????????// given vertex.

????????????????float2 uv???????????:?TEXCOORD0;

????????????};

????????????struct Varyings

????????????{

????????????????float4 positionHCS??:?SV_POSITION;

????????????????// The uv variable contains the UV coordinate?on?the texture for the

????????????????// given vertex.

????????????????float2 uv???????????:?TEXCOORD0;

????????????};

????????????// This macro declares _BaseMap as a Texture2D object.

????????????TEXTURE2D(_BaseMap);

????????????// This macro declares the sampler for the _BaseMap texture.

????????????SAMPLER(sampler_BaseMap);

????????????CBUFFER_START(UnityPerMaterial)

????????????????// The following line declares the _BaseMap_ST variable,?so that you

????????????????// can use the _BaseMap variable in the fragment shader. The _ST

????????????????// suffix is necessary for the tiling and offset function to work.

????????????????float4 _BaseMap_ST;

????????????CBUFFER_END

????????????Varyings vert(Attributes IN)

????????????{

????????????????Varyings OUT;

????????????????OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);

????????????????// The TRANSFORM_TEX macro performs the tiling and offset

????????????????// transformation.

????????????????OUT.uv = TRANSFORM_TEX(IN.uv,?_BaseMap);

????????????????return OUT;

????????????}

????????????half4 frag(Varyings IN)?:?SV_Target

????????????{

????????????????// The SAMPLE_TEXTURE2D marco samples the texture with the given

????????????????// sampler.

????????????????half4 color = SAMPLE_TEXTURE2D(_BaseMap,?sampler_BaseMap,?IN.uv);

????????????????return color;

????????????}

????????????ENDHLSL

????????}

????}

}

  • 需要额外声明TextureObj

TEXTURE2D(_BaseMap);

  • 贴图采样器的声明

SAMPLER(sampler_BaseMap);

  • CBUFFER

CBUFFER_START(UnityPerMaterial)

????// The following line declares the _BaseMap_ST variable,?so that you

????// can use the _BaseMap variable in the fragment shader. The _ST

????// suffix is necessary for the tiling and offset function to work.

????float4 _BaseMap_ST;

CBUFFER_END

  • 顶点函数中物体空间到裁剪空间的转换

OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);

  • UV的计算

OUT.uv = TRANSFORM_TEX(IN.uv,?_BaseMap);

  • 贴图采样

half4 color = SAMPLE_TEXTURE2D(_BaseMap,?sampler_BaseMap,?IN.uv);

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2021-08-26 12:27:12  更:2021-08-26 12:27:20 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/3 13:04:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码