当前位置:网站首页>unity 自定义天空球模型防止被裁剪
unity 自定义天空球模型防止被裁剪
2022-07-17 06:53:00 【暮志未晚Webgl】
在unity中,有时候不想使用内置的天空球去渲染,那么,我们就会使用一个球体去渲染天空球。为了保证游戏场景模型都放置在天空球内。球体就会放大的很大,那么问题就来了,这样会导致球体超出了相机的可视范围,导致天空球无法渲染,调整相机的裁减远面,会影响性能,还影响渲染效果。
这里有个解决方案,就是我们可以在材质里面去修改球体的顶点着色器输出的裁减坐标,将它的值限制在-1到1的范围内,来解决无法被渲染的问题。
这是一个基于unlit修改的防止被裁剪的天空球shader
Shader "Unlit/SkyBox"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {
}
}
SubShader
{
Tags {
"RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
//将输出位置的z坐标限制在-1到1的范围内,这样可以防止自定义的天空球被裁剪掉
#if UNITY_REVERSED_Z //这个宏是用来判断平台的,有个平台最远裁剪值是1,有的是-1
o.vertex.z = o.vertex.w * 0.000001f;
#else
o.vertex.z = o.vertex.w * 0.999999f;
#endif
return o;
}
half4 frag(v2f i) : SV_Target
{
// sample the texture
half4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
边栏推荐
- 【刷题篇】完全平方数
- Ku115 FPGA high performance 10G Optical fiber network hardware accelerator card / 2-way 10G Optical fiber data accelerator card
- Redis message subscription
- 写代码遇到Qt相关问题
- Modify checkbox style
- 剑指 Offer 42. 连续子数组的最大和-动态规划法
- Double index mechanism of redis source code analysis
- [MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine
- Conversation technology [dark horse introduction series]
- redis数据持久化
猜你喜欢

【MySQL】 锁机制:InnoDB引擎中锁分类以及表锁、行锁、页锁详解

“韭菜”是怎么把钱送给“镰刀”的? 2020-03-07
![[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine](/img/7e/ddf05e76da26e9b2d1fd1519703571.png)
[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine

By voting for the destruction of STI by Dao, seektiger is truly community driven

RISC-V技術雜談

并发编程的核心问题

从赌场逻辑,分析平台币的投资价值 2020-03-03

redis主从复制

Junit5
![[C language] user defined type details: structure, enumeration, union](/img/5c/69d238a71e24b34c2232c20ed7e09e.png)
[C language] user defined type details: structure, enumeration, union
随机推荐
Wechat oauth2.0 login process and security analysis
Pytorch notes (5)
[C# Console]-C# 控制台类
What if the user information in the website app database is leaked and tampered with
Shenzhen Prudential written examination record
[C# Console]-C# 控制臺類
Facial key point detection CNN
The connection between neural network and automatic control
Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],
[JVM] heap memory, escape analysis, on stack allocation, synchronous omission, scalar replacement details
会话技术【黑马入门系列】
[C # variable constant keyword] - variable constants and keywords in C #
Ruffian Heng embedded bimonthly issue 58
standard-version(发版与 Changelog 自动化)
Modify checkbox style
网站漏洞修复服务商分析可控参数带来的越权
在线问题反馈模块实战(五):实现对通用字段内容自动填充功能
Redis 跳跃表实现原理 & 时间复杂度分析
If a number in C language is exactly equal to the sum of its factors, this number is called "perfect". For example, 6=1 + 2 + 3 programming
Mongodb index