UnityShader源码2017---学习笔记与自我拓展048

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012871784/article/details/81737639

源自Sprites-Default,Sprites-Diffuse,Sprites-Mask

先说一下Properties里的一些特殊的toy

[PerRendererData]

先来看一下文档里的说明

简单的翻译一下,从MaterialPropertyBlock里而不是冲material里查询texture属性。于此操作对应的就是要在shader里的这个属性前添加[PerRendererData]。

简单的猜测一下,这里说的到了queries,查询的时间影响的是效率,也就是说这个或许会有些许效率的提升

[PerRendererData] 
- indicates that a texture property will be coming 
from per-renderer data in the form of a MaterialPropertyBlock. 
Material inspector changes the texture slot UI for these properties.

上面这个也是帮助文档里的,大体意思就是Block上的,以及UI的material更新Inspector的曹里的图片显示,因为一般的ui都是用图集的,如果没有这个标识,ui曹里的显示可能会有不一样的地方,but ,whatever。。。

我继续搜一些资料。

这个大哥说,如果没有PerRendererData,SetPropertyBlock也会起作用的,只不过unitiy会偷偷地给你创建一个实例。。

----------------------------------------------------------------------------------------------------------------------------------------------

自己做了一点拓展https://github.com/CorsairProhell/ShaderGUI_Ex-/tree/master/V3.0

----------------------------------------------------------------------------------------------------------------------------------------------

先来看一下Sprites-Default

属性中的PixelSnap的作用就是让图片的像素与屏幕的像素对应起来。

看一下UnityCG里的UnityPixelSnap方法

// snaps post-transformed position to screen pixels
inline float4 UnityPixelSnap (float4 pos)
{
    float2 hpc = _ScreenParams.xy * 0.5f;
    float2 pixelPos = round ((pos.xy / pos.w) * hpc);
    pos.xy = pixelPos / hpc * pos.w;
    return pos;
}

这里很明确地写了,其实就是在round上,这里变成了整数,丢失掉了精度,来让一一对应起来。

这个shader    Sprites-Diffuse是个diffuse的,也就是lambert模型下的,然后,看了一下,这个shader用了surfaceshader去写的。

用surfaecshader的话,一定要注意变体。

#pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing

这个Sprites-Mask  shader下,ColorMask 是 0,也就是不写colorbuffer,主要还是stencilbuffer的部分的写入

使用参考这个

猜你喜欢

转载自blog.csdn.net/u012871784/article/details/81737639