0

I'm trying to figure out how to get object's information pixel in screen is rendering in shader.

I'm trying to make a 3d pixelation shader. And this is done by

1.getting the render texture from camera. 2.and pixelate that using shader graph

and it works fine.

how pixelation turned out

I've also managed make a pixel outline.

with outline

But the problem is when the two objects are overlayed, the outline just gets drawn as if those were the same object.

when multiple objects overlays

I'm not exactly sure how to get over this but my idea is to,

1.Somehow get the object information the pixel in render texture in shader. 2.And draw outlines seperately based on that info

But even after days of researching. I couldn't get it working.

If you have any documents or information about accessing object in shader, or just have another way of doing this instead of this method. I would be glad to hear it. Thanks.

These are what i've tried and thought of so far

1.Google "Unity get access to object of pixel camera is rendering" (but couldn't find anything useful)

2.Just give object outline before pixelating(It sort of works but it is jittery)

3.Get the object information based on its depth value using depth texture(It kind of works but it's unstable because if two objects stay close, there's no way to distinguish them)

4.Get the object information by giving raycast on every single position pixel will render. (But it'll have to have 100k+ raycasts and use GetComponent 100k+ times every frame, which will be expensive)

frankhermes
  • 4,720
  • 1
  • 22
  • 39
Gejam
  • 1
  • 1

1 Answers1

0

First read about deferred rendering, maybe it will help you to find a nice solution.

Second, you can assign an ID to each object, then you could render all objects into a render texture using this ID as a color. Then use that render texture in your shader to differentiate objects. Some bit logic and you'll get what you need.

szamil
  • 684
  • 5
  • 17