代码中看到后收集的一些shader学习笔记
2016-12-03 09:01
549 查看
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
相关文章推荐
- 编程珠玑学习笔记 Aha算法 思考以及一些代码实现
- 【JQuery学习总结1 】 一些实用的JQuery代码片段收集(筛选,搜索,样式,清除默认值,多选等)
- 代码学习以及一些在线编辑器链接收集
- Unity Shader 学习笔记 (一) 创建Shader自带代码解读
- 【一些网站的收集】包含机器学习深度学习大牛主页等、 牛人主页(主页有很多论文代码)【真的好强大】
- wss3 sdk学习笔记三:一些常用代码
- 个人收集整理的一些学习shader的网站/博客(不定时更新)
- [Shader学习笔记]一些向量的几何知识
- jQuery学习笔记(七)JS 一些基本操作代码整理
- 【一些网站的收集】包含机器学习深度学习大牛主页等、 牛人主页(主页有很多论文代码)【真的好强大】
- 学习Hibernate 收集的一些笔记
- 学习Unity3d Shader笔记:用到的一些对象和关键字纪录
- 学习delphi过程中收集的一些功能代码(整理中)
- MyGeneration学习笔记(3) : dOOdads及生成代码的一些bug
- 一些关于广告管理系统的代码收集
- 学习javascript点滴总结,包括一些常用代码1
- [笔记]3.软件代码中的BUG问题的一些记录
- 学习初期写的一些代码,请勿见笑
- UML学习笔记(二):复习面向对象的一些基本概念
- 我的一些学习笔记