Godot Broken Glass Shader Tutorial

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 4

  • @a.williamcook2926
    @a.williamcook2926 18 дней назад +1

    thanks, this was super useful. I couldn't find any other tutorial explaining this

  • @erik-sandberg
    @erik-sandberg 4 месяца назад +1

    This is really awesome stuff, thanks for making the video!

  • @Polysthetic
    @Polysthetic  Год назад +4

    📻 Addendum:
    This would be the equivalent branchless shader:
    // Current pixel colour in texture
    vec4 pixelColour = texture(TEXTURE, UV);
    // Colour of neighbouring pixel in texture
    vec4 nextColour = texture(TEXTURE, UV + TEXTURE_PIXEL_SIZE * reflectionOffset);
    // Colour of screen-space refraction effect
    vec4 refractionColour = texture(SCREEN_TEXTURE, SCREEN_UV + SCREEN_PIXEL_SIZE * refractionOffset);
    // If the adjacent colour is transparent, use reflection, else use refraction
    vec4 colour = mix(reflectionColour, refractionColour, nextColour.a);
    // Now only display this shader if the current texture pixel is not transparent
    COLOR = colour * pixelColour.a;
    As discussed in the video, I'm not sure how much of a speed benefit this will provide, if any. GPU branching is a more complex topic than CPU branching. In addition, the number of instructions within this shader is low enough that it may make no difference between the number of clock cycles for a branched vs branchless case.