The VRSLGI Functions File - AcChosen/VR-Stage-Lighting-GI-ShaderPack GitHub Wiki

The VRSLGI-Functions.cginc File

This file is where all of the calculations of the VRSL GI system on the receiver end are done. This file can be copied and moved around, sold, etc. It's 100% open source. This file contains a bunch of functions that allow shader creators to implement the VRSL GI system into their shaders.

This documentation will not go over everything in the file, but it will go over the requirements for a basic implementation of the GI system.

Required Properties/Variables/Keywords

There are some required properties, variables, and keywords needed to use the VRSL GI system. I will provide some code excerpts from the standard shader here showing them.

Properties


        [ToggleUI] useVRSLGI("Use VRSL GI", Float) = 1.0
        [ToggleUI] _UseGlobalVRSLLightTexture("Use Global VRSL Light Texture", Float) = 0.0
        [ToggleUI] useVRSLGISpecular("Use VRSL GI Specular", Float) = 1.0
        [NoScaleOffset] _VRSL_LightTexture("VRSL GI Light Texture", 2D) = "white" {} //The base GI light texture
        [ToggleUI] _UseVRSLShadowMask1 ("Use VRSL Shadow Mask 1", Int) = 0 // The first shadow mask toggle
        [NoScaleOffset] _VRSLShadowMask1("VRSL GI ShadowMask 1", 2D) = "white" {} // The first shadow mask texture
        _UseVRSLShadowMask1RStrength("VRSL SM 1 R Strength", Range(0.0, 1.0)) = 1.0 // the R strength of the first shadow mask
        _UseVRSLShadowMask1GStrength("VRSL SM 1 G Strength", Range(0.0, 1.0)) = 1.0 // the G strength of the first shadow mask
        _UseVRSLShadowMask1BStrength("VRSL SM 1 B Strength", Range(0.0, 1.0)) = 1.0 // the B strength of the first shadow mask
        _UseVRSLShadowMask1AStrength("VRSL SM 1 A Strength", Range(0.0, 1.0)) = 1.0 // the A strength of the first shadow mask
        [Enum(GGX,0, Beckman,1, Blinn Phong,2)]_VRSLSpecularFunction("VRSL Specular Function", Int) = 0 // Selecting the specular function.

Variables


        #ifdef      _VRSL_GLOBALLIGHTTEXTURE
            Texture2D   _Udon_VRSL_GI_LightTexture;
            uniform float4  _Udon_VRSL_LightTexture_TexelSize;
        #else
            Texture2D   _VRSL_LightTexture;
            uniform float4  _VRSL_LightTexture_TexelSize;
        #endif


        int     _Udon_VRSL_GI_LightCount;

            half        _VRSLMetallicMapStrength;
            half        _VRSLGlossMapStrength;
            half        _VRSLSmoothnessChannel;
            half        _VRSLMetallicChannel;
            half        _VRSLInvertMetallicMap;
            half        _VRSLInvertSmoothnessMap;

            Texture2D   _VRSLShadowMask1;
            Texture2D   _VRSLShadowMask2;
            Texture2D   _VRSLShadowMask3;

            int         _UseVRSLShadowMask1;
            int         _UseVRSLShadowMask2;
            int         _UseVRSLShadowMask3;

            int         _VRSLGIVertexFalloff;
            float       _VRSLGIVertexAttenuation;


            half        _VRSLSpecularShine;
            half        _VRSLGlossiness;
            half        _VRSLSpecularStrength;
            half        _VRSLGIStrength;
            half        _VRSLDiffuseMix;
            half        _VRSLSpecularMultiplier;

            half        _UseVRSLShadowMask1RStrength;
            half        _UseVRSLShadowMask1GStrength;
            half        _UseVRSLShadowMask1BStrength;
            half        _UseVRSLShadowMask1AStrength;

            half        _UseVRSLShadowMask2RStrength;
            half        _UseVRSLShadowMask2GStrength;
            half        _UseVRSLShadowMask2BStrength;
            half        _UseVRSLShadowMask2AStrength;

            half        _UseVRSLShadowMask3RStrength;
            half        _UseVRSLShadowMask3GStrength;
            half        _UseVRSLShadowMask3BStrength;
            half        _UseVRSLShadowMask3AStrength;

            half        _VRSLShadowMaskUVSet;


Keywords


            #pragma shader_feature_local _ _VRSL_GI //Toggles The VRSL GI module
            #pragma shader_feature_local _ _VRSL_SPECFUNC_GGX _VRSL_SPECFUNC_BECKMAN _VRSL_SPECFUNC_PHONG //Selects the Specular Function
            #pragma shader_feature_local _ _VRSL_GI_SPECULARHIGHLIGHTS //Toggles Specularity
            #pragma shader_feature_local _ _VRSL_SHADOWMASK_UV0 _VRSL_SHADOWMASK_UV1 _VRSL_SHADOWMASK_UV2 //Chooses the Shadow mask UV Map
            #pragma shader_feature_local _VRSL_SHADOWMASK1 // Enables the shadow mask
            #pragma shader_feature_local _VRSL_GLOBALLIGHTTEXTURE // Chooses between reading the global light texture the provided one
            #pragma shader_feature_local _ _VRSL_SHADOWMASK_RG _VRSL_SHADOWMASK_RGB _VRSL_SHADOWMASK_RGBA //Chooses which channel to read the shadow mask from.

The Function

There are many functions that are in this file, but the primary you'll want to use in the base pass of your shader is this one

    float3 VRSLGI(float3 worldPos, float3 worldNormal, float roughness, float3 eyeVec, float3 diffuseColor, float2 mg, float2 uv, float occlusion)

This function will perform all the calculations for the VRSL GI system, assuming you have provided the correct inputs.

Here's a list of the inputs and a description of each


   float3 worldPos; // The world space position of the vertex. You can get it from mul(unity_ObjectToWorld, v.vertex);
   float3 worldNormal; // The world space normals of the current pixel/vertex. You'll want to ensure your normals are modified by your normal map first.
   float roughness; // The base smoothness/roughness value for specular.
   float3 eyeVec; // The view direction of the camera. You'll want to negate it on input.
   float3 diffuseColor; // The current diffuse/albedo color of the material.
   float2 mg; // The metallic/gloss or metallic/smoothness values for specular from the metallic/smoothness texture. X = metallic, Y = Smoothness.
   float2 uv; // The shadow mask UVs
   float occlusion; // An optional occlusion mask input. If none is available, you can just put 1.0 here.

The output will be the final total color from the VRSLGI system in RGB format. You can then add it to your final output color on your shader.