Spray/Decal Script

I created a spray script. It uses projection matrix of camera and material chunks. Super easy to use, it also doesn’t use spot light, which is better for performance.

You can add spray items to the shop and use this script in the game.

Project link :
https://playcanvas.com/project/930594/overview/spray-sample--projection-matrix

Video :

I want to include few keywords here because I had trouble with finding those things; projection matrix, spray, decal, material chunks

8 Likes

That’s really cool! I definitely can use this in my game! Thanks for sharing!

1 Like

That’s awesome! Thanks for sharing as always! :slight_smile:

1 Like

This is really awesome!
Unfortunately, it doesn’t work anymore since Playcanvas v1.55. See here.

To fix this, in the Spray.js, you need to change this (line 24)

material.resource.chunks.combineDiffuseSpecularPS = this.sprayShader.resource;

to

material.resource.chunks.combinePS = this.sprayShader.resource;
3 Likes

Thanks for the script Cem!

I found one issue, this script gets the camera’s position and perspective to render the decal. So based on the situation the spray gets stretched. Instead of doing that, could you share an updated version that gets mesh’s normal?

Here is the image;

I’m sorry, I don’t know enough math to solve this problem.

2 Likes

Maybe you can get around this by having a second camera that’s just for spray. You can do a raycast to get the normal of the point you want to spray and have the spray camera look down that normal?