Unity ShaderLab 中的像素完美着色器 [英] Pixel-perfect shader in Unity ShaderLab

查看:38
本文介绍了Unity ShaderLab 中的像素完美着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Unity 中,在编写着色器时,

In Unity, when writing shaders,

着色器本身是否有可能知道"屏幕分辨率是多少,并且着色器确实可以控制单个物理像素?

is it possible for the shader itself to "know" what the screen resolution is, and indeed for the shader to control single physical pixels?

我只考虑为 2D 对象编写着色器的情况(例如用于 UI 使用,或在任何情况下使用正射相机).

I'm thinking only of the case of writing shaders for 2D objects (such as for UI use, or at any event with an ortho camera).

(当然,通常要在屏幕上显示物理像素完美的 PNG,您只需说 400 像素的 PNG,然后您安排缩放,以便着色器恰好绘制到 400 个物理像素.我我想知道是一个只绘制的着色器,例如一条物理像素完美的黑线 - 它必须知道"物理像素的确切位置.)

(Of course, normally to show a physical-pixel perfect PNG on screen, you merely have a say 400 pixel PNG, and you arrange scaling so that the shader, happens to be drawing to, precisely 400 physical pixels. What I'm wondering about is a shader that just draws, for example a physical-pixel perfect black line - it would have to "know" exactly where the physical-pixels are.)

推荐答案

有一个名为 _ScreenParams 的 ShaderLab 内置值.

There is a ShaderLab built-in value called _ScreenParams.

_ScreenParams.x 是以像素为单位的屏幕宽度._ScreenParams.y 是以像素为单位的屏幕高度.

_ScreenParams.x is the screen width in pixels. _ScreenParams.y is the screen height in pixels.

这是文档页面:http://docs.unity3d.com/462/Documentation/手册/SL-BuiltinValues.html

这篇关于Unity ShaderLab 中的像素完美着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆