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

源自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的部分的写入

使用参考这个

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值