Overview
TheGridReader class is an OSC (Open Sound Control) receiver that communicates with the VRSL grid node to receive DMX data in real-time. It listens for OSC messages containing DMX channel values and writes them to a texture buffer that VRSL fixtures can read from.
This component is essential for real-time DMX control in the Unity Editor, allowing you to preview DMX-controlled lighting without being in VRChat.
Namespace: VRSLPlatform: Unity Editor only (
#if UNITY_EDITOR)Inherits from:
MonoBehaviour
This script only functions in the Unity Editor. It is automatically excluded from builds and is used solely for testing and previewing DMX lighting in the editor.
Configuration
Enable if using the grid node in vertical mode. This affects how DMX data is mapped to the texture buffer.
true= Vertical mode (~67 universes)false= Horizontal mode (~3 universes)
Enable if you are using RGB mode to use additional universes (9-universe mode). When enabled, RGB channels are parsed separately; when disabled, all RGB channels receive the same value.
The port to listen for OSC messages on. Must match the port set in the VRSL grid node. The listener actually uses
_OSCPort + 1 for receiving data.OSC address prefix assigned in the VRSL grid node. All incoming messages must match this prefix.
Internal Settings
The texture that stores DMX channel values. This texture is read by VRSL fixtures to determine their state.
How It Works
Initialization
-
On
Start(), GridReader initializes buffer arrays based on the selected mode:- Vertical mode: 13 x 67 pixels (871 DMX channels)
- Horizontal mode: 120 x 13 pixels (1560 DMX channels)
- Sets up an OSC UDP listener on the configured port
-
Sends a refresh command to the grid node to request current DMX state:
Data Reception
When OSC messages arrive:- Messages are parsed by
TekView.TekParse(standard or expanded mode) - Channel data is extracted:
[channel, red, green, blue] - Data is written to the buffer array
- The corresponding pixel is flagged for update
Texture Update
On everyUpdate():
- Checks which pixels need updating (flagged channels)
- Writes color data to the
_DataBuffertexture in 16x16 pixel blocks - Applies texture changes
- VRSL fixtures read from this texture to get their DMX values
Grid Modes
Vertical Mode (_IsVertical = true)
- Dimensions: 13 columns x 67 rows
- Total channels: 871 DMX channels
- Best for: Most standard lighting setups
- Mapping: Channels are arranged vertically, then horizontally
Horizontal Mode (_IsVertical = false)
- Dimensions: 120 columns x 13 rows
- Total channels: 1560 DMX channels
- Best for: Wide setups with many fixtures
- Mapping: Channels are arranged horizontally, then vertically
Expanded Universe Support
Standard Mode (_ExpandedUniverseSupport = false)
- Single value controls all RGB channels
- Color data:
R = value, G = value, B = value - Simpler, uses less bandwidth
Expanded Mode (_ExpandedUniverseSupport = true)
- Separate RGB values per channel
- Color data:
R = red, G = green, B = blue - Enables 9-universe RGB mode
- More data, more flexibility
Setup Example
In Unity Editor
-
Add GridReader component to a GameObject in your scene:
-
Configure the settings:
-
Create and assign a data buffer texture:
- The texture should match your grid mode dimensions
- For vertical: 208x1072 pixels (13x16, 67x16)
- For horizontal: 1920x208 pixels (120x16, 13x16)
With VRSL Grid Node
-
Ensure your VRSL grid node is configured with matching settings:
- OSC Port: 12000
- OSC Prefix: /VRSL
- Grid mode: Vertical or Horizontal
- Start your DMX software and grid node
- Enter Play mode in Unity - GridReader will automatically connect
Troubleshooting
No Data Received
- Port mismatch between GridReader and grid node
- Firewall blocking UDP traffic on the specified port
- Grid node not running
- OSC prefix mismatch
Texture Not Updating
Check:_DataBufferis assigned in the inspector- Texture format supports
SetPixels()(should be readable) - Console for error messages
Performance Issues
Optimization tips:- GridReader only updates changed pixels, not the entire texture
- Higher channel counts (horizontal mode) require more processing
- Consider using standard mode instead of expanded if RGB separation isn’t needed
Code Example: Custom Integration
Technical Details
Buffer Structure
- Each DMX channel occupies a 16x16 pixel block in the texture
- Channel values are stored as normalized color values (0-1)
- In standard mode:
R = G = B = DMX value / 255 - In expanded mode:
R = DMX red / 255, G = DMX green / 255, B = DMX blue / 255
Memory Usage
- Vertical mode: ~260KB texture (208x1072x4 bytes)
- Horizontal mode: ~1.6MB texture (1920x208x4 bytes)
- Buffer arrays: 871-1560 Color values in memory
Network Protocol
GridReader expects OSC messages in the format:Related Components
- VRSL_LocalUIControlPanel - Control panel for DMX settings
- VRStageLighting_DMX_Static - DMX-controlled fixtures that read from GridReader
Dependencies
GridReader requires the SharpOSC library for OSC communication:SharpOSC.UDPListener- Receives OSC messagesSharpOSC.UDPSender- Sends OSC messagesSharpOSC.OscMessage- OSC message structure