当前位置:网站首页>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
}
}
}
边栏推荐
- STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
- redis集群
- CAD fill to polyline script
- 本地存储 sessionStorage
- Modify checkbox style
- the max_ iter was reached which means the coef_ did not converge “the coef_ did not converge“
- Shenzhen Prudential written examination record
- Precautions for MySQL statements
- 并发编程的核心问题
- KingbaseES 中可以通过构造一个聚集函数来实现mysql的any_value功能。
猜你喜欢

From the casino logic, analyze the investment value of platform currency 2020-03-03

【flask入门系列】异常处理

How to choose the right model

YOLOV5-打标签建立自己的数据集

Understand LSTM and Gru

STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏

DP dynamic planning enterprise level template analysis (Digital triangle, rising sequence, knapsack, state machine, compressed DP)

Xilinx ultrascale+ MPSoC (zu9eg/zu15eg) high performance PCIe data preprocessing board

RNN convolutional neural network

美联储降息,为何长期利好数字货币市场? 2020-03-05
随机推荐
【刷题篇】完全平方数
[C# Console]-C# 控制臺類
【flask入门系列】异常处理
Redis storage structure principle 2
在线问题反馈模块实战(五):实现对通用字段内容自动填充功能
[MySQL] transaction: basic knowledge of transaction, implementation principle of MySQL transaction, detailed explanation of transaction log redolog & undo
行为型模式之策略模式
剑指 Offer 42. 连续子数组的最大和-动态规划法
[C classes and objects] - Methods and class and object programming in C
[MySQL] mvcc: correctly understand mvcc and its implementation principle
mySQL 2502 2503错误
Array exercise 3
Junit5
History and value of forked coins | eth, BCH, BSV 2020-03-08
网站漏洞修复服务商分析可控参数带来的越权
[characteristic Engineering]
没那么大的组合数
openvino机器学习初体验
[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine
Modify the select style