- Home /
Shaders and relative UVs
So I'm trying my hand at writing shaders at the moment. And I appreciate that what I want may not even be possible, but I have 2 questions:
Firstly - Can a shader in any way find out what section of the object it is currently drawing? For example, could I find out in a normalised fashion, if I'm currently operating on a pixel half way down the object's texture? UVs would normally help here, but in the scenario that I am using texture atlases, that flies out the window. I need to know in relation to the sub section of the larger texture, what I'm drawing, if that makes sense? Like if I could find out what the min and max UVs are of the object I'm currently rendering.
Example: I want pixels half way across a texture to become inverted in colour, and this shader is on an object that is part of a sprite sheet, and this particular frame has UVs of min(0.4, 0.6) max (0.5, 0.7), how can I find out from within the shader what those min and max UVs for this frame are?
Secondly - From my understanding, GrabPasses are only meant to grab the screen space behind the object you are trying to render, but all my attempts appear to be grabbing the entire screen, is this functionality correct? And if so, (and this kind of relates to the previous question) how can I find out what sub section of the screen my object occupies (I suspect this may be achieved via the use of matrices, but I'm really not highly educated in the area.)
Any help anyone could provide would be awesome, shaders seem like quite an introverted subject, the lack of intellisense makes them even harder to penetrate.
Answer by ungalyant2 · Apr 10, 2014 at 09:10 AM
I'm not sure if there's a more sublime solution that this, but I simply added a property for min and max UVs, and had an attached script provide each objects material with the relevant UV data.
Your answer
Follow this Question
Related Questions
Material offset relative to other game object 0 Answers
How do I get mesh data into post-processing shader (or render a mesh shader to a texture)? 0 Answers
Sprites consisting of two packed textures 0 Answers
U3: Beast Lightmapping + Nature / Soft Occlusion Shader 1 Answer
UV offset in surface shader. 1 Answer