当前位置:网站首页>Unity shader (data type in cghlsl)
Unity shader (data type in cghlsl)
2022-07-07 09:25:00 【heater404】
Unity Shader(Cg/HLSL Data types in )
stay Shader in , We are Properties The variables defined in are for display in the material panel and convenient for us to adjust , If you want to in Cg/HLSL If it is used in, it must be declared again ( The naming is required to be consistent ).
Cg/HLSL Data types in
- float
High precision type ,32 position , Usually used for positions in world coordinates , texture UV, Or scalar computation involving complex functions , Like trigonometric functions 、 Power operation, etc .
- half
Medium precision type ,16 position , The range of values is [-60000,+60000], Usually used for location in local coordinates 、 The direction of the vector 、HDR Color, etc. .
- fixed
Low precision type ,11 position , The range of values is [-2,+2], Usually used for regular colors and maps , And some operational variables between low precision .
stay PC The platform doesn't care about you Shader It says half still fixed, All will be regarded as float To deal with it .half And fixed Only effective on some mobile devices .
A common rule is , In addition to position and coordinates float outside , All the rest are used half. The main reason is also because most modern GPU Only support 32 Bit and 16 position , That is to say, only support float and half, I won't support it fixed.
- interger
Integer type , Usually used for loop and array indexing .
stay Direct3D 9 and OpenGL ES 2.0 On the platform, integer may be directly processed with floating-point numbers , stay Direct3D 11、OpenGL ES 3 Etc GPU Can be handled correctly with integer type .
- sampler2D、sampler3D And samplerCUBE
texture , By default, textures on mobile platforms will be automatically converted to low precision texture types , If you need medium precision or high precision, you need to declare it in the following way :
sampler2D_half( Medium precision 2D texture )
sampler2D*_*float( High precision 2D texture )
sampler3D_half( Medium precision 3D texture )
sampler3D*_*float( High precision 3D texture )
samplerCUBE_halft( Medium precision cube texture )
samplerCUBE_float( High precision cube texture )
Corresponding types
So in Properties And Cg/HLSL How does the in correspond ?
- Int/float/Range Expressed in floating-point values , That is to say float、half perhaps fixed, Define according to the accuracy you need .
- Vector/Color use float4、half4 perhaps fixed4 Express .
- 2D Type use sampler2D Express .
- 3D type sampler3D Express .
- CUBE Type use samplerCUBE Express .
It doesn't matter Vector still Color, Are composed of four floating-point values with the same accuracy , So when we define it, we write float4、half4 perhaps fixed4.
such as , We are Properties The following colors are declared in :
_Color("Color", Color) = (1,1,1,1)
stay Cg/HLSL We need to make the same statement again :
fixed4 _Color;
边栏推荐
- STM32 and motor development (from stand-alone version to Networking)
- Full link voltage test of the e-commerce campaign Guide
- What is the use of PMP certificate?
- Over 100000 words_ Ultra detailed SSM integration practice_ Manually implement permission management
- What are the suggestions for PMP candidates?
- Jenkins+ant+jmeter use
- Several stages of PMP preparation study
- Cesium load vector data
- Do you have any certificates with high gold content?
- C language pointer (Part 2)
猜你喜欢
Storage of data in memory
Where is the answer? action config/Interceptor/class/servlet
Pycharm create a new file and add author information
Selenium mouse sliding operation event
十二、排序
Difference between interface iterator and iteratable
华为HCIP-DATACOM-Core_03day
Information Security Experiment 4: implementation of IP packet monitoring program
How to pass the PMP Exam in a short time?
NATAPP内网穿透
随机推荐
Colorbar of using vertexehelper to customize controls (II)
How to speed up video playback in browser
Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]
5A summary: seven stages of PMP learning
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
MySql数据库-索引-学习笔记
Summary of PMP learning materials
Several stages of PMP preparation study
Variable parameter of variable length function
How to pass the PMP Exam in a short time?
**grafana安装**
Interface test API case, data and interface separation
Jenkins task grouping
Record of structured interview
答案在哪里?action config/Interceptor/class/servlet
Zen - batch import test cases
stm32和电机开发(从单机版到网络化)
信息安全实验三 :PGP邮件加密软件的使用
Original collection of hardware bear (updated on May 2022)
[chaosblade: node CPU load, node network delay, node network packet loss, node domain name access exception]