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 :

Video :

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


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;


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

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.


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?

I’ve updated the shader for engine1.62: https://playcanvas.com/project/1065956/overview/f-spray-sample--projection


what changed in engine 1.62?

This was the newsletter that was sent out about 1.62: PlayCanvas Engine v1.62 RC - Updates to Shader Chunks and WebGPU

1 Like