#How to apply a shader to an entire canvas?

1 messages · Page 1 of 1 (latest)

young marsh
#

I'd like to apply a shader across a whole canvas. So far the method I've been using involves aiming a camera at the canvas and having it output to a render texture, which I use on a RawImage, which has the shader's material applied.

This is obviously a lot of steps and means a new camera for every canvas I want to apply my effect to. Is there any way to skip the camera/RT/RawImage step and go straight to applying the shader to the canvas?

haughty bramble
young marsh
#

So this one, as an example, requires four cameras to be running at once, because each screen needs its own render texture (because they're angled differently, they can't share a render texture).

#

If I could cut the cameras out, it would help a lot with optimisation!

haughty bramble
# young marsh

I've often seen this done with just one camera by rendering all the elements in the same 2D space, then with mesh UVs splitting the texture into multiple different spots

young marsh
haughty bramble
#

Though hard to learn without getting into 3D modeling at least a bit

#

Unity's ProBuilder can do it and skip the need to learn something like Blender for it
But I'm not sure if it's all that easier, and knowing Blender for tasks just like this is super handy

young marsh
#

The shader does have a screen warp effect where it bends towards the edges. Do you think that'd be possible to replicate using the mesh UV method?

#

If you can share any examples of where you've seen this done that might be helpful, but no worries if you can't remember on the spot.

haughty bramble
young marsh
#

Ohhh that's clever.

#

Okay, yeah. My main concern with this would be the loss of control per individual screen (eg shader effects that come from the 'top' of the screen, no longer being able to vary the shader per screen, etc) but those might be worth sacrificing for performance.

Just to absolutely rule it out, there's no way at all of applying a shader to the canvas without first going through camera --> RT? No way to convert a canvas to a texture that doesn't involve using a camera as a middle-man?

haughty bramble
#

And no practical way to skip the need for for more cameras afaik
Except this one https://agentlien.github.io/cameras/
(Not really a tutorial as it doesn't have every step detailed, just the gist of it)

#

Only this one comes to mind off the top of my head

#

The grid of screens are physically separate
And some monitors apply the film effect, some don't, while sharing the RT

#

Actually Ep2 improved on this

#

Can more clearly see the separation and different effects per monitor

#

Which could be achieved by applying one shader that does different effects per-UV region, or using different shaders with the same RT just as well

young marsh
#

That's fantastic - thank you so much!

haughty bramble
#

The curving could be done in the shader but with meshes it's just very simple
Shaders are the way to go if you want the curvature to have some special parallax or respond to viewing angle in specific ways though

young marsh
#

No I think a mesh would be ideal for it. And for hit detection you'd just use a raycast and convert the area on the mesh to the relative area on the canvas?

haughty bramble
#

Probably only necessary if you have too many, or too dynamic elements to take care of manually

young marsh
#

We've got a lot of interactable elements, but only on some of the screens.

#

The bottom one in my screenshot is the only one the player really interacts with directly.

haughty bramble
#

If you did want to do some clever mapping of physical screens to UI, I think maybe you could translate the cursor and click coordinates from world space to the 2D UI space relative to the screens
But UI afaik uses graphics raycaster and inbuilt click events so I don't know if they allow offsetting the cursor in that way before checking for UI interaction

#

If you can get away with predefined clickable colliders on the screen itself, I recommend that

young marsh
#

Hm. It's definitely more dynamic than that unfortunately. I think it might come down to writing some custom button/interaction components and using them.