Milkshake.io logo

Creating Weapon Shaders

Step 1. Render Weapon with Stencil

First, render the weapon model with stencil buffer configuration:

stencilRef: 1
stencilZPass: ReplaceStencilOp
Step 1: Render Weapon with Stencil

Step 2. Render Outline Model

Scale the model up with a solid color or use a vertex shader to displace the vertices:

vec3 displacedPosition = position + normal * 0.1;
Step 2: Render Outline Model

Step 3. Stencil Buffer Magic

The stencil buffer is used to exclude the base gun model, allowing only outside pixels to be drawn:

side: DoubleSide,
stencilWrite: true,
stencilRef: 1,
stencilFunc: NotEqualStencilFunc
Step 3: Stencil Buffer Magic

Step 4. Glow Sprite

Add a simple 2D sprite image using the same stencil buffer magic to create a glow effect.

Step 4: Glow Sprite

Step 5. Fresnel

Add a Fresnel shader to the base weapon. Use PointLight & Bloom for added effect.