Hi!
So I made a B&W shader in my game, but i need some elements (in my case particles) to remain colored.
My shader is in canvay layer > color rectangle node:

which is instantiated in main scene
shader code is fairly simple > takes all color value and multiply to make it true B&W
`shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform float alpha : hint_range(0.0, 1.0) = 0.0;
uniform bool weighted = true;

void fragment() {
COLOR = texture(SCREEN_TEXTURE, SCREEN_UV);
COLOR.rgb = mix(vec3((COLOR.r + COLOR.g + COLOR.b) / 3.0), vec3(0.299 * COLOR.r + 0.587 * COLOR.g + 0.114 * COLOR.b), float(weighted));
COLOR.a = alpha;
}`

I tried to play with subviewport, but can't get far with it, since having additional subviewport hijacks my mouse input and i can't seem to get around that either

any solutions to it?
thanks!

  • xyz replied to this.
    • Edited

    An_unique_name If you're not using specular, you can write an exclusion flag to roughness and then read it from NR screen texture in your post processing shader. Otherwise, you'll have to render the flag in a separate pass which would require using a viewport.

      xyz I will need to look into that, those are totally new concepts for me, thanks for the hint

      4 days later

      Seems I managed to get a result I was looking for with setup below
      main camera mesh is on visibility layer 1 paired with cull mast from main camera outside
      second camera mesh is on visibility layer 2 paired with cull mask from camera in subviewport
      subviewport is inside canvas layer so that it's always projected on top of screen, visible layers don't seem to matter
      ColorRect has shader material that applies B&W shader to everything below.
      order within canvas layer is important, everything that won't have applied shader has to be below (or on top) of ColorRect
      :

      I think topic can be closed