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

Soft Particles #35

Merged
merged 74 commits into from
Jun 19, 2022
Merged

Soft Particles #35

merged 74 commits into from
Jun 19, 2022

Conversation

hmans
Copy link
Owner

@hmans hmans commented Jun 18, 2022

Summary

This PR adds support for Soft Particles. You can enable soft particle support per material by setting its softness prop to a non-zero value. In order for soft particles to work, the material also needs to passed a depth texture. The implementation in this PR expects the generation of this depth texture in userland; the examples app contains a sample implementation that may, at some point in the future, be integrated into the library itself.

Example

export const SoftParticlesExample = () => {
  const depthBuffer = useDepthBuffer()

  return (
    <VisualEffect>
      <MeshParticles>
        <planeGeometry args={[20, 20]} />

        <ParticlesMaterial
          baseMaterial={MeshStandardMaterial}
          color="hotpink"
          billboard
          transparent
          depthWrite={false}

          softness={5}
          depthTexture={depthBuffer.depthTexture}
        />

        <Emitter
          count={1}
          setup={(c) => {
            c.lifetime = Infinity
          }}
        />
      </MeshParticles>
    </VisualEffect>
  )
}

There is also a softnessFunction prop that allows the user to override the GLSL code used for determining the fragment softness.

Other things in this PR that somehow ended up in it, ahem:

  • Removed the Three.js vanilla post-processing and replaced it with a recent version of postprocessing (it has a cool new bloom effect!
  • The particle setup functions are now passed not only the configuration object, but also the index of the spawned particle. (This is currently the index within a single emission burst. It might be changed to something else later, like the index of the particle within the instance buffer. Use with care!)
  • Shader module bodies are now automatically scoped, so they can freely create local variables without colliding with other chunks, and are prevented from leaking variables to the main scope.

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Jun 18, 2022

🦋 Changeset detected

Latest commit: 54b4c5f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
three-vfx Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
three-vfx ✅ Ready (Inspect) Visit Preview Jun 19, 2022 at 11:48AM (UTC)

@hmans hmans linked an issue Jun 18, 2022 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Jun 19, 2022

Deployment failed with the following error:

Resource is limited - try again in 4 hours (more than 100, code: "api-deployments-free-per-day").

@hmans hmans added this to the 0.2.0 milestone Jun 19, 2022
@hmans hmans closed this Jun 19, 2022
@hmans hmans reopened this Jun 19, 2022
@hmans hmans merged commit baf11be into main Jun 19, 2022
@hmans hmans deleted the soft-particles branch June 19, 2022 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Soft Particles
1 participant