Addon ID

  • mikal-frag8-v2

Info

Statistics

  • Download count72 total downloads
  • Latest download count 56 downloads of latest version
  • Average download count2 downloads per day average

Owners

3D Fragment Light Effect

For now only webgl2 (testing webgpu), set webgl2 for editor and runtime.

3D Model and Mesh do not work with it yet, asking C3 team about a possible issue preventing it, or what I may need to change with the setting of this effect.

Must be first effect on an instance.

Do not use built-in opacity or color of instance.

Instead use the opacity and color tint of this effect.

8 Lights, world based x,y,z

Spotlight

Specular

Ambient

Fog (world based)

Currently works on 3D Shape and Sprite (not tested on 3D Model, since current beta crashes with 3D Model)

Add effect to each instance (best if using families for common objects). Add a common function to control all the light families.

# Frag Light V2 - 8 Light Effect

## Description

Frag Light V2 is a fragment shader effect supporting 8 independent point/spot lights, a directional light, Phong specular highlights, distance fog with height falloff, and screen-door transparency dithering. It works on both WebGL2 and WebGPU renderers. Apply it to any 3D-rendered object -- each light can be individually enabled, colored, positioned, and configured as a point light or spotlight with adjustable cone angle and soft edges. Attenuation (constant/linear/quadratic) controls distance falloff. A debug mode parameter (1-4) lets you visualize world position, normals, light distance, and attenuation in real-time.

## Usage Guide

**Lights:** Enable a light (e.g. Light 0 Enable = 1), set its position (PosX/Y/Z), color, and brightness. For spotlights, set SpotAngle as the cosine of the half-angle: `cos(angle_degrees * pi / 180)` -- e.g. 45 degree cone = `cos(22.5 * pi/180)` = 0.924, 90 degree cone = `cos(45 * pi/180)` = 0.707. SpotEdge controls soft edge width (0 = hard cutoff). SpotDir (X/Y/Z) sets the cone direction. Leave SpotAngle at -1 for an omnidirectional point light. Attenuation defaults to no falloff -- increase Linear or Quadratic for realistic distance dropoff.

**Directional Light:** A single infinite-distance light. Set DirX/Y/Z for the light direction vector and adjust brightness/color.

**Specular:** Enable for Phong highlights. Shininess controls tightness, Intensity controls strength. Set ViewPosition to your camera's world position for correct reflections.

**Fog:** Enable and set Start/End distances from the camera position (FogCameraPos X/Y/Z). HeightStart/HeightEnd controls vertical fog boundaries. Density > 1 thickens fog, < 1 thins it, 1.0 is linear.

**Screen-door Dithering:** Enable for 4x4 ordered dithering on semi-transparent objects -- useful for depth-correct transparency without sort issues.

**Debug Modes:** Set DebugMode to: 1 = world position, 2 = surface normals, 3 = light 0 distance, 4 = light 0 attenuation.

**Coordinate system:** +X right, -Y up, +Z toward camera.

## Architecture: Light Families

When multiple objects share the same lighting, group them into "families" -- e.g. all ground tiles use one effect instance, all characters another. Each family has its own Frag Light effect but should receive the same light values.

Create a central function to update a specific light across all families:

```

// SetLight(lightIndex, x, y, z, r, g, b, brightness)

// Loop through all family containers,

// set the effect parameters for that light index

```

Create similar helper functions for shared features:

```

SetDirectional(dirX, dirY, dirZ, r, g, b, brightness)

SetFog(start, end, density, r, g, b)

SetSpecular(shininess, intensity, r, g, b)

SetAmbient(r, g, b)

```

Each function iterates all families and writes to their effect parameters. This keeps lighting consistent across your scene and gives you a single point of control. You can still override individual families for special cases (e.g. an object that ignores fog).