Skip to content

Instantly share code, notes, and snippets.

@reduz
Last active October 2, 2023 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reduz/9035c2854eec816cb443f0613262c77a to your computer and use it in GitHub Desktop.
Save reduz/9035c2854eec816cb443f0613262c77a to your computer and use it in GitHub Desktop.

Mock up of how compositor material would work:

shader_type compositor;
// The custom buffers from the Compositor proposal are all available for reading and writing

// Available render modes
render_mode post_opaque, post_alpha, post_tonemap; // default is post_alpha

//uniform sampler2D buffer_texture0 : hint_custom_buffer0_texture, repeat_disable, filter_nearest;
//uniform sampler2D buffer_texture1 : hint_custom_buffer1_texture, repeat_disable, filter_nearest;
uniform sampler2D buffer_texture2 : hint_custom_buffer2_texture, repeat_disable, filter_nearest;
uniform sampler2D buffer_texture3 : hint_custom_buffer3_texture, repeat_disable, filter_nearest;

// These are available also like material shaders

uniform sampler2D source_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform sampler2D source_normal : hint_normal_texture, repeat_disable, filter_nearest;
uniform sampler2D source_depth : hint_depth_texture, repeat_disable, filter_nearest;
uniform sampler2D source_motion_vectors : hint_motion_vector_texture, repeat_disable, filter_nearest;

void composite() {

  vec4 color = SRC_COLOR; 
  COLOR = color * 2.0;  
  
  //CUSTOM_BUFFER2 = vec4(0,0,1);
  //CUSTOM_BUFFER3 = vec4(1,0,1);
}

Notes:

  • Only SRC_COLOR or hint_screen_texture can be used at the same time. Using both is error.
  • These should be implemented like render targets, not compute so they work properly on both mobile and compatibility renderers. On mobile it should be implemented as an input attachment, to not mess with performance.
  • next_pass should be supported in compositor shaders, this means the output of a pass is the input of the next.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment