当前位置:网站首页>Unity custom sky ball model to prevent it from being cropped
Unity custom sky ball model to prevent it from being cropped
2022-07-19 08:11:00 【It's not too late webgl】
stay unity in , Sometimes I don't want to use the built-in sky ball to render , that , We will use a sphere to render the sky ball . In order to ensure that the game scene models are placed in the sky ball . The sphere will enlarge greatly , So here's the problem , This will cause the sphere to be out of the camera's visual range , The sky ball cannot be rendered , Adjust the cut far side of the camera , Will affect performance , It also affects the rendering effect .
Here's a solution , That is, we can modify the cutting coordinates of the vertex shader output of the sphere in the material , Limit its value to -1 To 1 Within the scope of , To solve the problem that cannot be rendered .
This is a base unlit Modified sky ball to prevent being cropped 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);
// The output position will be z Coordinates are limited to -1 To 1 Within the scope of , This can prevent the customized sky ball from being cut out
#if UNITY_REVERSED_Z // This macro is used to judge the platform , The farthest clipping value of a platform is 1, There are plenty of them -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
}
}
}
边栏推荐
- redis缓存雪崩、穿透、击穿
- Redis message subscription
- STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
- 剑指 Offer 42. 连续子数组的最大和-动态规划法
- Pytoch notes (1)
- Local storage sessionstorage
- RNN convolutional neural network
- Conversation technology [dark horse introduction series]
- Convolutional neural network CNN
- History and value of forked coins | eth, BCH, BSV 2020-03-08
猜你喜欢

串口通讯到底有没有累积误差及对时钟精度的要求

Will it be a little late to realize your "wonderful" 360?

会话技术【黑马入门系列】

Yolov5 label and establish your own data set
[characteristic Engineering]

Redis jump table implementation principle & time complexity analysis

Code learning (deamnet) CVPR | adaptive consistency prior based deep network for image learning

FMC sub card: 4-way sfp+ 10 Gigabit optical fiber network FMC sub card

2022 review questions and mock exams for main principals of hazardous chemical business units

redis消息订阅
随机推荐
Titanic passenger rescue prediction (Advanced)
175. Combine two tables (MySQL database connection)
OI回忆录
812. 最大三角形面积
数组习题三
standard-version(发版与 Changelog 自动化)
V8 引擎如何进行垃圾内存的回收?
the max_ iter was reached which means the coef_ did not converge “the coef_ did not converge“
深圳保诚笔试记录
聊聊分布式锁
CCF-CSP《202206-2—寻宝!大冒险!》
在VSCode中设置settings.json
From the casino logic, analyze the investment value of platform currency 2020-03-03
[day01] preface, introductory program, constant variables
The connection between neural network and automatic control
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
Ccf-csp "202206-2 - treasure hunt! Adventure!"
Go language Bible
How did "leek" give money to "sickle"? 2020-03-07
redis6新功能