1
0
mirror of https://github.com/AcChosen/VR-Stage-Lighting.git synced 2025-02-25 21:58:09 +01:00

Updated VRSL DMX: Creating Custom DMX Shaders (markdown)

AcChosen 2023-01-27 10:16:46 -05:00
parent 805a4f95ac
commit acfd646ac2

@ -95,6 +95,65 @@ The general use case, however, will be to use the `ReadDMX()` function with `Get
- `getNineUniverseMode()`
- Returns the instanced toggle property, `_NineUniverseMode`.
## Example Code
It is recommended, if possible, to get the DMX data in the vertex shader rather than the fragment shader. This is because since there is no UV mapping involved when sampling, it is generally faster to sample the data in the vertex shader and send it to the fragment shader through the v2f struct.
Here is an example:
`
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 finalColor : TEXCOORD1;
};
#include "Packages/com.acchosen.vr-stage-lighting/Runtime/Shaders/VRSLDMX.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
float4 col = getBaseEmission() * getGlobalIntensity() * getFinalIntensity();
if(isDMX())
{
int dmxChannel = GetDMXChannel();
float intensity = ReadDMX(dmxChannel, _DMXGridRenderTexture); // channel 1: Intensity
float red = ReadDMX(dmxChannel + 1, _DMXGridRenderTexture); // channel 2: Red
float green = ReadDMX(dmxChannel + 2, _DMXGridRenderTexture); // channel 3: Green
float blue = ReadDMX(dmxChannel + 3, _DMXGridRenderTexture); // channel 4: Blue
float strobe = GetStrobeOutput(dmxChannel + 4); // channel 5: Strobe
o.dmxIntensityStrobe.b = strobe;
float4 rgb = float4(red, green, blue, 1);
rgb *= intensity * strobe;
col = rgb; // final DMX color output.
}
o.finalColor = col;
return o;
}`
In this example, we created a custom parameter in the v2f struct with `float4 finalColor : TEXCOORD1;`, which simply stores the final emission color of our DMX shader. We then use `isDMX()` to determine if we are using DMX at runtime, and adjust the final output of `finalColor` with dmx data accordingly.
This way, our fragment shader only needs to grab `i.finalColor` to get the final output of our DMX color.
You do not need to only send color data, you can also send the dmx data values themselves if needed through the same method.