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

Implement generic decal geometry placement over meshes #4053

Open
mvaligursky opened this issue Feb 25, 2022 · 4 comments
Open

Implement generic decal geometry placement over meshes #4053

mvaligursky opened this issue Feb 25, 2022 · 4 comments
Labels
area: graphics Graphics related issue feature

Comments

@mvaligursky
Copy link
Contributor

The task is to implement a geometry generation for a decal, allowing a rectangular quad to be placed on a mesh (or an array of meshes), with wrapping around. Something similar to this: http://blog.wolfire.com/2009/06/how-to-project-decals/

@kungfooman
Copy link
Collaborator

I worked on a live decal system, currently using the camera as "projector":

74

Front view:

74_front

Back, good to see the wrapping:

74_back

(the texture UV's don't look so good yet in the bottom/green part, because from the Point of View of the projector there is so little delta to calculate left/right)

It works only on static models, searching all mesh instances in the scene and using their node.worldTransform to transform the mesh faces/positions.

Currently it just generates a globally positioned mesh which is then drawn via app.drawMesh.

Maybe two systems would be useful:

  • live decals, like a light source drawing a decal on the entire scene (using tags as filters), with ability to assign custom materials or e.g. fire shader for some nice effects
  • static decals, that get generated once and then attached as child to the meshInstance parent entity, e.g. a driving car with decal bullet holes attached to it, so they 'stick'

This would be amazing for better testing/debugging: #2904

@kungfooman
Copy link
Collaborator

Finally came around to make it work in the Playcanvas Editor: https://playcanvas.com/project/907728/overview/decals

Thoughts/ideas/improvements are welcome, personally there are so many things I would like to add/change, but thats never-ending. Its at least a starting point.

The editor doesn't seem to be able to set the material attributes slopeDepthBias / depthBias, so I hardcoded that e.g.

Since the script currently regenerates all decals every frame (so you can move the camera in editor and see live results), normals/tangents calculation slows the scene a bit down:

image

@mvaligursky
Copy link
Contributor Author

That runs nicely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature
Projects
None yet
Development

No branches or pull requests

3 participants