代码中看到后收集的一些shader学习笔记
来源:互联网 发布:淘宝店铺模版怎么使用 编辑:程序博客网 时间:2024/06/03 21:19
ARB_precision_hint_nicest 的意义,作用:
首先,这2命令最权威解释的地方,肯定就是openGl官网了,以下是链接:
https://www.opengl.org/registry/specs/NV/fragment_program4.txt
这里有这么一段:
+ Precision Hints(ARB_precision_hint_fastest, ARB_precision_hint_nicest)
Fragment program computations are carriedout at an implementation- dependent precision. However, some implementationsmay be able to perform fragment program computations at more than oneprecision, and may be able to trade off computation precision for performance.If a fragment program specifies the "ARB_precision_hint_fastest"program option, implementations should select precision to minimize programexecution time, with possibly reduced precision. If a fragment programspecifies the "ARB_precision_hint_nicest" program option,implementations should maximize the precision, with possibly increasedexecution time. Only one precision control option may be specified by any givenfragment program. A fragment program that specifies both the"ARB_precision_hint_fastest" and "ARB_precision_hint_nicest"program options will fail to load.
看标题也知道了,也就是精度提示。
ARB_precision_hint_fastest最快的,意思就是会用低精度(一般是指fp16),以提升片段着色器的运行速度,减少时间。
ARB_precision_hint_nicest最佳的,意思就是会用高精度(一般是指fp32),可能会降低运行速度,增加时间。
注意:这2个命令不可以同时使用
unity里的写法是#pragma fragmentoption ARB_precision_hint_fastest
具体说fp16,fp32是什么的话,就涉及到GPU的知识了,我也不是太懂。
大概说说的话,fp16在gpu里一般被称为半精度计算。
图形计算中使用的精度是:
FP16,16bit,半精度
FX10,10bit,都不是浮点,而是定点数了
FP32,32bit,单精度(最常见的)
FP64,64bit,双精度(不常见的,图像处理一般用不到)
虽然在实际应用中,这2种精度在表现上区别并不大,但是还是建议使用fp16精度的更好。
因为像在 ARM Mali, Imagination PowerVR这种移动GPU上,都有独立的fp16单元,也就是说,fp16是从硬件电路级别上被支持的,我们知道,这就意味着一个字,那就是“快!”,所以你懂的!
不过据说NVIDIA的gpu里,都是用fp32 CUDA核心去处理fp16的。(这其实是比单独的fp16单元要慢的)
总结一下就是在写shader时可以顺手把这个命令给加上,但是如果你忘记了,或者懒,其实问题也不是太大
ARB_precision_hint_fastest
如果有UV移动的地方就用不了,Also depends on what platformthe compiler is targetingsome, like iOS 9+ have no performance difference forhalf precision values // iOS 9+以上没什么性能不同。
fixed and half are the same on iOS, in terms of speed,performance, memory, etc(在性能平台内存方面)
#if UNITY_UV_STARTS_AT_TOP
#if UNITY_UV_STARTS_AT_TOP //判断当前平台是否是DirectX类型
if ( _MainTex_TexelSize.y < 0 ) //判断是否开启抗锯齿
uv.y = 1.0-uv.y;
#endif
#if UNITY_UV_STARTS_AT_TOP用于判断当前平台是否是DirectX类型,当在该平台下开启了抗锯齿(project Setting->Quality->AntiAliasing)后,主纹理的纹素大小在Y方向上会变负值,以便我们对主纹理正确采样。
SV_POSTION和SV_Target
SV_POSTION描述顶点着色器输出的顶点位置,POSITION无法在PS4平台或使用了细分着色器的情况下工作
SV_Target描述片元着色器的输出颜色,COLOR或者COLOR0无法在PS4或使用了细分着色器的情况下工作
https://docs.unity3d.com/Manual/SL-PlatformDifferences.html不同平台区别
fixed(11位) half(16位) float(32位)
· float:32位高精度浮点数。
· half:16位中精度浮点数。范围是[-6万, +6万],能精确到十进制的小数点后3.3位。它适合存储UV坐标等
· fixed:11位低精度浮点数。范围是[-2, 2],精度是1/256。可以用于光照计算存储颜色和单位矢量。
_Time
//_Time是个4维向量,跟Unity3D中的deltaTime(这是个一维的,数值)不同。float4 _Time : Time (t/20, t, t*2, t*3)
waves += sin(_Time.z * _WaveControl.z * 0.666 + _WaveControl.x *worldPos.z * 1.2);
#pragma target 3.0
https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
#pragma target 3.0
· DX9 shader model 3.0: derivativeinstructions, texture LOD sampling, 10 interpolators, more math/textureinstructions allowed.
· Not supported on DX11 feature level 9.xGPUs (e.g. most Windows Phone devices).
· Might not be fully supported by someOpenGL ES 2.0 devices, depending on driver extensions present and featuresused.
Unity 3D ShaderLab开发实战详解 :适合shader中级开发人员
链接:http://pan.baidu.com/s/1jIhLTFg 密码:dkzo
- 代码中看到后收集的一些shader学习笔记
- JS学习中看到的一些好的写法
- 学习Hibernate 收集的一些笔记
- 关于lxc中看到的一些东西,ptmx,blockdev,sigprocmask
- 收集的一些代码
- 一些代码的收集
- [Shader学习笔记]一些向量的几何知识
- 个人收集整理的一些学习shader的网站/博客(不定时更新)
- 网上收集到的一些小脚本代码
- Unity Shader学习笔记:屏幕后处理
- 机器学习过程中看过的一些好文章
- Unity Shader学习笔记:简单的shader
- Python学习过程中看到的好的资料链接
- 学习过程中看到的:常见UI设计模式
- 收集到的一些javascript
- 一些好的代码,收集
- 收集的一些js代码
- 从冒险中看到的
- 关于中值滤波算法,以及C语言实现
- html5实现摇一摇功能
- 分享个JAVA学习路线
- TG2016D1T1&D2T1讲解
- 《Reverse Engineering for Beginners》 - 第1章 代码模式 - 笔记(1.4)
- 代码中看到后收集的一些shader学习笔记
- 正则表达式
- centos7-x86-64卸载自带jdk并安装1.8jdk
- Java Object Serialization Specification
- Spring Bean装配之Resource
- 程序员这样对待简历,你期望面试官怎么对待你?
- Lwip----ECHO Protocol
- android中的三种适配器
- 判断一个字符串中括号是否匹配