Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pixel-perfect shader in Unity ShaderLab

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?

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).

(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.)

like image 272
Fattie Avatar asked Jan 22 '16 17:01

Fattie


1 Answers

There is a ShaderLab built-in value called _ScreenParams.

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

Here's the documentation page: http://docs.unity3d.com/462/Documentation/Manual/SL-BuiltinValues.html

like image 188
HalpPlz Avatar answered Sep 21 '22 01:09

HalpPlz