Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
909 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...