Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Materials can now use the screen texture #2849

Merged
merged 3 commits into from
Dec 21, 2023

Conversation

eonarheim
Copy link
Member

@eonarheim eonarheim commented Dec 21, 2023

===:clipboard: PR Checklist :clipboard:===

  • 📌 issue exists in github for these changes
  • 🔬 existing tests still pass
  • 🙈 code conforms to the style guide
  • 📐 new tests written and passing / old tests updated with new scenario(s)
  • 📄 changelog entry added (or not needed)

==================

water-material.mp4

This PR adds a new feature for materials that allows them to reference the screen texture. They way it works is it's the screen's framebuffer RIGHT before the material draw call (if you include the complete drawing you get the infinite mirror artifact which is pretty unusable)

2 new uniforms

  • u_screen_texture - This is the texture of the screen right before the material draw call
  • u_time_ms - This is the milliseconds since page navigation (performance.now() under the hood)

2 new attribute/varyings

  • a_screenuv - The vertex attribute corresponding to the screen uv relative to the current graphic
  • v_screenuv - The fragment varying corresponding to the screen uv relative to the current graphic

Finally there is a new convenience api for updating shader values in materials. .update(shader => {...})

  game.input.pointers.primary.on('move', evt => {
    heartActor.pos = evt.worldPos;
    swirlMaterial.update(shader => {
      shader.trySetUniformFloatVector('iMouse', evt.worldPos);
    });
  });

@github-actions github-actions bot added the enhancement Label applied to enhancements or improvements to existing features label Dec 21, 2023
@eonarheim eonarheim merged commit 4832577 into main Dec 21, 2023
4 of 5 checks passed
@eonarheim eonarheim deleted the feature/material-screen-texture branch December 21, 2023 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Label applied to enhancements or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant