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

查看:602
本文介绍了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.)

推荐答案

ShaderLab内置值称为_ScreenParams.

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天全站免登陆