当前位置:网站首页>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;
边栏推荐
- DRF defines views and routes
- Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
- JWT certification used in DRF
- Locust performance test 4 (custom load Policy)
- Information Security Experiment 4: implementation of IP packet monitoring program
- What is the rating of Huishang futures company? Is it safe to open an account? I want to open an account, OK?
- [cloud native] Devops (I): introduction to Devops and use of code tool
- C language pointer (Part 2)
- Error: selenium common. exceptions. WebDriverException: Messag‘geckodriver‘ execute
- 二叉树高频题型
猜你喜欢
Using JWT to realize login function
Several stages of PMP preparation study
Confitest of fixture py
Network request process
Jenkins automated email
Interview question: general layout and wiring principles of high-speed PCB
Information Security Experiment 2: using x-scanner scanning tool
What is the use of PMP certificate?
Entity of cesium data visualization (Part 1)
Locust performance test 2 (interface request)
随机推荐
Implementation of corner badge of Youmeng message push
Entity of cesium data visualization (Part 1)
Regularly modify the system time of the computer
DRF defines views and routes
Locust performance test 4 (custom load Policy)
【云原生】DevOps(一):DevOps介绍及Code工具使用
【Istio Network CRD VirtualService、Envoyfilter】
Netease Cloud Wechat applet
2020 year end summary
Common short chain design methods
Difference between interface iterator and iteratable
(3/8) method parameters of improper use of enumeration (2)
How can I apply for a PMP certificate?
Several stages of PMP preparation study
Yapi test plug-in -- cross request
Data association between two interfaces of postman
網易雲微信小程序
What are the conditions for applying for NPDP?
Chaosblade: introduction to chaos Engineering (I)
How to use Arthas to view class variable values