Skip to content

Instantly share code, notes, and snippets.

@EtiTheSpirit
Last active May 10, 2024 11:25
Show Gist options
  • Save EtiTheSpirit/3dce03d381396f390f8a073d0276d7c0 to your computer and use it in GitHub Desktop.
Save EtiTheSpirit/3dce03d381396f390f8a073d0276d7c0 to your computer and use it in GitHub Desktop.

ChilloutVR Shader Parameters

This was last updated for ChilloutVR 2023r173. On future versions, these values might be out of date!

This mostly covers global values or values that are relevant to you as a player.

Shader Keywords

(Nothing here yet, sorry!)

Shader values

SOME OF THESE ARE PARAMETERS, OTHERS ARE GLOBAL.

  • For clarity, I will explicitly write the uniform keyword to refer to globals. You can access these in any shader simply by declaring the variable.
    • You don't need to actually use the keyword in your shader. It's something I do from habit.
  • Fields that do not have uniform on them are parameters that you must add to your ShaderLab Properties { } block
    • Note that it may be a good idea to make these fields instanced (via UNITY_DEFINE_INSTANCED_PROP)

Unsorted Globals / General Use

  • uniform float CVRRenderingCam - The type of camera that is being rendered.
    • 0 = Normal Camera (you are you)
    • 1 = Portable Camera (you are going to be in a picture)
    • 2 = CVRMirror Camera (your mirror copy is rendering)
  • uniform float4 CVRTime - The time on the system.
    • x is time, in seconds. It represents the local time. This includes decimal increments of millisecond accuracy.
    • y is time, in seconds. It represents GMT+0 or UTC. This includes decimal increments of millisecond accuracy.
    • z is the day of the year, a value between 1 and 366.
    • w is 1 if it is a leap year, 0 if not.
  • uniform float CVRIsUsingVr - 1 if VR, 0 if not.
  • uniform float CVRGlobalParams1 - Misc. goodies, 1
    • x is the current ping.
    • y is the amount of players in the instance.
    • z is the left hand controller's battery %.
    • w is the right hand controller's battery %.
  • uniform float CVRGlobalParams2 - Misc. goodies 2
    • x is 1 when using FBT, 0 if not.
    • y is the left foot's battery %.
    • z is the right foot's battery %.
    • w is the hip's battery %.

CVR Global Material Property Updater

  • This has no explicitly declared name, instead it is a field that is read in Awake().

CVR Material Updater

This exists on an object as a script, and expects a Renderer component to be present. The renderer's material is cloned (via the use of the material property rather than sharedMaterial) and then this unique clone is driven.

  • float3 _CVR_Velocity - The velocity of the object the updater is attached to.
  • float3 _CVR_Angular_Velocity - The angular velocity of the object the updater is attached to.

CVR Combat System

Exists for the game's built in combat system.

  • uniform float4 _CVRCombatSystemHealth - Your health in the current instance of a combat system, where applicable.
    • x is the current value
    • y is the max value
    • z is regeneration delay (how long it takes to start regenerating)
    • w is the time remaining until regeneration will begin
  • uniform float4 _CVRCombatSystemArmor - Your armor in the current instance of a combat system, where applicable.
    • Same as health for XYZW's purpose (current, max, delay, time).
  • uniform float4 _CVRCombatSystemShield - Your shield in the current instance of a combat system, where applicable.
    • Same as health for XYZW's purpose (current, max, delay, time).

CVR Audio Material Parser

This is the game's version of audiolink.

There are four sample arrays for left and right audio data. Each of these arrays is 1024 units long, for a total of 4096 samples for left, and 4096 for right.

This reads data from a specific, single AudioSource instance.

  • uniform float[] _leftSamples1 - This, as well as the next left arrays, combine to form a continuous space of 4096 floats. These represent audio samples for the left channel.
  • uniform float[] _leftSamples2
  • uniform float[] _leftSamples3
  • uniform float[] _leftSamples4
  • uniform float[] _rightSamples1 - This, as well as the next right arrays, combine to form a continuous space of 4096 floats. These represent audio samples for the right channel.
  • uniform float[] _rightSamples2
  • uniform float[] _rightSamples3
  • uniform float[] _rightSamples4
  • uniform float _volume - The volume of the AudioSource that this is reading.
  • uniform float _distance - The distance from the movement system's rotation pivot (your position, basically) and the audio's location.
  • uniform float _pitch - The pitch of the AudioSource that this is reading.
  • uniform float _doppler - The intensity of the doppler effect for the AudioSource that this is reading. This is not the current doppler effect, just how much it affects the audio when you do end up moving.
  • uniform float _spatial - The spatial blend of the audio, where 0 is 2D and 1 is 3D.

Player Material Parser

This is the system that allows player data to be accessed via shaders. For all arrays, [0] is the local player. Each array is 255 elements long.

ℹ While any skilled shader author should know this, this is a reminder to consider whether you should use [loop] or [unroll]! The amount of elements in the array will not sensibly change while a frame is rendering. As a result, warps do not become divergent when evaluating the branch, and thus the branch can evaluate the same result on all pixels and execute at its minimum cost. A standard loop will probably benefit when the loop contains highly complex code, but of course, the best choice is to actually pull open the GPU Profiler and test rather than relying on intuition, if it matters enough.
Consider using CVRGlobalParams1.y, see the Unsorted Globals section up top.
  • float4[] _PlayerRootPositions - The position of the root of each player, by index. XYZ is the position, and W is the height of the avatar.
  • float3[] _PlayerHipPositions - The position of the hip of each player.
  • float3[] _PlayerHeadPositions - The position of the head of each player.
  • float3[] _PlayerLeftHandPositions - The position of the left hand of each player.
  • float3[] _PlayerRightHandPositions - The position of the right hand of each player.
  • float3[] _PlayerChestPositions - The position of the chest of each player.
  • float3[] _PlayerLeftFootPositions - The position of the left foot of each player.
  • float3[] _PlayerRightFootPositions - The position of the right foot of each player.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment