当前位置:网站首页>unity urp 渲染管线顶点偏移的实现
unity urp 渲染管线顶点偏移的实现
2022-08-05 07:27:00 【暮志未晚Webgl】
这里我是通过法线对顶点进行偏移
如果面与面之间的点不是公用的,会出现屏幕中立方体的效果,球则没有这个问题。所以使用顶点偏移的时候需要注意一下。
我实现的是在模型空间进行顶点偏移,大家按自己的需求实现
接下来,代码:
Shader "URP/VertexOffset"
{
Properties
{
[MainTexture] _BaseMap ("Albedo", 2D) = "white" {
}
[MainColor] _BaseColor ("Color", Color) = (1, 1, 1, 1)
_Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_VertexOffset ("顶点偏移", Float) = 0
_Cull ("Cull", Int) = 2
}
SubShader
{
Tags {
"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" "ShaderModel" = "4.5" }
LOD 300
// ------------------------------------------------------------------
// Forward pass. Shades all light in a single pass. GI + emission + Fog
Pass
{
Tags {
"LightMode" = "UniversalForward" }
Cull[_Cull]
HLSLPROGRAM
#pragma exclude_renderers gles gles3 glcore
#pragma target 4.5
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
//需要光照系统时增加此引入
// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
half4 _BaseMap_ST;
half _Cutoff;
half4 _BaseMap_ST;
CBUFFER_END
// Used in Standard (Physically Based) shader
Varyings LitPassVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
//通过法向偏移顶点
half3 positionOS = input.positionOS;
positionOS += input.normalOS * _VertexOffset;
output.positionCS = TransformObjectToHClip(positionOS);
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
return output;
}
half4 LitPassFragment(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
//---------------输入数据-----------------
float2 UV = input.uv;
half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
clip(color.r - _Cutoff);
return color;
}
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
}
边栏推荐
猜你喜欢
线程池的创建及参数设置详解
400 times performance improvement 丨 swap valuation optimization case calculation
餐饮大单品「真香」,却没有穿透周期的能力
【 LeetCode 】 235. A binary search tree in recent common ancestor
Put Cloudflare on the website (take Tencent Cloud as an example)
七夕?编程?
在anaconda Promat界面import torch通过,在jupyter notebook中报错的问题(仅提供思路理解!)
爬虫之验证码
Hash 这些知识你也应该知道
Shiny02---Shiny异常解决
随机推荐
风控特征的优化分箱,看看这样教科书的操作
400 times performance improvement 丨 swap valuation optimization case calculation
2022 crane driver (limited bridge crane) exam question bank and simulation test
字符串提取 中文、英文、数字
C# FileSystemWatcher
AI+视频技术助力保障校园安全,校园智能安防平台该如何建设?
Mysql为什么 建立数据库失败
An IP conflict is reported after installing the software on a dedicated computer terminal
Hash 这些知识你也应该知道
MobileNetV2架构解析
Win10 设置锁屏壁纸提示尝试其它图片
busybox 知:构建
Shiny04---Application of DT and progress bar in shiny
Vulnhub靶机:HA_ NARAK
Task flow scheduling tool AirFlow,, 220804,,
cmake 学习使用笔记(三)
配合屏幕录像专家,又小又清晰!
MySQL:连接查询 | 内连接,外连接
Flink Learning 11: Flink Program Parallelism
栈与队列的基本介绍和创建、销毁、出入、计算元素数量、查看元素等功能的c语言实现,以及栈的压入、弹出序列判断,栈结构的链式表示与实现