浏览代码

Initial ScriptableRenderLoop

/main
Joachim Ante 9 年前
当前提交
7f741951
共有 61 个文件被更改,包括 6735 次插入0 次删除
  1. 3
      .gitignore
  2. 9
      Assets/ScriptableRenderLoop.meta
  3. 35
      Assets/ScriptableRenderLoop/AdditionalLightData.cs
  4. 12
      Assets/ScriptableRenderLoop/AdditionalLightData.cs.meta
  5. 9
      Assets/ScriptableRenderLoop/ForwardRenderLoop.meta
  6. 20
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.asset
  7. 8
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.asset.meta
  8. 233
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs
  9. 12
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs.meta
  10. 9
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders.meta
  11. 688
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_lighting.cginc
  12. 9
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_lighting.cginc.meta
  13. 634
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_standard.shader
  14. 9
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_standard.shader.meta
  15. 550
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_utils.cginc
  16. 9
      Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_utils.cginc.meta
  17. 620
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveMenuTools.cs
  18. 12
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveMenuTools.cs.meta
  19. 565
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveShaderGUI.cs
  20. 12
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveShaderGUI.cs.meta
  21. 9
      Assets/ScriptableRenderLoop/RenderPasses.meta
  22. 436
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  23. 12
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs.meta
  24. 11
      Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs
  25. 12
      Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs.meta
  26. 35
      Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs
  27. 12
      Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs.meta
  28. 9
      Assets/TestScenes.meta
  29. 9
      Assets/TestScenes/ForwardRenderLoop.meta
  30. 1001
      Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity
  31. 8
      Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity.meta
  32. 9
      Assets/TestScenes/ForwardRenderLoop/Materials.meta
  33. 194
      Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat
  34. 8
      Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat.meta
  35. 14
      ProjectSettings/AudioManager.asset
  36. 6
      ProjectSettings/ClusterInputManager.asset
  37. 14
      ProjectSettings/DynamicsManager.asset
  38. 7
      ProjectSettings/EditorBuildSettings.asset
  39. 15
      ProjectSettings/EditorSettings.asset
  40. 72
      ProjectSettings/GraphicsSettings.asset
  41. 295
      ProjectSettings/InputManager.asset
  42. 71
      ProjectSettings/NavMeshAreas.asset
  43. 8
      ProjectSettings/NetworkManager.asset
  44. 24
      ProjectSettings/Physics2DSettings.asset
  45. 544
      ProjectSettings/ProjectSettings.asset
  46. 2
      ProjectSettings/ProjectVersion.txt
  47. 182
      ProjectSettings/QualitySettings.asset
  48. 182
      ProjectSettings/QualitySettings.asset.orig
  49. 43
      ProjectSettings/TagManager.asset
  50. 8
      ProjectSettings/TimeManager.asset
  51. 11
      ProjectSettings/UnityAdsSettings.asset
  52. 14
      ProjectSettings/UnityConnectSettings.asset

3
.gitignore


Library/*
Temp/*

9
Assets/ScriptableRenderLoop.meta


fileFormatVersion: 2
guid: 7f2fa2efb8ce343069fc5393536094ad
folderAsset: yes
timeCreated: 1466769773
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

35
Assets/ScriptableRenderLoop/AdditionalLightData.cs


using System;
namespace UnityEngine.ScriptableRenderLoop
{
//@TODO: We should continously move these values
// into the engine when we can see them being generally useful
[RequireComponent(typeof(Light))]
public class AdditionalLightData : MonoBehaviour
{
public const int defaultShadowResolution = 512;
public int shadowResolution = defaultShadowResolution;
[RangeAttribute(0.0F, 100.0F)]
public float innerSpotPercent = 0.0F;
public static float GetInnerSpotPercent01(AdditionalLightData lightData)
{
if (lightData != null)
return Mathf.Clamp( lightData.innerSpotPercent, 0.0f, 100.0f ) / 100.0f;
else
return 0.0F;
}
public static int GetShadowResolution(AdditionalLightData lightData)
{
if (lightData != null)
return lightData.shadowResolution;
else
return defaultShadowResolution;
}
}
}

12
Assets/ScriptableRenderLoop/AdditionalLightData.cs.meta


fileFormatVersion: 2
guid: 7a68c43fe1f2a47cfa234b5eeaa98012
timeCreated: 1467027998
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ForwardRenderLoop.meta


fileFormatVersion: 2
guid: 87cf696b5a0ce42438ce41ddcd5022c2
folderAsset: yes
timeCreated: 1467034984
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

20
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 98fe12104b04e43dd9a963f3f7b26e8e, type: 3}
m_Name: ForwardRenderLoop
m_EditorClassIdentifier:
m_ShadowSettings:
enabled: 1
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
maxShadowDistance: 500
directionalLightCascadeCount: 4
directionalLightCascades: {x: 0.02, y: 0.1, z: 0.6}

8
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.asset.meta


fileFormatVersion: 2
guid: 873753be6b0da44d58b061c5ec3d12bc
timeCreated: 1467028110
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

233
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;
using UnityEditor;
namespace UnityEngine.ScriptableRenderLoop
{
public class ForwardRenderLoop : ScriptableRenderLoop
{
[MenuItem("Renderloop/CreateForwardRenderLoop")]
static void CreateForwardRenderLoop()
{
var instance = ScriptableObject.CreateInstance<ForwardRenderLoop>();
AssetDatabase.CreateAsset(instance, "Assets/forwardrenderloop.asset");
}
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowRenderPass m_ShadowPass;
const int MAX_LIGHTS = 10;
const int MAX_SHADOWMAP_PER_LIGHTS = 6;
const int MAX_DIRECTIONAL_SPLIT = 4;
// Directional lights become spotlights at a far distance. This is the distance we pull back to set the spotlight origin.
const float DIRECTIONAL_LIGHT_PULLBACK_DISTANCE = 10000.0f;
[NonSerialized] private int m_nWarnedTooManyLights = 0;
void OnEnable()
{
Rebuild ();
}
void OnValidate()
{
Rebuild ();
}
void Rebuild()
{
m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdateLightConstants(ActiveLight[] activeLights, ref ShadowOutput shadow)
{
int nNumLightsIncludingTooMany = 0;
int g_nNumLights = 0;
Vector4[] g_vLightColor = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightPosition_flInvRadius = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightDirection = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightShadowIndex_vLightParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightFalloffParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vSpotLightInnerOuterConeCosines = new Vector4[ MAX_LIGHTS ];
Matrix4x4[] g_matWorldToShadow = new Matrix4x4[ MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS ];
Vector4[] g_vDirShadowSplitSpheres = new Vector4[ MAX_DIRECTIONAL_SPLIT ];
for ( int nLight = 0; nLight < activeLights.Length; nLight++ )
{
nNumLightsIncludingTooMany++;
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
continue;
ActiveLight light = activeLights [nLight];
LightType lightType = light.lightType;
Vector3 position = light.light.transform.position;
Vector3 lightDir = light.light.transform.forward.normalized;
AdditionalLightData additionalLightData = light.light.GetComponent<AdditionalLightData> ();
// Setup shadow data arrays
bool hasShadows = shadow.GetShadowSliceCountLightIndex (nLight) != 0;
if ( lightType == LightType.Directional )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4(
position.x - ( lightDir.x * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.y - ( lightDir.y * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.z - ( lightDir.z * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
-1.0f );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, float.MaxValue, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
if (hasShadows)
{
for (int s = 0; s < MAX_DIRECTIONAL_SPLIT; ++s)
{
g_vDirShadowSplitSpheres[s] = shadow.directionalShadowSplitSphereSqr[s];
}
}
}
else if ( lightType == LightType.Point )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, 0.0f );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
}
else if ( lightType == LightType.Spot )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
float flInnerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);
float spotAngle = light.light.spotAngle;
float flPhiDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * Mathf.Deg2Rad ), 0.0f, 1.0f ); // outer cone
float flThetaDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * flInnerConePercent * Mathf.Deg2Rad ), 0.0f, 1.0f ); // inner cone
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( flThetaDot, flPhiDot, 1.0f / Mathf.Max( 0.01f, flThetaDot - flPhiDot ) );
}
if ( hasShadows )
{
// Enable shadows
g_vLightShadowIndex_vLightParams[ g_nNumLights ].x = 1;
for(int s=0; s < shadow.GetShadowSliceCountLightIndex (nLight); ++s)
{
int shadowSliceIndex = shadow.GetShadowSliceIndex (nLight, s);
g_matWorldToShadow [g_nNumLights * MAX_SHADOWMAP_PER_LIGHTS + s] = shadow.shadowSlices[shadowSliceIndex].shadowTransform.transpose;
}
}
g_nNumLights++;
}
// Warn if too many lights found
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
{
if ( nNumLightsIncludingTooMany > m_nWarnedTooManyLights )
{
Debug.LogError( "ERROR! Found " + nNumLightsIncludingTooMany + " runtime lights! Valve renderer supports up to " + MAX_LIGHTS +
" active runtime lights at a time!\nDisabling " + ( nNumLightsIncludingTooMany - MAX_LIGHTS ) + " runtime light" +
( ( nNumLightsIncludingTooMany - MAX_LIGHTS ) > 1 ? "s" : "" ) + "!\n" );
}
m_nWarnedTooManyLights = nNumLightsIncludingTooMany;
}
else
{
if ( m_nWarnedTooManyLights > 0 )
{
m_nWarnedTooManyLights = 0;
Debug.Log( "SUCCESS! Found " + nNumLightsIncludingTooMany + " runtime lights which is within the supported number of lights, " + MAX_LIGHTS + ".\n\n" );
}
}
// Send constants to shaders
Shader.SetGlobalInt( "g_nNumLights", g_nNumLights );
// New method for Unity 5.4 to set arrays of constants
Shader.SetGlobalVectorArray( "g_vLightPosition_flInvRadius", g_vLightPosition_flInvRadius );
Shader.SetGlobalVectorArray( "g_vLightColor", g_vLightColor );
Shader.SetGlobalVectorArray( "g_vLightDirection", g_vLightDirection );
Shader.SetGlobalVectorArray( "g_vLightShadowIndex_vLightParams", g_vLightShadowIndex_vLightParams );
Shader.SetGlobalVectorArray( "g_vLightFalloffParams", g_vLightFalloffParams );
Shader.SetGlobalVectorArray( "g_vSpotLightInnerOuterConeCosines", g_vSpotLightInnerOuterConeCosines );
Shader.SetGlobalMatrixArray( "g_matWorldToShadow", g_matWorldToShadow );
Shader.SetGlobalVectorArray( "g_vDirShadowSplitSpheres", g_vDirShadowSplitSpheres );
// Time
#if ( UNITY_EDITOR )
{
Shader.SetGlobalFloat( "g_flTime", Time.realtimeSinceStartup );
//Debug.Log( "Time " + Time.realtimeSinceStartup );
}
#else
{
Shader.SetGlobalFloat( "g_flTime", Time.timeSinceLevelLoad );
//Debug.Log( "Time " + Time.timeSinceLevelLoad );
}
#endif
// PCF 3x3 Shadows
float flTexelEpsilonX = 1.0f / m_ShadowSettings.shadowAtlasWidth;
float flTexelEpsilonY = 1.0f / m_ShadowSettings.shadowAtlasHeight;
Vector4 g_vShadow3x3PCFTerms0 = new Vector4( 20.0f / 267.0f, 33.0f / 267.0f, 55.0f / 267.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms1 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, -flTexelEpsilonX, -flTexelEpsilonY );
Vector4 g_vShadow3x3PCFTerms2 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, 0.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms3 = new Vector4( -flTexelEpsilonX, -flTexelEpsilonY, 0.0f, 0.0f );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms0", g_vShadow3x3PCFTerms0 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms1", g_vShadow3x3PCFTerms1 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms2", g_vShadow3x3PCFTerms2 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms3", g_vShadow3x3PCFTerms3 );
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
foreach (var camera in cameras)
{
CullResults cullResults;
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters (camera, out cullingParams))
continue;
m_ShadowPass.UpdateCullingParameters (ref cullingParams);
cullResults = CullResults.Cull (ref cullingParams, renderLoop);
ShadowOutput shadows;
m_ShadowPass.Render (renderLoop, cullResults, out shadows);
renderLoop.SetupCameraProperties (camera);
UpdateLightConstants(cullResults.culledLights, ref shadows);
DrawRendererSettings settings = new DrawRendererSettings (cullResults, camera, new ShaderPassName("ForwardBase"));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
renderLoop.DrawRenderers (ref settings);
renderLoop.Submit ();
}
// Post effects
}
}
}

12
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs.meta


fileFormatVersion: 2
guid: 98fe12104b04e43dd9a963f3f7b26e8e
timeCreated: 1467027998
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders.meta


fileFormatVersion: 2
guid: 09f8dae5907a4374a8c827890d14dbbc
folderAsset: yes
timeCreated: 1446119266
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

688
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_lighting.cginc


// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
#ifndef VALVE_VR_LIGHTING_INCLUDED
#define VALVE_VR_LIGHTING_INCLUDED
#include "UnityCG.cginc"
#include "UnityStandardBRDF.cginc"
#define Tex2DLevel( name, uv, flLevel ) name.SampleLevel( sampler##name, ( uv ).xy, flLevel )
#define Tex2DLevelFromSampler( texturename, samplername, uv, flLevel ) texturename.SampleLevel( sampler##samplername, ( uv ).xy, flLevel )
//---------------------------------------------------------------------------------------------------------------------------------------------------------
#define DEBUG_SHADOWS_SPLIT 0
//---------------------------------------------------------------------------------------------------------------------------------------------------------
#define MAX_LIGHTS 10
#define MAX_SHADOWMAP_PER_LIGHTS 6
#define MAX_DIRECTIONAL_SPLIT 4
#define LIGHT_TYPE_SPOT 0
#define LIGHT_TYPE_DIRECTIONAL 1
#define LIGHT_TYPE_POINT 2
#define CUBEMAPFACE_POSITIVE_X 0
#define CUBEMAPFACE_NEGATIVE_X 1
#define CUBEMAPFACE_POSITIVE_Y 2
#define CUBEMAPFACE_NEGATIVE_Y 3
#define CUBEMAPFACE_POSITIVE_Z 4
#define CUBEMAPFACE_NEGATIVE_Z 5
CBUFFER_START(ValveVrLighting)
int g_nNumLights;
bool g_bIndirectLightmaps = false;
float4 g_vLightColor[MAX_LIGHTS];
float4 g_vLightPosition_flInvRadius[MAX_LIGHTS];
float4 g_vLightDirection[MAX_LIGHTS];
float4 g_vLightShadowIndex_vLightParams[MAX_LIGHTS]; // x = Shadow index, y = Light cookie index, z = Diffuse enabled, w = Specular enabled
float4 g_vLightFalloffParams[MAX_LIGHTS]; // x = Linear falloff, y = Quadratic falloff, z = Radius squared for culling, w = type
float4 g_vSpotLightInnerOuterConeCosines[MAX_LIGHTS];
float4 g_vDirShadowSplitSpheres[MAX_DIRECTIONAL_SPLIT];
//float4x4 g_matWorldToLightCookie[ MAX_LIGHTS ];
float4x4 g_matWorldToShadow[MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS];
float4 g_vShadow3x3PCFTerms0;
float4 g_vShadow3x3PCFTerms1;
float4 g_vShadow3x3PCFTerms2;
float4 g_vShadow3x3PCFTerms3;
CBUFFER_END
// Override lightmap
sampler2D g_tOverrideLightmap;
uniform float3 g_vOverrideLightmapScale;
float g_flCubeMapScalar = 1.0;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
struct LightingTerms_t
{
float3 vDiffuse;
float3 vSpecular;
float3 vIndirectDiffuse;
float3 vIndirectSpecular;
float3 vTransmissiveSunlight;
};
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float CalculateGeometricRoughnessFactor(float3 vGeometricNormalWs)
{
float3 vNormalWsDdx = ddx(vGeometricNormalWs.xyz);
float3 vNormalWsDdy = ddy(vGeometricNormalWs.xyz);
float flGeometricRoughnessFactor = pow(saturate(max(dot(vNormalWsDdx.xyz, vNormalWsDdx.xyz), dot(vNormalWsDdy.xyz, vNormalWsDdy.xyz))), 0.333);
return flGeometricRoughnessFactor;
}
float2 AdjustRoughnessByGeometricNormal(float2 vRoughness, float3 vGeometricNormalWs)
{
float flGeometricRoughnessFactor = CalculateGeometricRoughnessFactor(vGeometricNormalWs.xyz);
//if ( Blink( 1.0 ) )
//vRoughness.xy = min( vRoughness.xy + flGeometricRoughnessFactor.xx, float2( 1.0, 1.0 ) );
//else
vRoughness.xy = max(vRoughness.xy, flGeometricRoughnessFactor.xx);
return vRoughness.xy;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
void RoughnessEllipseToScaleAndExp(float2 vRoughness, out float2 o_vDiffuseExponentOut, out float2 o_vSpecularExponentOut, out float2 o_vSpecularScaleOut)
{
o_vDiffuseExponentOut.xy = ((1.0 - vRoughness.xy) * 0.8) + 0.6; // 0.8 and 0.6 are magic numbers
o_vSpecularExponentOut.xy = exp2(pow(float2(1.0, 1.0) - vRoughness.xy, float2(1.5, 1.5)) * float2(14.0, 14.0)); // Outputs 1-16384
o_vSpecularScaleOut.xy = 1.0 - saturate(vRoughness.xy * 0.5); // This is an energy conserving scalar for the roughness exponent.
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
// Used for ( N.H^k ) * ( N.L )
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float BlinnPhongModifiedNormalizationFactor(float k)
{
float flNumer = (k + 2.0) * (k + 4.0);
float flDenom = 8 * (exp2(-k * 0.5) + k);
return flNumer / flDenom;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float DistanceFalloff(float flDistToLightSq, float flLightInvRadius, float2 vFalloffParams)
{
// AV - My approximation to Unity's falloff function (I'll experiment with putting this into a texture later)
return lerp(1.0, (1.0 - pow(flDistToLightSq * flLightInvRadius * flLightInvRadius, 0.175)), vFalloffParams.x);
// AV - This is the VR Aperture Demo falloff function
//flDistToLightSq = max( flDistToLightSq, 8.0f ); // Can't be inside the light source (assuming radius^2 == 8.0f)
//
//float2 vInvRadiusAndInvRadiusSq = float2( flLightInvRadius, flLightInvRadius * flLightInvRadius );
//float2 vLightDistAndLightDistSq = float2( sqrt( flDistToLightSq ), flDistToLightSq );
//
//float flTruncation = dot( vFalloffParams.xy, vInvRadiusAndInvRadiusSq.xy ); // Constant amount to subtract to ensure that the light is zero past the light radius
//float flFalloff = dot( vFalloffParams.xy, vLightDistAndLightDistSq.xy );
//
//return saturate( ( 1.0f / flFalloff ) - flTruncation );
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
// Anisotropic diffuse and specular lighting based on 2D tangent-space axis-aligned roughness
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float4 ComputeDiffuseAndSpecularTerms(bool bDiffuse, bool bSpecular,
float3 vNormalWs, float3 vEllipseUWs, float3 vEllipseVWs, float3 vPositionToLightDirWs, float3 vPositionToCameraDirWs,
float2 vDiffuseExponent, float2 vSpecularExponent, float2 vSpecularScale, float3 vReflectance, float flFresnelExponent)
{
float flNDotL = ClampToPositive(dot(vNormalWs.xyz, vPositionToLightDirWs.xyz));
// Diffuse
float flDiffuseTerm = 0.0;
if (bDiffuse)
{
/* Disabling anisotropic diffuse until we have a need for it. Isotropic diffuse should be enough.
// Project light vector onto each tangent plane
float3 vDiffuseNormalX = vPositionToLightDirWs.xyz - ( vEllipseUWs.xyz * dot( vPositionToLightDirWs.xyz, vEllipseUWs.xyz ) ); // Not normalized on purpose
float3 vDiffuseNormalY = vPositionToLightDirWs.xyz - ( vEllipseVWs.xyz * dot( vPositionToLightDirWs.xyz, vEllipseVWs.xyz ) ); // Not normalized on purpose
float flNDotLX = ClampToPositive( dot( vDiffuseNormalX.xyz, vPositionToLightDirWs.xyz ) );
flNDotLX = pow( flNDotLX, vDiffuseExponent.x * 0.5 );
float flNDotLY = ClampToPositive( dot( vDiffuseNormalY.xyz, vPositionToLightDirWs.xyz ) );
flNDotLY = pow( flNDotLY, vDiffuseExponent.y * 0.5 );
flDiffuseTerm = flNDotLX * flNDotLY;
flDiffuseTerm *= ( ( vDiffuseExponent.x * 0.5 + vDiffuseExponent.y * 0.5 ) + 1.0 ) * 0.5;
flDiffuseTerm *= flNDotL;
//*/
float flDiffuseExponent = (vDiffuseExponent.x + vDiffuseExponent.y) * 0.5;
flDiffuseTerm = pow(flNDotL, flDiffuseExponent) * ((flDiffuseExponent + 1.0) * 0.5);
}
// Specular
float3 vSpecularTerm = float3(0.0, 0.0, 0.0);
[branch] if (bSpecular)
{
float3 vHalfAngleDirWs = normalize(vPositionToLightDirWs.xyz + vPositionToCameraDirWs.xyz);
float flSpecularTerm = 0.0;
#if ( S_ANISOTROPIC_GLOSS ) // Adds 34 asm instructions compared to isotropic spec in #else below
{
float3 vSpecularNormalX = vHalfAngleDirWs.xyz - (vEllipseUWs.xyz * dot(vHalfAngleDirWs.xyz, vEllipseUWs.xyz)); // Not normalized on purpose
float3 vSpecularNormalY = vHalfAngleDirWs.xyz - (vEllipseVWs.xyz * dot(vHalfAngleDirWs.xyz, vEllipseVWs.xyz)); // Not normalized on purpose
float flNDotHX = ClampToPositive(dot(vSpecularNormalX.xyz, vHalfAngleDirWs.xyz));
float flNDotHkX = pow(flNDotHX, vSpecularExponent.x * 0.5);
flNDotHkX *= vSpecularScale.x;
float flNDotHY = ClampToPositive(dot(vSpecularNormalY.xyz, vHalfAngleDirWs.xyz));
float flNDotHkY = pow(flNDotHY, vSpecularExponent.y * 0.5);
flNDotHkY *= vSpecularScale.y;
flSpecularTerm = flNDotHkX * flNDotHkY;
}
#else
{
float flNDotH = saturate(dot(vNormalWs.xyz, vHalfAngleDirWs.xyz));
float flNDotHk = pow(flNDotH, dot(vSpecularExponent.xy, float2(0.5, 0.5)));
flNDotHk *= dot(vSpecularScale.xy, float2(0.33333, 0.33333)); // The 0.33333 is to match the spec of the aniso algorithm above with isotropic roughness values
flSpecularTerm = flNDotHk;
}
#endif
flSpecularTerm *= flNDotL; // This makes it modified Blinn-Phong
flSpecularTerm *= BlinnPhongModifiedNormalizationFactor(vSpecularExponent.x * 0.5 + vSpecularExponent.y * 0.5);
float flLDotH = ClampToPositive(dot(vPositionToLightDirWs.xyz, vHalfAngleDirWs.xyz));
float3 vMaxReflectance = vReflectance.rgb / (Luminance(vReflectance.rgb) + 0.0001);
float3 vFresnel = lerp(vReflectance.rgb, vMaxReflectance.rgb, pow(1.0 - flLDotH, flFresnelExponent));
vSpecularTerm.rgb = flSpecularTerm * vFresnel.rgb;
}
return float4(flDiffuseTerm, vSpecularTerm.rgb);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Filter weights: 20 33 20
// 33 55 33
// 20 33 20
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#define VALVE_DECLARE_SHADOWMAP( tex ) Texture2D tex; SamplerComparisonState sampler##tex
#define VALVE_SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, (coord).z )
VALVE_DECLARE_SHADOWMAP(g_tShadowBuffer);
float ComputeShadow_PCF_3x3_Gaussian(float3 vPositionWs, float4x4 matWorldToShadow)
{
float4 vPositionTextureSpace = mul(float4(vPositionWs.xyz, 1.0), matWorldToShadow);
vPositionTextureSpace.xyz /= vPositionTextureSpace.w;
float2 shadowMapCenter = vPositionTextureSpace.xy;
//if ( ( frac( shadowMapCenter.x ) != shadowMapCenter.x ) || ( frac( shadowMapCenter.y ) != shadowMapCenter.y ) )
if ((shadowMapCenter.x < 0.0f) || (shadowMapCenter.x > 1.0f) || (shadowMapCenter.y < 0.0f) || (shadowMapCenter.y > 1.0f))
return 1.0f;
//float objDepth = saturate( vPositionTextureSpace.z - 0.000001 );
float objDepth = (vPositionTextureSpace.z);
/* // Depth texture visualization
if ( 1 )
{
#define NUM_SAMPLES 128.0
float flSum = 0.0;
for ( int j = 0; j < NUM_SAMPLES; j++ )
{
flSum += ( 1.0 / NUM_SAMPLES ) * ( VALVE_SAMPLE_SHADOW( g_tShadowBuffer, float3( shadowMapCenter.xy, j / NUM_SAMPLES ) ).r );
}
return flSum;
}
//*/
//float flTexelEpsilonX = 1.0 / 4096.0;
//float flTexelEpsilonY = 1.0 / 4096.0;
//g_vShadow3x3PCFTerms0 = float4( 20.0 / 267.0, 33.0 / 267.0, 55.0 / 267.0, 0.0 );
//g_vShadow3x3PCFTerms1 = float4( flTexelEpsilonX, flTexelEpsilonY, -flTexelEpsilonX, -flTexelEpsilonY );
//g_vShadow3x3PCFTerms2 = float4( flTexelEpsilonX, flTexelEpsilonY, 0.0, 0.0 );
//g_vShadow3x3PCFTerms3 = float4( -flTexelEpsilonX, -flTexelEpsilonY, 0.0, 0.0 );
float4 v20Taps;
v20Taps.x = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms1.xy, objDepth)).x; // 1 1
v20Taps.y = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms1.zy, objDepth)).x; // -1 1
v20Taps.z = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms1.xw, objDepth)).x; // 1 -1
v20Taps.w = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms1.zw, objDepth)).x; // -1 -1
float flSum = dot(v20Taps.xyzw, float4(0.25, 0.25, 0.25, 0.25));
if ((flSum == 0.0) || (flSum == 1.0))
return flSum;
flSum *= g_vShadow3x3PCFTerms0.x * 4.0;
float4 v33Taps;
v33Taps.x = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms2.xz, objDepth)).x; // 1 0
v33Taps.y = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms3.xz, objDepth)).x; // -1 0
v33Taps.z = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms3.zy, objDepth)).x; // 0 -1
v33Taps.w = VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy + g_vShadow3x3PCFTerms2.zy, objDepth)).x; // 0 1
flSum += dot(v33Taps.xyzw, g_vShadow3x3PCFTerms0.yyyy);
flSum += VALVE_SAMPLE_SHADOW(g_tShadowBuffer, float3(shadowMapCenter.xy, objDepth)).x * g_vShadow3x3PCFTerms0.z;
return flSum;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float3 ComputeOverrideLightmap(float2 vLightmapUV)
{
float4 vLightmapTexel = tex2D(g_tOverrideLightmap, vLightmapUV.xy);
// This path looks over-saturated
//return g_vOverrideLightmapScale * ( unity_Lightmap_HDR.x * pow( vLightmapTexel.a, unity_Lightmap_HDR.y ) ) * vLightmapTexel.rgb;
// This path looks less broken
return g_vOverrideLightmapScale * (unity_Lightmap_HDR.x * vLightmapTexel.a) * sqrt(vLightmapTexel.rgb);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* Gets the cascade weights based on the world position of the fragment and the positions of the split spheres for each cascade.
* Returns an invalid split index if past shadowDistance (ie 4 is invalid for cascade)
*/
float GetSplitSphereIndexForDirshadows(float3 wpos)
{
float3 fromCenter0 = wpos.xyz - g_vDirShadowSplitSpheres[0].xyz;
float3 fromCenter1 = wpos.xyz - g_vDirShadowSplitSpheres[1].xyz;
float3 fromCenter2 = wpos.xyz - g_vDirShadowSplitSpheres[2].xyz;
float3 fromCenter3 = wpos.xyz - g_vDirShadowSplitSpheres[3].xyz;
float4 distances2 = float4(dot(fromCenter0, fromCenter0), dot(fromCenter1, fromCenter1), dot(fromCenter2, fromCenter2), dot(fromCenter3, fromCenter3));
float4 vDirShadowSplitSphereSqRadii;
vDirShadowSplitSphereSqRadii.x = g_vDirShadowSplitSpheres[0].w;
vDirShadowSplitSphereSqRadii.y = g_vDirShadowSplitSpheres[1].w;
vDirShadowSplitSphereSqRadii.z = g_vDirShadowSplitSpheres[2].w;
vDirShadowSplitSphereSqRadii.w = g_vDirShadowSplitSpheres[3].w;
fixed4 weights = float4(distances2 < vDirShadowSplitSphereSqRadii);
weights.yzw = saturate(weights.yzw - weights.xyz);
return 4 - dot(weights, float4(4, 3, 2, 1));
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
void OverrideLightColorWithSplitDebugInfo(inout float3 lightColor, int shadowSplitIndex)
{
#if DEBUG_SHADOWS_SPLIT
// Slightly intensified colors of ShadowCascadeSplitGUI + 2 new for point light (ie splitIndex 4 and 5)
const fixed3 kSplitColors[6] =
{
fixed3(0.5, 0.5, 0.7),
fixed3(0.5, 0.7, 0.5),
fixed3(0.7, 0.7, 0.5),
fixed3(0.7, 0.5, 0.5),
fixed3(0.7, 0.5, 0.7),
fixed3(0.5, 0.7, 0.7),
};
lightColor = kSplitColors[shadowSplitIndex];
#endif
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
LightingTerms_t ComputeLighting(float3 vPositionWs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs, float2 vRoughness,
float3 vReflectance, float flFresnelExponent, float4 vLightmapUV)
{
LightingTerms_t o;
o.vDiffuse = float3(0.0, 0.0, 0.0);
o.vSpecular = float3(0.0, 0.0, 0.0);
o.vIndirectDiffuse = float3(0.0, 0.0, 0.0);
o.vIndirectSpecular = float3(0.0, 0.0, 0.0);
o.vTransmissiveSunlight = float3(0.0, 0.0, 0.0);
// Convert roughness to scale and exp
float2 vDiffuseExponent;
float2 vSpecularExponent;
float2 vSpecularScale;
RoughnessEllipseToScaleAndExp(vRoughness.xy, vDiffuseExponent.xy, vSpecularExponent.xy, vSpecularScale.xy);
// Get positions between the clip planes of the frustum in 0..1 coordinates
//float3 vPositionCs = float3( vPosition4Cs.xy / vPosition4Cs.w, vPosition4Cs.z );
//vPositionCs.xy = ( vPositionCs.xy * 0.5 ) + 0.5;
float3 vPositionToCameraDirWs = CalculatePositionToCameraDirWs(vPositionWs.xyz);
// Compute tangent frame relative to per-pixel normal
float3 vEllipseUWs = normalize(cross(vTangentVWs.xyz, vNormalWs.xyz));
float3 vEllipseVWs = normalize(cross(vNormalWs.xyz, vTangentUWs.xyz));
//-------------------------------------//
// Point, spot, and directional lights //
//-------------------------------------//
int nNumLightsUsed = 0;
[loop] for (int i = 0; i < g_nNumLights; i++)
{
float3 vPositionToLightRayWs = g_vLightPosition_flInvRadius[i].xyz - vPositionWs.xyz;
float flDistToLightSq = dot(vPositionToLightRayWs.xyz, vPositionToLightRayWs.xyz);
if (flDistToLightSq > g_vLightFalloffParams[i].z) // .z stores radius squared of light
{
// Outside light range
continue;
}
if (dot(vNormalWs.xyz, vPositionToLightRayWs.xyz) <= 0.0)
{
// Backface cull pixel to this light
continue;
}
float3 vPositionToLightDirWs = normalize(vPositionToLightRayWs.xyz);
float flOuterConeCos = g_vSpotLightInnerOuterConeCosines[i].y;
float flTemp = dot(vPositionToLightDirWs.xyz, -g_vLightDirection[i].xyz) - flOuterConeCos;
if (flTemp <= 0.0)
{
// Outside spotlight cone
continue;
}
float3 vSpotAtten = saturate(flTemp * g_vSpotLightInnerOuterConeCosines[i].z).xxx;
nNumLightsUsed++;
//[branch] if ( g_vLightShadowIndex_vLightParams[ i ].y != 0 ) // If has light cookie
//{
// // Light cookie
// float4 vPositionTextureSpace = mul( float4( vPositionWs.xyz, 1.0 ), g_matWorldToLightCookie[ i ] );
// vPositionTextureSpace.xyz /= vPositionTextureSpace.w;
// vSpotAtten.rgb = Tex3DLevel( g_tVrLightCookieTexture, vPositionTextureSpace.xyz, 0.0 ).rgb;
//}
float flLightFalloff = DistanceFalloff(flDistToLightSq, g_vLightPosition_flInvRadius[i].w, g_vLightFalloffParams[i].xy);
float flShadowScalar = 1.0;
int shadowSplitIndex = 0;
if (g_vLightShadowIndex_vLightParams[i].x != 0.0)
{
if (g_vLightFalloffParams[i].w == LIGHT_TYPE_DIRECTIONAL)
{
shadowSplitIndex = GetSplitSphereIndexForDirshadows(vPositionWs);
}
if (g_vLightFalloffParams[i].w == LIGHT_TYPE_POINT)
{
float3 absPos = abs(vPositionToLightDirWs);
shadowSplitIndex = (vPositionToLightDirWs.z > 0) ? CUBEMAPFACE_NEGATIVE_Z : CUBEMAPFACE_POSITIVE_Z;
if (absPos.x > absPos.y)
{
if (absPos.x > absPos.z)
{
shadowSplitIndex = (vPositionToLightDirWs.x > 0) ? CUBEMAPFACE_NEGATIVE_X : CUBEMAPFACE_POSITIVE_X;
}
}
else
{
if (absPos.y > absPos.z)
{
shadowSplitIndex = (vPositionToLightDirWs.y > 0) ? CUBEMAPFACE_NEGATIVE_Y : CUBEMAPFACE_POSITIVE_Y;
}
}
}
flShadowScalar = ComputeShadow_PCF_3x3_Gaussian(vPositionWs.xyz, g_matWorldToShadow[i * MAX_SHADOWMAP_PER_LIGHTS + shadowSplitIndex]);
if (flShadowScalar <= 0.0)
continue;
}
float4 vLightingTerms = ComputeDiffuseAndSpecularTerms(g_vLightShadowIndex_vLightParams[i].z != 0.0, g_vLightShadowIndex_vLightParams[i].w != 0.0,
vNormalWs.xyz, vEllipseUWs.xyz, vEllipseVWs.xyz,
vPositionToLightDirWs.xyz, vPositionToCameraDirWs.xyz,
vDiffuseExponent.xy, vSpecularExponent.xy, vSpecularScale.xy, vReflectance.rgb, flFresnelExponent);
float3 vLightColor = g_vLightColor[i].rgb;
OverrideLightColorWithSplitDebugInfo(vLightColor, shadowSplitIndex);
float3 vLightMask = vLightColor.rgb * flShadowScalar * flLightFalloff * vSpotAtten.rgb;
o.vDiffuse.rgb += vLightingTerms.xxx * vLightMask.rgb;
o.vSpecular.rgb += vLightingTerms.yzw * vLightMask.rgb;
}
/* // Visualize number of lights for the first 7 as RGBCMYW
if ( nNumLightsUsed == 0 )
o.vDiffuse.rgb = float3( 0.0, 0.0, 0.0 );
else if ( nNumLightsUsed == 1 )
o.vDiffuse.rgb = float3( 1.0, 0.0, 0.0 );
else if ( nNumLightsUsed == 2 )
o.vDiffuse.rgb = float3( 0.0, 1.0, 0.0 );
else if ( nNumLightsUsed == 3 )
o.vDiffuse.rgb = float3( 0.0, 0.0, 1.0 );
else if ( nNumLightsUsed == 4 )
o.vDiffuse.rgb = float3( 0.0, 1.0, 1.0 );
else if ( nNumLightsUsed == 5 )
o.vDiffuse.rgb = float3( 1.0, 0.0, 1.0 );
else if ( nNumLightsUsed == 6 )
o.vDiffuse.rgb = float3( 1.0, 1.0, 0.0 );
else
o.vDiffuse.rgb = float3( 1.0, 1.0, 1.0 );
o.vDiffuse.rgb *= float3( 2.0, 2.0, 2.0 );
o.vSpecular.rgb = float3( 0.0, 0.0, 0.0 );
return o;
//*/
// Apply specular reflectance to diffuse term (specular term already accounts for this in the fresnel equation)
o.vDiffuse.rgb *= (float3(1.0, 1.0, 1.0) - vReflectance.rgb);
//------------------//
// Indirect diffuse //
//------------------//
#if ( S_OVERRIDE_LIGHTMAP )
{
o.vIndirectDiffuse.rgb += ComputeOverrideLightmap(vLightmapUV.xy);
}
#elif ( LIGHTMAP_ON )
{
// Baked lightmaps
float4 bakedColorTex = Tex2DLevel(unity_Lightmap, vLightmapUV.xy, 0.0);
float3 bakedColor = DecodeLightmap(bakedColorTex);
#if ( DIRLIGHTMAP_OFF ) // Directional Mode = Non Directional
{
o.vIndirectDiffuse.rgb += bakedColor.rgb;
//o_gi.indirect.diffuse = bakedColor;
//
//#ifdef SHADOWS_SCREEN
// o_gi.indirect.diffuse = MixLightmapWithRealtimeAttenuation (o_gi.indirect.diffuse, data.atten, bakedColorTex);
//#endif // SHADOWS_SCREEN
}
#elif ( DIRLIGHTMAP_COMBINED ) // Directional Mode = Directional
{
//o.vIndirectDiffuse.rgb = float3( 0.0, 1.0, 0.0 );
float4 bakedDirTex = Tex2DLevelFromSampler(unity_LightmapInd, unity_Lightmap, vLightmapUV.xy, 0.0);
//float flHalfLambert = dot( vNormalWs.xyz, bakedDirTex.xyz - 0.5 ) + 0.5;
//o.vIndirectDiffuse.rgb += bakedColor.rgb * flHalfLambert / bakedDirTex.w;
float flHalfLambert = dot(vNormalWs.xyz, normalize(bakedDirTex.xyz - 0.5));// + ( 1.0 - length( bakedDirTex.xyz - 0.5 ) );
o.vIndirectDiffuse.rgb += bakedColor.rgb * flHalfLambert / (bakedDirTex.w);
//#ifdef SHADOWS_SCREEN
// o_gi.indirect.diffuse = MixLightmapWithRealtimeAttenuation (o_gi.indirect.diffuse, data.atten, bakedColorTex);
//#endif // SHADOWS_SCREEN
}
#elif ( DIRLIGHTMAP_SEPARATE ) // Directional Mode = Directional Specular
{
// Left halves of both intensity and direction lightmaps store direct light; right halves store indirect.
float2 vUvDirect = vLightmapUV.xy;
float2 vUvIndirect = vLightmapUV.xy + float2(0.5, 0.0);
// Direct Diffuse
float4 bakedDirTex = float4(0.0, 0.0, 0.0, 0.0);
if (!g_bIndirectLightmaps)
{
bakedDirTex = Tex2DLevelFromSampler(unity_LightmapInd, unity_Lightmap, vUvDirect.xy, 0.0);
//float flHalfLambert = dot( vNormalWs.xyz, bakedDirTex.xyz - 0.5 ) + 0.5;
//o.vDiffuse.rgb += bakedColor.rgb * flHalfLambert / bakedDirTex.w;
float flHalfLambert = ClampToPositive(dot(vNormalWs.xyz, normalize(bakedDirTex.xyz - 0.5)));// + ( 1.0 - length( bakedDirTex.xyz - 0.5 ) );
o.vDiffuse.rgb += bakedColor.rgb * flHalfLambert / (bakedDirTex.w);
}
// Indirect Diffuse
float4 bakedIndirTex = float4(0.0, 0.0, 0.0, 0.0);
float3 vBakedIndirectColor = float3(0.0, 0.0, 0.0);
if (1)
{
vBakedIndirectColor.rgb = DecodeLightmap(Tex2DLevel(unity_Lightmap, vUvIndirect.xy, 0.0));
bakedIndirTex = Tex2DLevelFromSampler(unity_LightmapInd, unity_Lightmap, vUvIndirect.xy, 0.0);
//float flHalfLambert = dot( vNormalWs.xyz, bakedIndirTex.xyz - 0.5 ) + 0.5;
//o.vIndirectDiffuse.rgb += vBakedIndirectColor.rgb * flHalfLambert / bakedIndirTex.w;
float flHalfLambert = dot(vNormalWs.xyz, normalize(bakedIndirTex.xyz - 0.5));// + ( 1.0 - length( bakedIndirTex.xyz - 0.5 ) );
o.vIndirectDiffuse.rgb += vBakedIndirectColor.rgb * flHalfLambert / (bakedIndirTex.w);
}
// Direct Specular
if (!g_bIndirectLightmaps)
{
UnityLight o_light;
o.vIndirectDiffuse.rgb += DecodeDirectionalSpecularLightmap(bakedColor, bakedDirTex, vNormalWs, false, 0, o_light);
float4 vLightingTerms = ComputeDiffuseAndSpecularTerms(false, true,
vNormalWs.xyz, vEllipseUWs.xyz, vEllipseVWs.xyz,
o_light.dir.xyz, vPositionToCameraDirWs.xyz,
vDiffuseExponent.xy, vSpecularExponent.xy, vSpecularScale.xy, vReflectance.rgb, flFresnelExponent);
float3 vLightColor = o_light.color;
float3 vLightMask = vLightColor.rgb;
o.vSpecular.rgb += vLightingTerms.yzw * vLightMask.rgb;
}
// Indirect Specular
//if ( 1 )
//{
// UnityLight o_light;
// o.vIndirectSpecular.rgb += DecodeDirectionalSpecularLightmap( vBakedIndirectColor, bakedIndirTex, vNormalWs, false, 0, o_light );
//}
}
#endif
}
#elif ( UNITY_SHOULD_SAMPLE_SH )
{
// Light probe
o.vIndirectDiffuse.rgb += ShadeSH9(float4(vNormalWs.xyz, 1.0));
}
#endif
#if ( DYNAMICLIGHTMAP_ON )
{
float4 realtimeColorTex = Tex2DLevel(unity_DynamicLightmap, vLightmapUV.zw, 0.0);
float3 realtimeColor = DecodeRealtimeLightmap(realtimeColorTex);
#if ( DIRLIGHTMAP_OFF )
{
o.vIndirectDiffuse.rgb += realtimeColor.rgb;
}
#elif ( DIRLIGHTMAP_COMBINED )
{
float4 realtimeDirTex = Tex2DLevelFromSampler(unity_DynamicDirectionality, unity_DynamicLightmap, vLightmapUV.zw, 0.0);
o.vIndirectDiffuse.rgb += DecodeDirectionalLightmap(realtimeColor, realtimeDirTex, vNormalWs);
}
#elif ( DIRLIGHTMAP_SEPARATE )
{
float4 realtimeDirTex = Tex2DLevelFromSampler(unity_DynamicDirectionality, unity_DynamicLightmap, vLightmapUV.zw, 0.0);
o.vIndirectDiffuse.rgb += DecodeDirectionalLightmap(realtimeColor, realtimeDirTex, vNormalWs);
UnityLight o_light;
float4 realtimeNormalTex = Tex2DLevelFromSampler(unity_DynamicNormal, unity_DynamicLightmap, vLightmapUV.zw, 0.0);
o.vIndirectSpecular.rgb += DecodeDirectionalSpecularLightmap(realtimeColor, realtimeDirTex, vNormalWs, true, realtimeNormalTex, o_light);
float4 vLightingTerms = ComputeDiffuseAndSpecularTerms(false, true,
vNormalWs.xyz, vEllipseUWs.xyz, vEllipseVWs.xyz,
o_light.dir.xyz, vPositionToCameraDirWs.xyz,
vDiffuseExponent.xy, vSpecularExponent.xy, vSpecularScale.xy, vReflectance.rgb, flFresnelExponent);
float3 vLightColor = o_light.color;
float3 vLightMask = vLightColor.rgb;
o.vSpecular.rgb += vLightingTerms.yzw * vLightMask.rgb;
}
#endif
}
#endif
//-------------------//
// Indirect specular //
//-------------------//
#if ( 1 )
{
float flRoughness = dot(vRoughness.xy, float2(0.5, 0.5));
float3 vReflectionDirWs = CalculateCameraReflectionDirWs(vPositionWs.xyz, vNormalWs.xyz);
float3 vReflectionDirWs0 = vReflectionDirWs.xyz;
#if ( UNITY_SPECCUBE_BOX_PROJECTION )
{
vReflectionDirWs0.xyz = BoxProjectedCubemapDirection(vReflectionDirWs.xyz, vPositionWs.xyz, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
}
#endif
float3 vEnvMap0 = max(0.0, Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, vReflectionDirWs0, flRoughness));
#if ( 0 )
{
const float flBlendFactor = 0.99999;
float flBlendLerp = saturate(unity_SpecCube0_BoxMin.w);
UNITY_BRANCH
if (flBlendLerp < flBlendFactor)
{
float3 vReflectionDirWs1 = vReflectionDirWs.xyz;
#if ( UNITY_SPECCUBE_BOX_PROJECTION )
{
vReflectionDirWs1.xyz = BoxProjectedCubemapDirection(vReflectionDirWs.xyz, vPositionWs.xyz, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
}
#endif
float3 vEnvMap1 = max(0.0, Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube1), unity_SpecCube1_HDR, vReflectionDirWs1, flRoughness));
o.vIndirectSpecular.rgb += lerp(vEnvMap1.rgb, vEnvMap0.rgb, flBlendLerp);
}
else
{
o.vIndirectSpecular.rgb += vEnvMap0.rgb;
}
}
#else
{
o.vIndirectSpecular.rgb += vEnvMap0.rgb;
}
#endif
}
#endif
// Apply fresnel to indirect specular
float flVDotN = saturate(dot(vPositionToCameraDirWs.xyz, vNormalWs.xyz));
float3 vMaxReflectance = vReflectance.rgb / (Luminance(vReflectance.rgb) + 0.0001);
float3 vFresnel = lerp(vReflectance.rgb, vMaxReflectance.rgb, pow(1.0 - flVDotN, flFresnelExponent));
o.vIndirectSpecular.rgb *= vFresnel.rgb;
o.vIndirectSpecular.rgb *= g_flCubeMapScalar; // !!! FIXME: This also contains lightmap spec
// Since we have indirect specular, apply reflectance to indirect diffuse
o.vIndirectDiffuse.rgb *= (float3(1.0, 1.0, 1.0) - vReflectance.rgb);
return o;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
LightingTerms_t ComputeLightingDiffuseOnly(float3 vPositionWs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs, float2 vRoughness, float4 vLightmapUV)
{
LightingTerms_t lightingTerms = ComputeLighting(vPositionWs, vNormalWs, vTangentUWs, vTangentVWs, vRoughness, 0.0, 1.0, vLightmapUV.xyzw);
lightingTerms.vSpecular = float3(0.0, 0.0, 0.0);
lightingTerms.vIndirectSpecular = float3(0.0, 0.0, 0.0);
return lightingTerms;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float3 CubeMapBoxProjection(float3 vPositionCubemapLocal, float3 vNormalCubemapLocal, float3 vCameraPositionCubemapLocal, float3 vBoxMins, float3 vBoxMaxs)
{
float3 vCameraToPositionRayCubemapLocal = vPositionCubemapLocal.xyz - vCameraPositionCubemapLocal.xyz;
float3 vCameraToPositionRayReflectedCubemapLocal = reflect(vCameraToPositionRayCubemapLocal.xyz, vNormalCubemapLocal.xyz);
float3 vIntersectA = (vBoxMaxs.xyz - vPositionCubemapLocal.xyz) / vCameraToPositionRayReflectedCubemapLocal.xyz;
float3 vIntersectB = (vBoxMins.xyz - vPositionCubemapLocal.xyz) / vCameraToPositionRayReflectedCubemapLocal.xyz;
float3 vIntersect = max(vIntersectA.xyz, vIntersectB.xyz);
float flDistance = min(vIntersect.x, min(vIntersect.y, vIntersect.z));
float3 vReflectDirectionWs = vPositionCubemapLocal.xyz + vCameraToPositionRayReflectedCubemapLocal.xyz * flDistance;
return vReflectDirectionWs;
}
#endif

9
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_lighting.cginc.meta


fileFormatVersion: 2
guid: dcd79a5cd543fa845a8137749d9df096
timeCreated: 1442663113
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

634
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_standard.shader


// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
Shader "Valve/vr_standard"
{
Properties
{
[Toggle( S_UNLIT )] g_bUnlit( "g_bUnlit", Int ) = 0
_Color( "Color", Color ) = ( 1, 1, 1, 1 )
_MainTex( "Albedo", 2D ) = "white" {}
_Cutoff( "Alpha Cutoff", Range( 0.0, 1.0 ) ) = 0.5
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular", Color) = (0.2,0.2,0.2)
_SpecGlossMap("Specular", 2D) = "white" {}
g_flReflectanceMin( "g_flReflectanceMin", Range( 0.0, 1.0 ) ) = 0.0
g_flReflectanceMax( "g_flReflectanceMax", Range( 0.0, 1.0 ) ) = 1.0
[HideInInspector] g_flReflectanceScale( "g_flReflectanceScale", Range( 0.0, 1.0 ) ) = 0.0
[HideInInspector] g_flReflectanceBias( "g_flReflectanceBias", Range( 0.0, 1.0 ) ) = 1.0
[Gamma] _Metallic( "Metallic", Range( 0.0, 1.0 ) ) = 0.0
_MetallicGlossMap( "Metallic", 2D ) = "white" {}
_BumpScale( "Scale", Float ) = 1.0
[Normal] _BumpMap( "Normal Map", 2D ) = "bump" {}
_Parallax ( "Height Scale", Range ( 0.005, 0.08 ) ) = 0.02
_ParallaxMap ( "Height Map", 2D ) = "black" {}
_OcclusionStrength( "Strength", Range( 0.0, 1.0 ) ) = 1.0
_OcclusionMap( "Occlusion", 2D ) = "white" {}
_OcclusionStrengthDirectDiffuse( "StrengthDirectDiffuse", Range( 0.0, 1.0 ) ) = 1.0
_OcclusionStrengthDirectSpecular( "StrengthDirectSpecular", Range( 0.0, 1.0 ) ) = 1.0
_OcclusionStrengthIndirectDiffuse( "StrengthIndirectDiffuse", Range( 0.0, 1.0 ) ) = 1.0
_OcclusionStrengthIndirectSpecular( "StrengthIndirectSpecular", Range( 0.0, 1.0 ) ) = 1.0
g_flCubeMapScalar( "Cube Map Scalar", Range( 0.0, 2.0 ) ) = 1.0
_EmissionColor( "Color", Color ) = ( 0, 0, 0 )
_EmissionMap( "Emission", 2D ) = "white" {}
_DetailMask( "Detail Mask", 2D ) = "white" {}
_DetailAlbedoMap( "Detail Albedo x2", 2D ) = "grey" {}
_DetailNormalMapScale( "Scale", Float ) = 1.0
_DetailNormalMap( "Normal Map", 2D ) = "bump" {}
g_tOverrideLightmap( "Override Lightmap", 2D ) = "white" {}
[Enum(UV0,0,UV1,1)] _UVSec ( "UV Set for secondary textures", Float ) = 0
[Toggle( S_WORLD_ALIGNED_TEXTURE )] g_bWorldAlignedTexture( "g_bWorldAlignedTexture", Int ) = 0
g_vWorldAlignedTextureSize( "g_vWorldAlignedTextureSize", Vector ) = ( 1.0, 1.0, 1.0, 0.0 )
g_vWorldAlignedTextureNormal( "g_vWorldAlignedTextureNormal", Vector ) = ( 0.0, 1.0, 0.0, 0.0 )
g_vWorldAlignedTexturePosition( "g_vWorldAlignedTexturePosition", Vector ) = ( 0.0, 0.0, 0.0, 0.0 )
[HideInInspector] g_vWorldAlignedNormalTangentU( "g_vWorldAlignedNormalTangentU", Vector ) = ( -1.0, 0.0, 0.0, 0.0)
[HideInInspector] g_vWorldAlignedNormalTangentV( "g_vWorldAlignedNormalTangentV", Vector ) = ( 0.0, 0.0, 1.0, 0.0)
//g_tShadowBuffer( "g_tShadowBuffer", 2D ) = "white" {}
[HideInInspector] _SpecularMode( "__specularmode", Int ) = 1.0
// Blending state
[HideInInspector] _Mode ( "__mode", Float ) = 0.0
[HideInInspector] _SrcBlend ( "__src", Float ) = 1.0
[HideInInspector] _DstBlend ( "__dst", Float ) = 0.0
[HideInInspector] _ZWrite ( "__zw", Float ) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "PerformanceChecks" = "False" }
LOD 300
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
CGPROGRAM
#pragma target 4.0
//#pragma only_renderers d3d11
//#pragma exclude_renderers gles
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _NORMALMAP
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _EMISSION
#pragma shader_feature _DETAIL_MULX2
//#pragma shader_feature _PARALLAXMAP
#pragma shader_feature S_SPECULAR_NONE S_SPECULAR_BLINNPHONG S_SPECULAR_METALLIC
#pragma shader_feature S_UNLIT
#pragma shader_feature S_OVERRIDE_LIGHTMAP
#pragma shader_feature S_WORLD_ALIGNED_TEXTURE
#pragma shader_feature S_OCCLUSION
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile _ D_HOLOGRAM_FX
#pragma skip_variants SHADOWS_SOFT
#pragma vertex MainVs
#pragma fragment MainPs
// Dynamic combo skips (Static combo skips happen in ValveShaderGUI.cs in SetMaterialKeywords())
#if ( S_UNLIT )
#undef LIGHTMAP_OFF
#define LIGHTMAP_OFF 1
#undef LIGHTMAP_ON
#undef DIRLIGHTMAP_OFF
#define DIRLIGHTMAP_OFF 1
#undef DIRLIGHTMAP_COMBINED
#undef DIRLIGHTMAP_SEPARATE
#undef DYNAMICLIGHTMAP_OFF
#define DYNAMICLIGHTMAP_OFF 1
#undef DYNAMICLIGHTMAP_ON
#endif
// Includes -------------------------------------------------------------------------------------------------------------------------------------------------
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
#include "UnityStandardUtils.cginc"
#include "UnityStandardInput.cginc"
#include "vr_utils.cginc"
#include "vr_lighting.cginc"
// Structs --------------------------------------------------------------------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 vPositionOs : POSITION;
float3 vNormalOs : NORMAL;
float2 vTexCoord0 : TEXCOORD0;
#if ( _DETAIL || S_OVERRIDE_LIGHTMAP || LIGHTMAP_ON )
float2 vTexCoord1 : TEXCOORD1;
#endif
#if ( DYNAMICLIGHTMAP_ON || UNITY_PASS_META )
float2 vTexCoord2 : TEXCOORD2;
#endif
#if ( _NORMALMAP )
float4 vTangentUOs_flTangentVSign : TANGENT;
#endif
};
struct PS_INPUT
{
float4 vPositionPs : SV_Position;
#if ( !S_UNLIT || D_HOLOGRAM_FX )
float3 vPositionWs : TEXCOORD0;
float3 vNormalWs : TEXCOORD1;
#endif
#if ( _DETAIL )
float4 vTextureCoords : TEXCOORD2;
#else
float2 vTextureCoords : TEXCOORD2;
#endif
#if ( S_OVERRIDE_LIGHTMAP || LIGHTMAP_ON || DYNAMICLIGHTMAP_ON )
#if ( DYNAMICLIGHTMAP_ON )
centroid float4 vLightmapUV : TEXCOORD3;
#else
centroid float2 vLightmapUV : TEXCOORD3;
#endif
#endif
#if ( _NORMALMAP )
float3 vTangentUWs : TEXCOORD4;
float3 vTangentVWs : TEXCOORD5;
#endif
};
// World-aligned texture
float3 g_vWorldAlignedTextureSize = float3( 1.0, 1.0, 1.0 );
float3 g_vWorldAlignedNormalTangentU = float3( -1.0, 0.0, 0.0 );
float3 g_vWorldAlignedNormalTangentV = float3( 0.0, 0.0, 1.0 );
float3 g_vWorldAlignedTexturePosition = float3( 0.0, 0.0, 0.0 );
uniform sampler3D g_tHologramNoise3D;
float3 g_vHologramTransmissionSource;
float g_flHologramTransmissionDistance;
float g_flHologramTransmissionFrontier;
// MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
PS_INPUT MainVs( VS_INPUT i )
{
PS_INPUT o = ( PS_INPUT )0;
// Position
float3 vPositionWs = mul( unity_ObjectToWorld, i.vPositionOs.xyzw ).xyz;
#if ( !S_UNLIT || D_HOLOGRAM_FX )
{
o.vPositionWs.xyz = vPositionWs.xyz;
}
#endif
o.vPositionPs.xyzw = mul( UNITY_MATRIX_MVP, i.vPositionOs.xyzw );
// Normal
float3 vNormalWs = UnityObjectToWorldNormal( i.vNormalOs.xyz );
#if ( !S_UNLIT || D_HOLOGRAM_FX )
{
o.vNormalWs.xyz = vNormalWs.xyz;
}
#endif
#if ( _NORMALMAP )
{
// TangentU and TangentV
float3 vTangentUWs = UnityObjectToWorldDir( i.vTangentUOs_flTangentVSign.xyz ); // Transform tangentU into world space
//vTangentUWs.xyz = normalize( vTangentUWs.xyz - ( vNormalWs.xyz * dot( vTangentUWs.xyz, vNormalWs.xyz ) ) ); // Force tangentU perpendicular to normal and normalize
o.vTangentUWs.xyz = vTangentUWs.xyz;
o.vTangentVWs.xyz = cross( vNormalWs.xyz, vTangentUWs.xyz ) * i.vTangentUOs_flTangentVSign.w;
}
#endif
#if ( S_WORLD_ALIGNED_TEXTURE )
{
float3 vTexturePositionScaledWs = ( vPositionWs.xyz - g_vWorldAlignedTexturePosition.xyz ) / g_vWorldAlignedTextureSize.xyz;
o.vTextureCoords.x = dot( vTexturePositionScaledWs.xyz, g_vWorldAlignedNormalTangentU.xyz );
o.vTextureCoords.y = dot( vTexturePositionScaledWs.xyz, g_vWorldAlignedNormalTangentV.xyz );
#if ( _DETAIL )
{
o.vTextureCoords.zw = TRANSFORM_TEX( o.vTextureCoords.xy, _DetailAlbedoMap );
}
#endif
}
#else
{
// Texture coords (Copied from Unity's TexCoords() helper function)
o.vTextureCoords.xy = TRANSFORM_TEX( i.vTexCoord0, _MainTex );
#if ( _DETAIL )
{
o.vTextureCoords.zw = TRANSFORM_TEX( ( ( _UVSec == 0 ) ? i.vTexCoord0 : i.vTexCoord1 ), _DetailAlbedoMap );
}
#endif
}
#endif
// Indirect lighting uv's or light probe
#if ( S_OVERRIDE_LIGHTMAP )
{
o.vLightmapUV.xy = i.vTexCoord1.xy;
}
#elif ( LIGHTMAP_ON )
{
// Static lightmaps
o.vLightmapUV.xy = i.vTexCoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
}
#endif
#if ( DYNAMICLIGHTMAP_ON )
{
o.vLightmapUV.zw = i.vTexCoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
}
#endif
return o;
}
// MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
#define g_vColorTint _Color
#define g_tColor _MainTex
#define g_tNormalMap _BumpMap
#define g_flBumpScale _BumpScale
#define g_vReflectance _SpecColor
#define g_tReflectanceGloss _SpecGlossMap
#define g_flGlossScale _Glossiness
#define g_tDetailAlbedo _DetailAlbedoMap
#define g_tDetailNormal _DetailNormalMap
#define g_flDetailNormalScale _DetailNormalMapScale
float g_flReflectanceScale = 1.0;
float g_flReflectanceBias = 0.0;
float _OcclusionStrengthDirectDiffuse = 1.0;
float _OcclusionStrengthDirectSpecular = 1.0;
float _OcclusionStrengthIndirectDiffuse = 1.0;
float _OcclusionStrengthIndirectSpecular = 1.0;
struct PS_OUTPUT
{
float4 vColor : SV_Target0;
};
PS_OUTPUT MainPs( PS_INPUT i )
{
PS_OUTPUT o = ( PS_OUTPUT )0;
//--------//
// Albedo //
//--------//
float4 vAlbedoTexel = tex2D( g_tColor, i.vTextureCoords.xy ) * g_vColorTint.rgba;
float3 vAlbedo = vAlbedoTexel.rgb;
// Apply detail to albedo
#if ( _DETAIL )
{
float flDetailMask = DetailMask( i.vTextureCoords.xy );
float3 vDetailAlbedo = tex2D( g_tDetailAlbedo, i.vTextureCoords.zw ).rgb;
#if ( _DETAIL_MULX2 )
vAlbedo.rgb *= LerpWhiteTo( vDetailAlbedo.rgb * unity_ColorSpaceDouble.rgb, flDetailMask );
#elif ( _DETAIL_MUL )
vAlbedo.rgb *= LerpWhiteTo( vDetailAlbedo.rgb, flDetailMask );
#elif ( _DETAIL_ADD )
vAlbedo.rgb += vDetailAlbedo.rgb * flDetailMask;
#elif ( _DETAIL_LERP )
vAlbedo.rgb = lerp( vAlbedo.rgb, vDetailAlbedo.rgb, flDetailMask );
#endif
}
#endif
//--------------//
// Translucency //
//--------------//
#if ( _ALPHATEST_ON )
{
clip( vAlbedoTexel.a - _Cutoff );
}
#endif
#if ( _ALPHAPREMULTIPLY_ON )
{
vAlbedo.rgb *= vAlbedoTexel.a;
}
#endif
#if ( _ALPHABLEND_ON || _ALPHAPREMULTIPLY_ON )
{
o.vColor.a = vAlbedoTexel.a;
}
#else
{
o.vColor.a = 1.0;
}
#endif
//---------------//
// Tangent Space //
//---------------//
float3 vTangentUWs = float3( 1.0, 0.0, 0.0 );
float3 vTangentVWs = float3( 0.0, 1.0, 0.0 );
#if ( _NORMALMAP )
{
vTangentUWs.xyz = i.vTangentUWs.xyz;
vTangentVWs.xyz = i.vTangentVWs.xyz;
}
#endif
//--------//
// Normal //
//--------//
float3 vGeometricNormalWs = float3( 0.0, 0.0, 1.0 );
#if ( !S_UNLIT )
{
i.vNormalWs.xyz = normalize( i.vNormalWs.xyz );
vGeometricNormalWs.xyz = i.vNormalWs.xyz;
}
#endif
float3 vNormalWs = vGeometricNormalWs.xyz;
float3 vNormalTs = float3( 0.0, 0.0, 1.0 );
#if ( _NORMALMAP )
{
vNormalTs.xyz = UnpackScaleNormal( tex2D( g_tNormalMap, i.vTextureCoords.xy ), g_flBumpScale );
//vNormalTs.y = -vNormalTs.y;
// Apply detail to tangent normal
#if ( _DETAIL )
{
float flDetailMask = DetailMask( i.vTextureCoords.xy );
float3 vDetailNormalTs = UnpackScaleNormal( tex2D( g_tDetailNormal, i.vTextureCoords.zw ), g_flDetailNormalScale );
#if ( _DETAIL_LERP )
{
vNormalTs.xyz = lerp( vNormalTs.xyz, vDetailNormalTs.xyz, flDetailMask );
}
#else
{
vNormalTs.xyz = lerp( vNormalTs.xyz, BlendNormals( vNormalTs.xyz, vDetailNormalTs.xyz ), flDetailMask );
}
#endif
}
#endif
// Convert to world space
vNormalWs.xyz = Vec3TsToWsNormalized( vNormalTs.xyz, vGeometricNormalWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz );
}
#endif
//-----------//
// Roughness //
//-----------//
float2 vRoughness = float2( 0.6, 0.6 );// vNormalTexel.rb;
//#if ( S_HIGH_QUALITY_GLOSS )
//{
// float4 vGlossTexel = Tex2D( g_tGloss, i.vTextureCoords.xy );
// vRoughness.xy += vGlossTexel.ag;
//}
//#endif
// Reflectance and gloss
float3 vReflectance = float3( 0.0, 0.0, 0.0 );
float flGloss = 0.0;
#if ( S_SPECULAR_METALLIC )
{
float2 vMetallicGloss = MetallicGloss( i.vTextureCoords.xy );
float flOneMinusReflectivity;
float3 vSpecColor;
float3 diffColor = DiffuseAndSpecularFromMetallic( vAlbedo.rgb, vMetallicGloss.x, /*out*/ vSpecColor, /*out*/ flOneMinusReflectivity);
vAlbedo = diffColor.rgb;
vReflectance.rgb = vSpecColor.rgb;
flGloss = vMetallicGloss.y;
}
#elif ( S_SPECULAR_BLINNPHONG )
{
float4 vReflectanceGloss = SpecularGloss( i.vTextureCoords.xy );
vReflectanceGloss.rgb = ( vReflectanceGloss.rgb * g_flReflectanceScale.xxx ) + g_flReflectanceBias.xxx;
vReflectance.rgb = vReflectanceGloss.rgb;
flGloss = vReflectanceGloss.a;
}
#endif
vRoughness.xy = ( 1.0 - flGloss ).xx;
#if ( !S_SPECULAR_NONE )
{
vRoughness.xy = AdjustRoughnessByGeometricNormal( vRoughness.xy, vGeometricNormalWs.xyz );
}
#endif
//----------//
// Lighting //
//----------//
LightingTerms_t lightingTerms;
lightingTerms.vDiffuse.rgb = float3( 1.0, 1.0, 1.0 );
lightingTerms.vSpecular.rgb = float3( 0.0, 0.0, 0.0 );
lightingTerms.vIndirectDiffuse.rgb = float3( 0.0, 0.0, 0.0 );
lightingTerms.vIndirectSpecular.rgb = float3( 0.0, 0.0, 0.0 );
lightingTerms.vTransmissiveSunlight.rgb = float3( 0.0, 0.0, 0.0 );
float flFresnelExponent = 5.0;
float flMetalness = 0.0f;
#if ( !S_UNLIT )
{
float4 vLightmapUV = float4( 0.0, 0.0, 0.0, 0.0 );
#if ( S_OVERRIDE_LIGHTMAP || LIGHTMAP_ON || DYNAMICLIGHTMAP_ON )
{
vLightmapUV.xy = i.vLightmapUV.xy;
#if ( DYNAMICLIGHTMAP_ON )
{
vLightmapUV.zw = i.vLightmapUV.zw;
}
#endif
}
#endif
// Compute lighting
lightingTerms = ComputeLighting( i.vPositionWs.xyz, vNormalWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz, vRoughness.xy, vReflectance.rgb, flFresnelExponent, vLightmapUV.xyzw );
#if ( S_OCCLUSION )
{
float flOcclusion = tex2D( _OcclusionMap, i.vTextureCoords.xy ).g;
lightingTerms.vDiffuse.rgb *= LerpOneTo( flOcclusion, _OcclusionStrength * _OcclusionStrengthDirectDiffuse );
lightingTerms.vSpecular.rgb *= LerpOneTo( flOcclusion, _OcclusionStrength * _OcclusionStrengthDirectSpecular );
lightingTerms.vIndirectDiffuse.rgb *= LerpOneTo( flOcclusion, _OcclusionStrength * _OcclusionStrengthIndirectDiffuse );
lightingTerms.vIndirectSpecular.rgb *= LerpOneTo( flOcclusion, _OcclusionStrength * _OcclusionStrengthIndirectSpecular );
}
#endif
}
#endif
// Diffuse
o.vColor.rgb = ( lightingTerms.vDiffuse.rgb + lightingTerms.vIndirectDiffuse.rgb ) * vAlbedo.rgb;
// Specular
#if ( !S_SPECULAR_NONE )
{
o.vColor.rgb += lightingTerms.vSpecular.rgb;
}
#endif
o.vColor.rgb += lightingTerms.vIndirectSpecular.rgb; // Indirect specular applies its own fresnel in the forward lighting header file
// Emission - Unity just adds the emissive term at the end instead of adding it to the diffuse lighting term. Artists may want both options.
float3 vEmission = Emission( i.vTextureCoords.xy );
o.vColor.rgb += vEmission.rgb;
#if ( D_HOLOGRAM_FX )
{
float flNoise =
0.35 * tex3D(g_tHologramNoise3D, 0.016 * i.vPositionWs.xyz + float3(0.756, 0.159, 0.871)).x +
0.25 * tex3D(g_tHologramNoise3D, 0.032 * i.vPositionWs.xyz + float3(0.147, 0.051, 0.273)).x +
0.20 * tex3D(g_tHologramNoise3D, 0.064 * i.vPositionWs.xyz + float3(0.230, 0.700, 0.809)).x +
0.15 * tex3D(g_tHologramNoise3D, 0.128 * i.vPositionWs.xyz + float3(0.938, 0.117, 0.952)).x +
0.05 * tex3D(g_tHologramNoise3D, 0.256 * i.vPositionWs.xyz + float3(0.867, 0.363, 0.502)).x;
float EDGE = 1.0;
float HEIGHT_BIAS = 4.0;
float flAvgColor = saturate( dot( float3( 0.3333333, 0.3333333, 0.3333333 ), o.vColor.rgb ) );
float3 vTransmissionRayWs = i.vPositionWs.xyz - g_vHologramTransmissionSource;
vTransmissionRayWs.y *= HEIGHT_BIAS;
float flTransmissionDistance = length( vTransmissionRayWs.xyz );
flTransmissionDistance -= g_flHologramTransmissionFrontier * 0.5 * ( flNoise + flAvgColor );
clip( g_flHologramTransmissionDistance - flTransmissionDistance );
float flEdgeAmount = saturate( EDGE * ( g_flHologramTransmissionDistance - flTransmissionDistance ) );
float3 vCyan = float3( 0.0, 1.0, 1.0 );
o.vColor.rgb = lerp( vCyan.rgb, o.vColor.rgb, flEdgeAmount );
}
#endif
// Dither to fix banding artifacts
o.vColor.rgb += ScreenSpaceDither( i.vPositionPs.xy );
return o;
}
ENDCG
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
Pass
{
Name "META"
Tags { "LightMode"="Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
#include "UnityStandardMeta.cginc"
ENDCG
}
Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
//Tags { "LightMode" = "ShadowCaster" }
ZWrite On
ZTest LEqual
ColorMask 0
Blend Off
Offset 2.5, 1 // http://docs.unity3d.com/Manual/SL-CullAndDepth.html
CGPROGRAM
#pragma target 4.0
//#pragma only_renderers d3d11
//#pragma multi_compile_shadowcaster
#pragma vertex MainVs
#pragma fragment MainPs
#include "UnityCG.cginc"
struct VertexInput
{
float4 vPositionOs : POSITION;
float3 vNormalOs : NORMAL;
};
struct VertexOutput
{
float4 vPositionPs : SV_POSITION;
};
float3 g_vLightDirWs = float3( 0.0, 0.0, 0.0 );
float2 GetShadowOffsets( float3 N, float3 L )
{
// From: Ignacio Castaño http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/
float cos_alpha = saturate( dot( N, L ) );
float offset_scale_N = sqrt( 1 - ( cos_alpha * cos_alpha ) ); // sin( acos( L·N ) )
float offset_scale_L = offset_scale_N / cos_alpha; // tan( acos( L·N ) )
return float2( offset_scale_N, min( 2.0, offset_scale_L ) );
}
VertexOutput MainVs( VertexInput i )
{
VertexOutput o;
//o.vPositionPs.xyzw = mul( UNITY_MATRIX_MVP, i.vPositionOs.xyzw );
float3 vNormalWs = UnityObjectToWorldNormal( i.vNormalOs.xyz );
float3 vPositionWs = mul( unity_ObjectToWorld, i.vPositionOs.xyzw ).xyz;
float2 vShadowOffsets = GetShadowOffsets( vNormalWs.xyz, g_vLightDirWs.xyz );
vPositionWs.xyz -= vShadowOffsets.x * vNormalWs.xyz / 100;
vPositionWs.xyz += vShadowOffsets.y * g_vLightDirWs.xyz / 1000;
o.vPositionPs.xyzw = mul( UNITY_MATRIX_MVP, float4( mul( unity_WorldToObject, float4( vPositionWs.xyz, 1.0 ) ).xyz, 1.0 ) );
return o;
}
float4 MainPs( VertexOutput i ) : SV_Target
{
return float4( 0.0, 0.0, 0.0, 0.0 );
}
ENDCG
}
}
CustomEditor "ValveShaderGUI"
}

9
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_standard.shader.meta


fileFormatVersion: 2
guid: 908b379d4818cd64184b95a21123d909
timeCreated: 1442663114
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

550
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_utils.cginc


// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
#ifndef VALVE_VR_UTILS_INCLUDED
#define VALVE_VR_UTILS_INCLUDED
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "UnityShaderVariables.cginc"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#define g_vCameraPositionWs ( _WorldSpaceCameraPos )
//#define g_flTime ( _Time.y )
float g_flTime = 0.0; // Set by ValveCamera.cs
//float3 g_vMiddleEyePositionWs;
//float4x4 g_matWorldToProjectionMultiview[ 2 ];
//float4 g_vCameraPositionWsMultiview[ 2 ];
//---------------------------------------------------------------------------------------------------------------------------------------------------------
float3 ScreenSpaceDither( float2 vScreenPos )
{
//if ( Blink( 1.5 ) )
// return 0.0;
//if ( ( int )vScreenPos.y == 840 )
// return 0.3;
//if ( vScreenPos.y < 840 )
// return 0.0;
float3 vDither = dot( float2( 171.0, 231.0 ), vScreenPos.xy + g_flTime.xx ).xxx;
vDither.rgb = frac( vDither.rgb / float3( 103.0, 71.0, 97.0 ) ) - float3( 0.5, 0.5, 0.5 );
return ( vDither.rgb / 255.0 ) * 0.375;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Used to blink shader code to see before/after during development. Meant to be used like this: if ( Blink( 1.0 ) )
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float Blink( float flNumSeconds )
{
return step( 0.5, frac( g_flTime * 0.5 / flNumSeconds ) );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Tangent transform helper functions
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 Vec3WsToTs( float3 vVectorWs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs )
{
float3 vVectorTs;
vVectorTs.x = dot( vVectorWs.xyz, vTangentUWs.xyz );
vVectorTs.y = dot( vVectorWs.xyz, vTangentVWs.xyz );
vVectorTs.z = dot( vVectorWs.xyz, vNormalWs.xyz );
return vVectorTs.xyz; // Return without normalizing
}
float3 Vec3WsToTsNormalized( float3 vVectorWs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs )
{
return normalize( Vec3WsToTs( vVectorWs.xyz, vNormalWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz ) );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 Vec3TsToWs( float3 vVectorTs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs )
{
float3 vVectorWs;
vVectorWs.xyz = vVectorTs.x * vTangentUWs.xyz;
vVectorWs.xyz += vVectorTs.y * vTangentVWs.xyz;
vVectorWs.xyz += vVectorTs.z * vNormalWs.xyz;
return vVectorWs.xyz; // Return without normalizing
}
float3 Vec3TsToWsNormalized( float3 vVectorTs, float3 vNormalWs, float3 vTangentUWs, float3 vTangentVWs )
{
return normalize( Vec3TsToWs( vVectorTs.xyz, vNormalWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz ) );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 ComputeTangentVFromSign( float3 vNormalWs, float3 vTangentUWs, float flTangentFlip )
{
return normalize( cross( vTangentUWs.xyz, vNormalWs.xyz ) ) * flTangentFlip;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 DecodeHemiOctahedronNormal( float2 vHemiOct )
{
// Rotate and scale the unit square back to the center diamond
vHemiOct.xy = ( vHemiOct.xy * 2.0 ) - 1.0;
float2 temp = float2( vHemiOct.x + vHemiOct.y, vHemiOct.x - vHemiOct.y ) * 0.5;
float3 v = float3( temp.xy, 1.0 - abs( temp.x ) - abs( temp.y ) );
return normalize( v );
}
// Defines ----------------------------------------------------------------------------------------------------------------------------------------------------
#define M_PI ( 3.14159265358979323846 )
#define MOD2X_SCALAR ( 1.992156862745098 ) // 254.0/255.0 * 2.0. This maps 128 in an 8-bit texture to 1.0. We'll probably need something different for DXT textures
#define SMALL_FLOAT 1e-12
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// MAX/MIN to match src
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float MAX( float flA, float flB )
{
return max( flA, flB );
}
float MIN( float flA, float flB )
{
return min( flA, flB );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Normalize functions that avoid divide by 0
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 NormalizeSafe( float3 vVec )
{
float3 vResult;
//[flatten]
if ( length( vVec.xyz ) == 0.0 )
{
vResult.xyz = float3( 0.0, 0.0, 0.0 );
}
else
{
vResult.xyz = normalize( vVec.xyz );
}
return vResult.xyz;
}
float2 NormalizeSafe( float2 vVec )
{
float2 vResult;
//[flatten]
if ( length( vVec.xy ) == 0.0 )
{
vResult.xy = float2( 0.0, 0.0 );
}
else
{
vResult.xy = normalize( vVec.xy );
}
return vResult.xy;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float ClampToPositive( float flValue )
{
return max( 0.0, flValue );
}
float2 ClampToPositive( float2 vValue )
{
return max( float2( 0.0, 0.0 ), vValue.xy );
}
float3 ClampToPositive( float3 vValue )
{
return max( float3( 0.0, 0.0, 0.0 ), vValue.xyz );
}
float4 ClampToPositive( float4 vValue )
{
return max( float4( 0.0, 0.0, 0.0, 0.0 ), vValue.xyzw );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float LinearRamp( float flMin, float flMax, float flInput )
{
return saturate( ( flInput - flMin ) / ( flMax - flMin ) );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float fsel( float flComparand, float flValGE, float flLT )
{
return ( flComparand >= 0.0 ) ? flValGE : flLT;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Remap a value in the range [A,B] to [C,D].
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float RemapVal( float flOldVal, float flOldMin, float flOldMax, float flNewMin, float flNewMax )
{
// Put the old val into 0-1 range based on the old min/max
float flValNormalized = ( flOldVal - flOldMin ) / ( flOldMax - flOldMin );
// Map 0-1 range into new min/max
return ( flValNormalized * ( flNewMax - flNewMin ) ) + flNewMin;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// Remap a value in the range [A,B] to [C,D]. Values <A map to C, and >B maps to D.
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float RemapValClamped( float flOldVal, float flOldMin, float flOldMax, float flNewMin, float flNewMax )
{
// Put the old val into 0-1 range based on the old min/max
float flValNormalized = saturate( ( flOldVal - flOldMin ) / ( flOldMax - flOldMin ) );
// Map 0-1 range into new min/max
return ( flValNormalized * ( flNewMax - flNewMin ) ) + flNewMin;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float4 PackToColor( float4 vValue )
{
return ( ( vValue.xyzw * 0.5 ) + 0.5 );
}
float3 PackToColor( float3 vValue )
{
return ( ( vValue.xyz * 0.5 ) + 0.5 );
}
float2 PackToColor( float2 vValue )
{
return ( ( vValue.xy * 0.5 ) + 0.5 );
}
float PackToColor( float flValue )
{
return ( ( flValue * 0.5 ) + 0.5 );
}
float4 UnpackFromColor( float4 cColor )
{
return ( ( cColor.xyzw * 2.0 ) - 1.0 );
}
float3 UnpackFromColor( float3 cColor )
{
return ( ( cColor.xyz * 2.0 ) - 1.0 );
}
float2 UnpackFromColor( float2 cColor )
{
return ( ( cColor.xy * 2.0 ) - 1.0 );
}
float UnpackFromColor( float flColor )
{
return ( ( flColor * 2.0 ) - 1.0 );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float Luminance( float3 cColor )
{
// Formula for calculating luminance based on NTSC standard
float3 tmpv = float3( 0.2125, 0.7154, 0.0721 );
float flLuminance = dot( cColor.rgb, tmpv.rgb );
// Alternate formula for calculating luminance for linear RGB space (Widely used in color hue and saturation computations)
//float3 tmpv = float3( 0.3086, 0.6094, 0.0820 );;
//float flLuminance = dot( cColor.rgb, tmpv.rgb );
// Simple average
//float3 tmpv = float3( 0.333, 0.333, 0.333 );
//float flLuminance = dot( cColor.rgb, tmpv.rgb );
return flLuminance;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 SaturateColor( float3 cColor, float flTargetSaturation )
{
float lum = Luminance( cColor.rgb );
return lerp( float3( lum, lum, lum ), cColor.rgb, flTargetSaturation.xxx );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// 2.0 gamma conversion routines - Should only be used in special cases
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float LinearToGamma20( float vLinear )
{
return pow( vLinear, 0.5 );
}
float3 LinearToGamma20( float3 vLinear )
{
return pow( vLinear.rgb, float3( 0.5, 0.5, 0.5 ) );
}
float4 LinearToGamma20( float4 vLinear )
{
return float4( pow( vLinear.rgb, float3( 0.5, 0.5, 0.5 ) ), vLinear.a );
}
float Gamma20ToLinear( float vGamma )
{
return vGamma * vGamma;
}
float3 Gamma20ToLinear( float3 vGamma )
{
return vGamma.rgb * vGamma.rgb;
}
float4 Gamma20ToLinear( float4 vGamma )
{
return float4( vGamma.rgb * vGamma.rgb, vGamma.a );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// 2.2 gamma conversion routines - Should only be used in special cases
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float LinearToGamma22( float vLinear )
{
return pow( vLinear, 0.454545454545455 );
}
float3 LinearToGamma22( float3 vLinear )
{
return pow( vLinear.rgb, float3( 0.454545454545455, 0.454545454545455, 0.454545454545455 ) );
}
float4 LinearToGamma22( float4 vLinear )
{
return float4( pow( vLinear.rgb, float3( 0.454545454545455, 0.454545454545455, 0.454545454545455 ) ), vLinear.a );
}
float Gamma22ToLinear( float vGamma )
{
return pow( vGamma, 2.2 );
}
float3 Gamma22ToLinear( float3 vGamma )
{
return pow( vGamma.rgb, float3( 2.2, 2.2, 2.2 ) );
}
float4 Gamma22ToLinear( float4 vGamma )
{
return float4( pow( vGamma.rgb, float3( 2.2, 2.2, 2.2 ) ), vGamma.a );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// sRGB gamma conversion routines
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 SrgbGammaToLinear( float3 vSrgbGammaColor )
{
// 15 asm instructions
float3 vLinearSegment = vSrgbGammaColor.rgb / 12.92;
float3 vExpSegment = pow( ( ( vSrgbGammaColor.rgb / 1.055 ) + ( 0.055 / 1.055 ) ), float3( 2.4, 2.4, 2.4 ) );
float3 vLinearColor = float3( ( vSrgbGammaColor.r <= 0.04045 ) ? vLinearSegment.r : vExpSegment.r,
( vSrgbGammaColor.g <= 0.04045 ) ? vLinearSegment.g : vExpSegment.g,
( vSrgbGammaColor.b <= 0.04045 ) ? vLinearSegment.b : vExpSegment.b );
return vLinearColor.rgb;
}
float3 SrgbLinearToGamma( float3 vLinearColor )
{
// 15 asm instructions
float3 vLinearSegment = vLinearColor.rgb * 12.92;
float3 vExpSegment = ( 1.055 * pow( vLinearColor.rgb, float3 ( 1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4 ) ) ) - 0.055;
float3 vGammaColor = float3( ( vLinearColor.r <= 0.0031308 ) ? vLinearSegment.r : vExpSegment.r,
( vLinearColor.g <= 0.0031308 ) ? vLinearSegment.g : vExpSegment.g,
( vLinearColor.b <= 0.0031308 ) ? vLinearSegment.b : vExpSegment.b );
return vGammaColor.rgb;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// RGBM encode/decode
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float4 RGBMEncode( float3 vLinearColor )
{
vLinearColor.rgb = sqrt( vLinearColor.rgb );
vLinearColor.rgb = saturate( vLinearColor.rgb * ( 1.0 / 6.0 ) );
float4 vRGBM;
vRGBM.a = max( max( vLinearColor.r, vLinearColor.g ), max( vLinearColor.b, 1.0 / 6.0 ) );
vRGBM.a = ceil( vRGBM.a * 255.0 ) / 255.0;
vRGBM.rgb = vLinearColor.rgb / vRGBM.a;
return vRGBM;
}
float3 RGBMDecode( float4 vRGBM )
{
float3 vLinearColor = vRGBM.rgb * 6.0 * vRGBM.a;
vLinearColor.rgb *= vLinearColor.rgb;
return vLinearColor.rgb;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// NOTE: All 2D normal vectors are assumed to be from a unit-length normal, so the length of xy must be <= 1.0!
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float2 UnpackNormal2D( float2 vNormal )
{
return ( ( vNormal.xy * 2.0 ) - 1.0 );
}
float2 PackNormal2D( float2 vNormal )
{
return ( ( vNormal.xy * 0.5 ) + 0.5 );
}
float3 UnpackNormal3D( float3 vNormal )
{
return ( ( vNormal.xyz * 2.0 ) - 1.0 );
}
float3 PackNormal3D( float3 vNormal )
{
return ( ( vNormal.xyz * 0.5 ) + 0.5 );
}
float3 ComputeNormalFromXY( float2 vXY )
{
float3 vNormalTs;
vNormalTs.xy = vXY.xy;
vNormalTs.z = sqrt( saturate( 1.0 - dot( vNormalTs.xy, vNormalTs.xy ) ) );
return vNormalTs.xyz;
}
float3 ComputeNormalFromRGTexture( float2 vRGPixel )
{
float3 vNormalTs;
vNormalTs.xy = UnpackNormal2D( vRGPixel.rg );
vNormalTs.z = sqrt( saturate( 1.0 - dot( vNormalTs.xy, vNormalTs.xy ) ) );
return vNormalTs.xyz;
}
float3 ComputeNormalFromDXT5Texture( float4 vDXT5Pixel )
{
return ComputeNormalFromRGTexture( vDXT5Pixel.ag );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 ConvertSphericalToNormal( float2 vSpherical )
{
float2 sincosTheta;
sincos( vSpherical.x * M_PI, sincosTheta.x, sincosTheta.y );
float2 sincosPhi = float2( sqrt( 1.0 - ( vSpherical.y * vSpherical.y ) ), vSpherical.y );
return float3( sincosTheta.y * sincosPhi.x, sincosTheta.x * sincosPhi.x, sincosPhi.y );
}
float2 ConvertNormalToSphericalRGTexture( float3 vNormal )
{
// TODO: atan2 isn't defined at 0,0. Is this a problem?
float flAtanYX = atan2( vNormal.y, vNormal.x ) / M_PI;
return PackToColor( float2( flAtanYX, vNormal.z ) );
}
float3 ComputeNormalFromSphericalRGTexture( float2 vRGPixel )
{
float2 vUnpackedSpherical = UnpackNormal2D( vRGPixel.rg );
return ConvertSphericalToNormal( vUnpackedSpherical.xy );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 CalculateCameraToPositionRayWs( float3 vPositionWs )
{
return ( vPositionWs.xyz - g_vCameraPositionWs.xyz );
}
float3 CalculateCameraToPositionDirWs( float3 vPositionWs )
{
return normalize( CalculateCameraToPositionRayWs( vPositionWs.xyz ) );
}
float3 CalculateCameraToPositionRayTs( float3 vPositionWs, float3 vTangentUWs, float3 vTangentVWs, float3 vNormalWs )
{
float3 vViewVectorWs = CalculateCameraToPositionRayWs( vPositionWs.xyz ); // Not normalized
return Vec3WsToTs( vViewVectorWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz, vNormalWs.xyz ); // Not Normalized
}
float3 CalculateCameraToPositionDirTs( float3 vPositionWs, float3 vTangentUWs, float3 vTangentVWs, float3 vNormalWs )
{
return normalize( CalculateCameraToPositionRayTs( vPositionWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz, vNormalWs.xyz ) );
}
float3 CalculateCameraToPositionRayWsMultiview( uint nView, float3 vPositionWs )
{
// TODO!
return CalculateCameraToPositionRayWs( vPositionWs.xyz );
//return ( vPositionWs.xyz - g_vCameraPositionWsMultiview[ nView ].xyz );
}
float3 CalculateCameraToPositionDirWsMultiview( uint nView, float3 vPositionWs )
{
return normalize( CalculateCameraToPositionRayWsMultiview( nView, vPositionWs.xyz ) );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
// This helps the compiler reuse the output of the reverse functions above instead of duplicating the above code with camera - position
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 CalculatePositionToCameraRayWs( float3 vPositionWs )
{
return -CalculateCameraToPositionRayWs( vPositionWs.xyz );
}
float3 CalculatePositionToCameraDirWs( float3 vPositionWs )
{
return -CalculateCameraToPositionDirWs( vPositionWs.xyz );
}
float3 CalculatePositionToCameraRayTs( float3 vPositionWs, float3 vTangentUWs, float3 vTangentVWs, float3 vNormalWs )
{
return -CalculateCameraToPositionRayTs( vPositionWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz, vNormalWs.xyz );
}
float3 CalculatePositionToCameraDirTs( float3 vPositionWs, float3 vTangentUWs, float3 vTangentVWs, float3 vNormalWs )
{
return -CalculateCameraToPositionDirTs( vPositionWs.xyz, vTangentUWs.xyz, vTangentVWs.xyz, vNormalWs.xyz );
}
float3 CalculatePositionToCameraRayWsMultiview( uint nView, float3 vPositionWs )
{
return -CalculateCameraToPositionRayWsMultiview( nView, vPositionWs.xyz );
}
float3 CalculatePositionToCameraDirWsMultiview( uint nView, float3 vPositionWs )
{
return -CalculateCameraToPositionDirWsMultiview( nView, vPositionWs.xyz );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float3 CalculateCameraReflectionDirWs( float3 vPositionWs, float3 vNormalWs )
{
float3 vViewVectorWs = CalculateCameraToPositionDirWs( vPositionWs.xyz );
float3 vReflectionVectorWs = reflect( vViewVectorWs.xyz, vNormalWs.xyz );
return vReflectionVectorWs.xyz;
}
float3 CalculateCameraReflectionDirWsMultiview( uint nView, float3 vPositionWs, float3 vNormalWs )
{
float3 vViewVectorWs = CalculateCameraToPositionDirWsMultiview( nView, vPositionWs.xyz );
float3 vReflectionVectorWs = reflect( vViewVectorWs.xyz, vNormalWs.xyz );
return vReflectionVectorWs.xyz;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
float CalculateDistanceToCamera( float3 vPositionWs )
{
return length( g_vCameraPositionWs.xyz - vPositionWs.xyz );
}
#endif

9
Assets/ScriptableRenderLoop/ForwardRenderLoop/Shaders/vr_utils.cginc.meta


fileFormatVersion: 2
guid: 54e88da308c76ec45accf54e939d818e
timeCreated: 1442663113
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

620
Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveMenuTools.cs


// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
#if ( UNITY_EDITOR )
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.VersionControl;
//---------------------------------------------------------------------------------------------------------------------------------------------------
public class ValveRefreshStandardShader
{
static void SaveAssetsAndFreeMemory()
{
UnityEditor.AssetDatabase.SaveAssets();
GC.Collect();
UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
UnityEditor.AssetDatabase.Refresh();
}
private static void RenameShadersInAllMaterials( string nameBefore, string nameAfter )
{
Shader destShader = Shader.Find( nameAfter );
if ( destShader == null )
{
return;
}
int i = 0;
int nCount = 0;
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
nCount++;
}
}
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Valve Material Conversion", string.Format( "({0} of {1}) {2}", i, nCount, s ), ( float )i / ( float )nCount ) )
{
break;
}
Material m = UnityEditor.AssetDatabase.LoadMainAssetAtPath( s ) as Material;
//Debug.Log( m.name + "\n" );
//Debug.Log( m.shader.name + "\n" );
if ( m.shader.name.Equals( nameBefore ) )
{
Debug.Log( "Converting from \"" + nameBefore + "\"-->\"" + nameAfter + "\": " + m.name + "\n" );
m.shader = destShader;
SaveAssetsAndFreeMemory();
}
}
}
//object[] obj = GameObject.FindObjectsOfType( typeof( GameObject ) );
//foreach ( object o in obj )
//{
// GameObject g = ( GameObject )o;
//
// Renderer[] renderers = g.GetComponents<Renderer>();
// foreach ( Renderer r in renderers )
// {
// foreach ( Material m in r.sharedMaterials )
// {
// //Debug.Log( m.name + "\n" );
// //Debug.Log( m.shader.name + "\n" );
// if ( m.shader.name.Equals( "Standard" ) )
// {
// Debug.Log( "Refreshing Standard shader for material: " + m.name + "\n" );
// m.shader = destShader;
// SaveAssetsAndFreeMemory();
// }
// }
// }
//}
UnityEditor.EditorUtility.ClearProgressBar();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
public static bool StandardToValveSingleMaterial( Material m, Shader srcShader, Shader destShader, bool bRecordUnknownShaders, List<string> unknownShaders )
{
string n = srcShader.name;
if ( n.Equals( destShader.name ) )
{
// Do nothing
//Debug.Log( " Skipping " + m.name + "\n" );
return false;
}
else if ( n.Equals( "Standard" ) || n.Equals( "Valve/VR/Standard" ) )
{
// Metallic specular
Debug.Log( " Converting from \"" + n + "\"-->\"" + destShader.name + "\": " + m.name + "\n" );
m.shader = destShader;
m.SetOverrideTag( "OriginalShader", n );
m.SetInt( "_SpecularMode", 2 );
m.DisableKeyword( "S_SPECULAR_NONE" );
m.DisableKeyword( "S_SPECULAR_BLINNPHONG" );
m.EnableKeyword( "S_SPECULAR_METALLIC" );
return true;
}
else if ( n.Equals( "Standard (Specular setup)" ) || n.Equals( "Legacy Shaders/Bumped Diffuse" ) || n.Equals( "Legacy Shaders/Transparent/Diffuse" ) )
{
// Regular specular
Debug.Log( " Converting from \"" + n + "\"-->\"" + destShader.name + "\": " + m.name + "\n" );
m.shader = destShader;
m.SetOverrideTag( "OriginalShader", n );
m.SetInt( "_SpecularMode", 1 );
m.DisableKeyword( "S_SPECULAR_NONE" );
m.EnableKeyword( "S_SPECULAR_BLINNPHONG" );
m.DisableKeyword( "S_SPECULAR_METALLIC" );
if ( n.Equals( "Legacy Shaders/Transparent/Diffuse" ) )
{
m.SetFloat( "_Mode", 2 );
m.SetOverrideTag( "RenderType", "Transparent" );
m.SetInt( "_SrcBlend", ( int )UnityEngine.Rendering.BlendMode.SrcAlpha );
m.SetInt( "_DstBlend", ( int )UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha );
m.SetInt( "_ZWrite", 0 );
m.DisableKeyword( "_ALPHATEST_ON" );
m.EnableKeyword( "_ALPHABLEND_ON" );
m.DisableKeyword( "_ALPHAPREMULTIPLY_ON" );
m.renderQueue = 3000;
}
return true;
}
else if ( n.Equals( "Unlit/Color" ) || n.Equals( "Unlit/Texture" ) || n.Equals( "Unlit/Transparent" ) || n.Equals( "Unlit/Transparent Cutout" ) )
{
// Unlit
Debug.Log( " Converting from \"" + n + "\"-->\"" + destShader.name + "\": " + m.name + "\n" );
m.shader = destShader;
m.SetOverrideTag( "OriginalShader", n );
m.SetInt( "g_bUnlit", 1 );
m.EnableKeyword( "S_UNLIT" );
m.SetColor( "_EmissionColor", Color.black );
if ( n.Equals( "Unlit/Color" ) )
{
m.SetTexture( "_MainTex", Texture2D.whiteTexture );
}
else
{
m.SetColor( "_Color", Color.white );
if ( n.Equals( "Unlit/Transparent Cutout" ) )
{
m.SetFloat( "_Mode", 1 );
m.SetOverrideTag( "RenderType", "TransparentCutout" );
m.SetInt( "_SrcBlend", ( int )UnityEngine.Rendering.BlendMode.One );
m.SetInt( "_DstBlend", ( int )UnityEngine.Rendering.BlendMode.Zero );
m.SetInt( "_ZWrite", 1 );
m.EnableKeyword( "_ALPHATEST_ON" );
m.DisableKeyword( "_ALPHABLEND_ON" );
m.DisableKeyword( "_ALPHAPREMULTIPLY_ON" );
m.renderQueue = 2450;
}
else if ( n.Equals( "Unlit/Transparent" ) )
{
m.SetFloat( "_Mode", 2 );
m.SetOverrideTag( "RenderType", "Transparent" );
m.SetInt( "_SrcBlend", ( int )UnityEngine.Rendering.BlendMode.SrcAlpha );
m.SetInt( "_DstBlend", ( int )UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha );
m.SetInt( "_ZWrite", 0 );
m.DisableKeyword( "_ALPHATEST_ON" );
m.EnableKeyword( "_ALPHABLEND_ON" );
m.DisableKeyword( "_ALPHAPREMULTIPLY_ON" );
m.renderQueue = 3000;
}
}
return true;
}
else if ( bRecordUnknownShaders )
{
// Don't know how to convert, so add to list to spew at the end
Debug.LogWarning( " Don't know how to convert shader \"" + n + "\"" + " in material \"" + m.name + "\"" + "\n" );
if ( !unknownShaders.Contains( n ) )
{
unknownShaders.Add( n );
}
return false;
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
private static void StandardToValve( bool bConvertAllMaterials )
{
int nNumMaterialsConverted = 0;
Debug.Log( "Begin Convert to Valve Shaders\n\n" + Time.realtimeSinceStartup );
Shader destShader = Shader.Find( "Valve/vr_standard" );
if ( destShader == null )
{
Debug.LogWarning( " ERROR! Cannot find the \"Valve/vr_standard\" shader!" + "\n" );
return;
}
List< string > unknownShaders = new List< string >();
List< string > alreadyConvertedMaterials = new List<string>();
if ( bConvertAllMaterials )
{
int i = 0;
int nCount = 0;
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
nCount++;
}
}
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Valve Material Conversion to Valve Shaders", string.Format( "({0} of {1}) {2}", i, nCount, s ), ( float )i / ( float )nCount ) )
{
break;
}
Material m = UnityEditor.AssetDatabase.LoadMainAssetAtPath( s ) as Material;
if ( ( m == null ) || ( m.shader == null ) )
continue;
if ( !m.name.StartsWith( "" ) )
continue;
if ( alreadyConvertedMaterials.Contains( m.name ) )
continue;
alreadyConvertedMaterials.Add( m.name );
if ( StandardToValveSingleMaterial( m, m.shader, destShader, true, unknownShaders ) )
{
nNumMaterialsConverted++;
}
SaveAssetsAndFreeMemory();
}
}
}
else
{
int i = 0;
int nCount = 0;
Renderer[] renderers = GameObject.FindObjectsOfType<Renderer>();
List<string> countedMaterials = new List<string>();
foreach ( Renderer r in renderers )
{
if ( r.sharedMaterials == null )
continue;
foreach ( Material m in r.sharedMaterials )
{
if ( ( m == null ) || ( m.shader == null ) )
continue;
if ( !m.name.StartsWith( "" ) )
continue;
if ( countedMaterials.Contains( m.name ) )
continue;
countedMaterials.Add( m.name );
string assetPath = UnityEditor.AssetDatabase.GetAssetPath( m );
Material mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath( assetPath ) as Material;
if ( !mainAsset )
{
Debug.LogError( "Error calling LoadMainAssetAtPath( " + assetPath + " )!\n\n" );
continue;
}
nCount++;
}
}
bool bCanceled = false;
foreach ( Renderer r in renderers )
{
if ( r.sharedMaterials == null )
continue;
foreach ( Material m in r.sharedMaterials )
{
if ( ( m == null ) || ( m.shader == null ) )
continue;
if ( !m.name.StartsWith( "" ) )
continue;
if ( alreadyConvertedMaterials.Contains( m.name ) )
continue;
alreadyConvertedMaterials.Add( m.name );
string assetPath = UnityEditor.AssetDatabase.GetAssetPath( m );
Material mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath( assetPath ) as Material;
if ( !mainAsset )
{
Debug.LogError( "Error calling LoadMainAssetAtPath( " + assetPath + " )!\n\n" );
continue;
}
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Valve Material Conversion to Valve Shaders", string.Format( "({0} of {1}) {2}", i, nCount, assetPath ), ( float )i / ( float )nCount ) )
{
bCanceled = true;
break;
}
if ( StandardToValveSingleMaterial( mainAsset, mainAsset.shader, destShader, true, unknownShaders ) )
{
nNumMaterialsConverted++;
}
SaveAssetsAndFreeMemory();
}
if ( bCanceled )
break;
}
}
foreach ( string s in unknownShaders )
{
Debug.LogWarning( " Don't know how to convert shader \"" + s + "\"" + "\n" );
}
Debug.Log( "Converted " + nNumMaterialsConverted + " materials to Valve Shaders\n\n" + Time.realtimeSinceStartup );
UnityEditor.EditorUtility.ClearProgressBar();
}
[UnityEditor.MenuItem( "Valve/Shader Dev/Convert Active Materials to Valve Shaders", false, 50 )]
private static void StandardToValveCurrent()
{
StandardToValve( false );
}
[UnityEditor.MenuItem( "Valve/Shader Dev/Convert All Materials to Valve Shaders", false, 100 )]
private static void StandardToValveAll()
{
StandardToValve( true );
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
private static bool ValveToStandardSingleMaterial( Material m, Shader destShaderStandard, Shader destShaderStandardSpecular )
{
if ( m.shader.name.Equals( "Valve/vr_standard" ) )
{
if ( ( m.GetTag( "OriginalShader", true ) != null ) && ( m.GetTag( "OriginalShader", true ).Length > 0 ) )
{
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + m.GetTag( "OriginalShader", true ) + "\": " + m.name + "\n" );
m.shader = Shader.Find( m.GetTag( "OriginalShader", true ) );
return true;
}
else if ( m.GetInt( "_SpecularMode" ) == 2 )
{
// Metallic specular
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + destShaderStandard.name + "\": " + m.name + "\n" );
m.shader = destShaderStandard;
return true;
}
else
{
// Regular specular
Debug.Log( " Converting from \"" + m.shader.name + "\"-->\"" + destShaderStandardSpecular.name + "\": " + m.name + "\n" );
m.shader = destShaderStandardSpecular;
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
[UnityEditor.MenuItem( "Valve/Shader Dev/Convert All Materials Back to Unity Shaders", false, 101 )]
private static void ValveToStandard( bool bConvertAllMaterials )
{
int nNumMaterialsConverted = 0;
Debug.Log( "Begin Convert to Unity Shaders\n\n" + Time.realtimeSinceStartup );
Shader destShaderStandard = Shader.Find( "Standard" );
if ( destShaderStandard == null )
{
Debug.LogWarning( " ERROR! Cannot find the \"Standard\" shader!" + "\n" );
return;
}
Shader destShaderStandardSpecular = Shader.Find( "Standard (Specular setup)" );
if ( destShaderStandardSpecular == null )
{
Debug.LogWarning( " ERROR! Cannot find the \"Standard (Specular setup)\" shader!" + "\n" );
return;
}
List<string> alreadyConvertedMaterials = new List<string>();
if ( bConvertAllMaterials )
{
int i = 0;
int nCount = 0;
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
nCount++;
}
}
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Valve Material Conversion Back to Unity Shaders", string.Format( "({0} of {1}) {2}", i, nCount, s ), ( float )i / ( float )nCount ) )
{
break;
}
Material m = UnityEditor.AssetDatabase.LoadMainAssetAtPath( s ) as Material;
if ( ValveToStandardSingleMaterial( m, destShaderStandard, destShaderStandardSpecular ) )
{
nNumMaterialsConverted++;
}
SaveAssetsAndFreeMemory();
}
}
}
else
{
int i = 0;
int nCount = 0;
Renderer[] renderers = GameObject.FindObjectsOfType<Renderer>();
List<string> countedMaterials = new List<string>();
foreach ( Renderer r in renderers )
{
if ( r.sharedMaterials == null )
continue;
foreach ( Material m in r.sharedMaterials )
{
if ( ( m == null ) || ( m.shader == null ) )
continue;
if ( !m.name.StartsWith( "" ) )
continue;
if ( countedMaterials.Contains( m.name ) )
continue;
countedMaterials.Add( m.name );
string assetPath = UnityEditor.AssetDatabase.GetAssetPath( m );
Material mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath( assetPath ) as Material;
if ( !mainAsset )
{
Debug.LogError( "Error calling LoadMainAssetAtPath( " + assetPath + " )!\n\n" );
continue;
}
nCount++;
}
}
bool bCanceled = false;
foreach ( Renderer r in renderers )
{
if ( r.sharedMaterials == null )
continue;
foreach ( Material m in r.sharedMaterials )
{
if ( ( m == null ) || ( m.shader == null ) )
continue;
if ( !m.name.StartsWith( "" ) )
continue;
if ( alreadyConvertedMaterials.Contains( m.name ) )
continue;
alreadyConvertedMaterials.Add( m.name );
string assetPath = UnityEditor.AssetDatabase.GetAssetPath( m );
Material mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath( assetPath ) as Material;
if ( !mainAsset )
{
Debug.LogError( "Error calling LoadMainAssetAtPath( " + assetPath + " )!\n\n" );
continue;
}
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Valve Material Conversion Back to Unity Shaders", string.Format( "({0} of {1}) {2}", i, nCount, assetPath ), ( float )i / ( float )nCount ) )
{
bCanceled = true;
break;
}
if ( ValveToStandardSingleMaterial( mainAsset, destShaderStandard, destShaderStandardSpecular ) )
{
nNumMaterialsConverted++;
}
SaveAssetsAndFreeMemory();
}
if ( bCanceled )
break;
}
}
Debug.Log( "Converted " + nNumMaterialsConverted + " materials to Unity Shaders\n\n" + Time.realtimeSinceStartup );
UnityEditor.EditorUtility.ClearProgressBar();
}
[UnityEditor.MenuItem( "Valve/Shader Dev/Convert Active Materials Back to Unity Shaders", false, 51 )]
private static void ValveToStandardCurrent()
{
ValveToStandard( false );
}
[UnityEditor.MenuItem( "Valve/Shader Dev/Convert All Materials Back to Unity Shaders", false, 101 )]
private static void ValveToStandardAll()
{
ValveToStandard( true );
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
//[UnityEditor.MenuItem( "Valve/Shader Dev/Refresh Standard", false, 150 )]
//private static void RefreshStandard()
//{
// RenameShadersInAllMaterials( "Standard", "Standard" );
//}
//---------------------------------------------------------------------------------------------------------------------------------------------------
[UnityEditor.MenuItem( "Valve/Shader Dev/Ensure Consistency in Valve Materials", false, 200 )]
private static void EnsureConsistencyInValveMaterials()
{
int nNumMaterialChanges = 0;
Debug.Log( "Begin consistency check for all Valve materials\n\n" + Time.realtimeSinceStartup );
int i = 0;
int nCount = 0;
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
nCount++;
}
}
foreach ( string s in UnityEditor.AssetDatabase.GetAllAssetPaths() )
{
if ( s.EndsWith( ".mat", StringComparison.OrdinalIgnoreCase ) )
{
i++;
if ( UnityEditor.EditorUtility.DisplayCancelableProgressBar( "Consistency check for all Valve materials", string.Format( "({0} of {1}) {2}", i, nCount, s ), ( float )i / ( float )nCount ) )
{
break;
}
Material m = UnityEditor.AssetDatabase.LoadMainAssetAtPath( s ) as Material;
if ( m.shader.name.Equals( "Valve/vr_standard" ) )
{
// Convert old metallic bool to new specular mode
if ( ( m.HasProperty( "g_bEnableMetallic" ) && m.GetInt( "g_bEnableMetallic" ) == 1 ) || ( m.IsKeywordEnabled( "_METALLIC_ENABLED" ) ) )
{
Debug.Log( " Converting old metallic checkbox to specular mode on material \"" + m.name + "\"\n" );
m.DisableKeyword( "_METALLIC_ENABLED" );
m.SetInt( "g_bEnableMetallic", 0 );
m.SetInt( "_SpecularMode", 2 );
m.EnableKeyword( "S_SPECULAR_METALLIC" );
nNumMaterialChanges++;
}
else if ( !m.IsKeywordEnabled( "S_SPECULAR_NONE" ) && !m.IsKeywordEnabled( "S_SPECULAR_BLINNPHONG" ) && !m.IsKeywordEnabled( "S_SPECULAR_METALLIC" ) )
{
Debug.Log( " Converting old specular to BlinnPhong specular mode on material \"" + m.name + "\"\n" );
m.SetInt( "_SpecularMode", 1 );
m.EnableKeyword( "S_SPECULAR_BLINNPHONG" );
nNumMaterialChanges++;
}
// If occlusion map is set, enable S_OCCLUSION static combo
if ( m.GetTexture( "_OcclusionMap" ) && !m.IsKeywordEnabled( "S_OCCLUSION" ) )
{
Debug.Log( " Enabling new occlusion combo S_OCCLUSION on material \"" + m.name + "\"\n" );
m.EnableKeyword( "S_OCCLUSION" );
nNumMaterialChanges++;
}
SaveAssetsAndFreeMemory();
}
}
}
Debug.Log( "Consistency check made " + nNumMaterialChanges + " changes to Valve materials\n\n" + Time.realtimeSinceStartup );
UnityEditor.EditorUtility.ClearProgressBar();
}
}
#endif

12
Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveMenuTools.cs.meta


fileFormatVersion: 2
guid: d929642ab18724fdcad04b4f10af6565
timeCreated: 1467147001
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

565
Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveShaderGUI.cs


// Copyright (c) Valve Corporation, All rights reserved. ======================================================================================================
#if ( UNITY_EDITOR )
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor
{
internal class ValveShaderGUI : ShaderGUI
{
public enum BlendMode
{
Opaque,
AlphaTest,
AlphaBlend,
Glass,
Additive
// TODO: MaskedGlass that will require an additional grayscale texture to act as a standard alpha blend mask
}
public enum SpecularMode
{
None,
BlinnPhong,
Metallic
//Anisotropic
}
private static class Styles
{
public static GUIStyle optionsButton = "PaneOptions";
public static GUIContent uvSetLabel = new GUIContent("UV Set");
public static GUIContent[] uvSetOptions = new GUIContent[] { new GUIContent("UV channel 0"), new GUIContent("UV channel 1") };
public static GUIContent unlitText = new GUIContent( "Unlit", "" );
public static string emptyTootip = "";
public static GUIContent albedoText = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
public static GUIContent specularMapText = new GUIContent("Specular", "Reflectance (RGB) and Gloss (A)");
public static GUIContent reflectanceMinText = new GUIContent( "Reflectance Min", "" );
public static GUIContent reflectanceMaxText = new GUIContent( "Reflectance Max", "" );
public static GUIContent metallicMapText = new GUIContent( "Metallic", "Metallic (R) and Gloss (A)" );
public static GUIContent smoothnessText = new GUIContent("Gloss", "");
public static GUIContent normalMapText = new GUIContent("Normal", "Normal Map");
//public static GUIContent heightMapText = new GUIContent("Height Map", "Height Map (G)");
public static GUIContent cubeMapScalarText = new GUIContent( "Cube Map Scalar", "" );
public static GUIContent occlusionText = new GUIContent("Occlusion", "Occlusion (G)");
public static GUIContent occlusionStrengthDirectDiffuseText = new GUIContent( "Occlusion Direct Diffuse", "" );
public static GUIContent occlusionStrengthDirectSpecularText = new GUIContent( "Occlusion Direct Specular", "" );
public static GUIContent occlusionStrengthIndirectDiffuseText = new GUIContent( "Occlusion Indirect Diffuse", "" );
public static GUIContent occlusionStrengthIndirectSpecularText = new GUIContent( "Occlusion Indirect Specular", "" );
public static GUIContent emissionText = new GUIContent( "Emission", "Emission (RGB)" );
public static GUIContent detailMaskText = new GUIContent("Detail Mask", "Mask for Secondary Maps (A)");
public static GUIContent detailAlbedoText = new GUIContent("Detail Albedo", "Detail Albedo (RGB) multiplied by 2");
public static GUIContent detailNormalMapText = new GUIContent("Detail Normal", "Detail Normal Map");
public static GUIContent overrideLightmapText = new GUIContent( "Override Lightmap", "Requires ValveOverrideLightmap.cs scrip on object" );
public static GUIContent worldAlignedTextureText = new GUIContent( "World Aligned Texture", "" );
public static GUIContent worldAlignedTextureSizeText = new GUIContent( "Size", "" );
public static GUIContent worldAlignedTextureNormalText = new GUIContent( "Normal", "" );
public static GUIContent worldAlignedTexturePositionText = new GUIContent( "World Position", "" );
public static string whiteSpaceString = " ";
public static string primaryMapsText = "Main Maps";
public static string secondaryMapsText = "Secondary Maps";
public static string renderingMode = "Rendering Mode";
public static string specularModeText = "Specular Mode";
public static GUIContent emissiveWarning = new GUIContent( "Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive." );
public static GUIContent emissiveColorWarning = new GUIContent ("Ensure emissive color is non-black for emission to have effect.");
public static readonly string[] blendNames = Enum.GetNames (typeof (BlendMode));
public static readonly string[] specularNames = Enum.GetNames( typeof( SpecularMode ) );
}
MaterialProperty unlit = null;
MaterialProperty blendMode = null;
MaterialProperty specularMode = null;
MaterialProperty albedoMap = null;
MaterialProperty albedoColor = null;
MaterialProperty alphaCutoff = null;
MaterialProperty specularMap = null;
MaterialProperty specularColor = null;
MaterialProperty reflectanceMin = null;
MaterialProperty reflectanceMax = null;
MaterialProperty metallicMap = null;
MaterialProperty metallic = null;
MaterialProperty smoothness = null;
MaterialProperty bumpScale = null;
MaterialProperty bumpMap = null;
MaterialProperty cubeMapScalar = null;
MaterialProperty occlusionStrength = null;
MaterialProperty occlusionMap = null;
MaterialProperty occlusionStrengthDirectDiffuse = null;
MaterialProperty occlusionStrengthDirectSpecular = null;
MaterialProperty occlusionStrengthIndirectDiffuse = null;
MaterialProperty occlusionStrengthIndirectSpecular = null;
//MaterialProperty heigtMapScale = null;
//MaterialProperty heightMap = null;
MaterialProperty emissionColorForRendering = null;
MaterialProperty emissionMap = null;
MaterialProperty detailMask = null;
MaterialProperty detailAlbedoMap = null;
MaterialProperty detailNormalMapScale = null;
MaterialProperty detailNormalMap = null;
MaterialProperty uvSetSecondary = null;
MaterialProperty overrideLightmap = null;
MaterialProperty worldAlignedTexture = null;
MaterialProperty worldAlignedTextureSize = null;
MaterialProperty worldAlignedTextureNormal = null;
MaterialProperty worldAlignedTexturePosition = null;
MaterialEditor m_MaterialEditor;
ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, 99f, 1/99f, 3f);
bool m_FirstTimeApply = true;
public void FindProperties (MaterialProperty[] props)
{
unlit = FindProperty( "g_bUnlit", props );
blendMode = FindProperty( "_Mode", props );
specularMode = FindProperty( "_SpecularMode", props );
albedoMap = FindProperty( "_MainTex", props );
albedoColor = FindProperty ("_Color", props);
alphaCutoff = FindProperty ("_Cutoff", props);
specularMap = FindProperty ("_SpecGlossMap", props, false);
specularColor = FindProperty ("_SpecColor", props, false);
reflectanceMin = FindProperty( "g_flReflectanceMin", props );
reflectanceMax = FindProperty( "g_flReflectanceMax", props );
metallicMap = FindProperty ("_MetallicGlossMap", props, false);
metallic = FindProperty ("_Metallic", props, false);
smoothness = FindProperty ("_Glossiness", props);
bumpScale = FindProperty ("_BumpScale", props);
bumpMap = FindProperty ("_BumpMap", props);
//heigtMapScale = FindProperty ("_Parallax", props);
//heightMap = FindProperty("_ParallaxMap", props);
cubeMapScalar = FindProperty( "g_flCubeMapScalar", props );
occlusionStrength = FindProperty ("_OcclusionStrength", props);
occlusionStrengthDirectDiffuse = FindProperty( "_OcclusionStrengthDirectDiffuse", props );
occlusionStrengthDirectSpecular = FindProperty( "_OcclusionStrengthDirectSpecular", props );
occlusionStrengthIndirectDiffuse = FindProperty( "_OcclusionStrengthIndirectDiffuse", props );
occlusionStrengthIndirectSpecular = FindProperty( "_OcclusionStrengthIndirectSpecular", props );
occlusionMap = FindProperty ("_OcclusionMap", props);
emissionColorForRendering = FindProperty ("_EmissionColor", props);
emissionMap = FindProperty ("_EmissionMap", props);
detailMask = FindProperty ("_DetailMask", props);
detailAlbedoMap = FindProperty ("_DetailAlbedoMap", props);
detailNormalMapScale = FindProperty ("_DetailNormalMapScale", props);
detailNormalMap = FindProperty ("_DetailNormalMap", props);
uvSetSecondary = FindProperty ("_UVSec", props);
overrideLightmap = FindProperty( "g_tOverrideLightmap", props );
worldAlignedTexture = FindProperty( "g_bWorldAlignedTexture", props, false );
worldAlignedTextureSize = FindProperty( "g_vWorldAlignedTextureSize", props, worldAlignedTexture != null );
worldAlignedTextureNormal = FindProperty( "g_vWorldAlignedTextureNormal", props, worldAlignedTexture != null );
worldAlignedTexturePosition = FindProperty( "g_vWorldAlignedTexturePosition", props, worldAlignedTexture != null );
}
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
ShaderPropertiesGUI (material);
// Make sure that needed keywords are set up if we're switching some existing
// material to a standard shader.
if (m_FirstTimeApply)
{
SetMaterialKeywords (material);
m_FirstTimeApply = false;
}
}
public void Vector3GUI( GUIContent label, MaterialProperty materialProperty )
{
Vector4 v4 = materialProperty.vectorValue;
Vector3 v3 = EditorGUILayout.Vector3Field( label, new Vector3( v4.x, v4.y, v4.z ) );
materialProperty.vectorValue = new Vector4( v3.x, v3.y, v3.z, 0.0f );
}
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
m_MaterialEditor.ShaderProperty( unlit, Styles.unlitText.text );
bool bUnlit = ( unlit.floatValue != 0.0f );
BlendModePopup();
if ( !bUnlit )
{
SpecularModePopup();
}
EditorGUILayout.Space();
//GUILayout.Label( Styles.primaryMapsText, EditorStyles.boldLabel );
DoAlbedoArea( material );
if ( !bUnlit )
{
m_MaterialEditor.TexturePropertySingleLine( Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null );
DoSpecularMetallicArea( material );
m_MaterialEditor.TexturePropertySingleLine( Styles.occlusionText, occlusionMap, occlusionMap.textureValue != null ? occlusionStrength : null );
if ( occlusionMap.textureValue != null )
{
m_MaterialEditor.ShaderProperty( occlusionStrengthDirectDiffuse, Styles.occlusionStrengthDirectDiffuseText.text, 2 );
m_MaterialEditor.ShaderProperty( occlusionStrengthDirectSpecular, Styles.occlusionStrengthDirectSpecularText.text, 2 );
m_MaterialEditor.ShaderProperty( occlusionStrengthIndirectDiffuse, Styles.occlusionStrengthIndirectDiffuseText.text, 2 );
m_MaterialEditor.ShaderProperty( occlusionStrengthIndirectSpecular, Styles.occlusionStrengthIndirectSpecularText.text, 2 );
}
m_MaterialEditor.ShaderProperty( cubeMapScalar, Styles.cubeMapScalarText.text, 0 );
}
//m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightMap.textureValue != null ? heigtMapScale : null);
DoEmissionArea( material );
m_MaterialEditor.TexturePropertySingleLine( Styles.detailMaskText, detailMask );
if ( !bUnlit )
{
m_MaterialEditor.TexturePropertySingleLine( Styles.overrideLightmapText, overrideLightmap );
}
EditorGUI.BeginChangeCheck(); // !!! AV - This is from Unity's script. Can these Begin/End calls be nested like this?
m_MaterialEditor.TextureScaleOffsetProperty( albedoMap );
if ( EditorGUI.EndChangeCheck() )
{
emissionMap.textureScaleAndOffset = albedoMap.textureScaleAndOffset; // Apply the main texture scale and offset to the emission texture as well, for Enlighten's sake
}
if ( worldAlignedTexture != null )
{
m_MaterialEditor.ShaderProperty( worldAlignedTexture, Styles.worldAlignedTextureText.text );
if ( worldAlignedTexture.floatValue != 0.0f )
{
EditorGUI.indentLevel = 2;
Vector3GUI( Styles.worldAlignedTextureSizeText, worldAlignedTextureSize );
Vector3GUI( Styles.worldAlignedTextureNormalText, worldAlignedTextureNormal );
Vector3GUI( Styles.worldAlignedTexturePositionText, worldAlignedTexturePosition );
EditorGUI.indentLevel = 0;
}
}
EditorGUILayout.Space();
// Secondary properties
GUILayout.Label( Styles.secondaryMapsText, EditorStyles.boldLabel );
m_MaterialEditor.TexturePropertySingleLine( Styles.detailAlbedoText, detailAlbedoMap );
if ( !bUnlit )
{
m_MaterialEditor.TexturePropertySingleLine( Styles.detailNormalMapText, detailNormalMap, detailNormalMapScale );
}
m_MaterialEditor.TextureScaleOffsetProperty( detailAlbedoMap );
m_MaterialEditor.ShaderProperty( uvSetSecondary, Styles.uvSetLabel.text );
}
if ( EditorGUI.EndChangeCheck() )
{
foreach ( var obj in blendMode.targets )
{
MaterialChanged( ( Material )obj );
}
foreach ( var obj in specularMode.targets )
{
MaterialChanged( ( Material )obj );
}
}
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial( material, oldShader, newShader );
if ( oldShader == null )
return;
// Convert to vr_standard
if ( newShader.name.Equals( "Valve/vr_standard" ) )
{
List<string> unknownShaders = new List<string>();
ValveRefreshStandardShader.StandardToValveSingleMaterial( material, oldShader, newShader, false, unknownShaders );
}
// Legacy shaders
if ( !oldShader.name.Contains( "Legacy Shaders/" ) )
return;
BlendMode blendMode = BlendMode.Opaque;
if (oldShader.name.Contains("/Transparent/Cutout/"))
{
blendMode = BlendMode.AlphaTest;
}
else if (oldShader.name.Contains("/Transparent/"))
{
// NOTE: legacy shaders did not provide physically based transparency
// therefore Fade mode
blendMode = BlendMode.AlphaBlend;
}
material.SetFloat("_Mode", (float)blendMode);
MaterialChanged(material);
}
void BlendModePopup()
{
EditorGUI.showMixedValue = blendMode.hasMixedValue;
var mode = (BlendMode)blendMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.renderingMode, (int)mode, Styles.blendNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Mode");
blendMode.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
void SpecularModePopup()
{
EditorGUI.showMixedValue = specularMode.hasMixedValue;
var mode = ( SpecularMode )specularMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = ( SpecularMode )EditorGUILayout.Popup( Styles.specularModeText, ( int )mode, Styles.specularNames );
if ( EditorGUI.EndChangeCheck() )
{
m_MaterialEditor.RegisterPropertyChangeUndo( "Specular Mode" );
specularMode.floatValue = ( float )mode;
}
EditorGUI.showMixedValue = false;
}
void DoAlbedoArea(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
if (((BlendMode)material.GetFloat("_Mode") == BlendMode.AlphaTest))
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel+1);
}
}
void DoEmissionArea(Material material)
{
float brightness = emissionColorForRendering.colorValue.maxColorComponent;
bool showHelpBox = !HasValidEmissiveKeyword(material);
bool showEmissionColorAndGIControls = brightness > 0.0f;
bool hadEmissionTexture = emissionMap.textureValue != null;
// Texture and HDR color controls
m_MaterialEditor.TexturePropertyWithHDRColor(Styles.emissionText, emissionMap, emissionColorForRendering, m_ColorPickerHDRConfig, false);
// If texture was assigned and color was black set color to white
if (emissionMap.textureValue != null && !hadEmissionTexture && brightness <= 0f)
emissionColorForRendering.colorValue = Color.white;
// Dynamic Lightmapping mode
if (showEmissionColorAndGIControls)
{
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled(emissionColorForRendering.colorValue);
using ( new EditorGUI.DisabledScope( !shouldEmissionBeEnabled ) )
{
m_MaterialEditor.LightmapEmissionProperty( MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1 );
}
}
if (showHelpBox)
{
EditorGUILayout.HelpBox(Styles.emissiveWarning.text, MessageType.Warning);
}
}
void DoSpecularMetallicArea( Material material )
{
SpecularMode specularMode = ( SpecularMode )material.GetInt( "_SpecularMode" );
if ( specularMode == SpecularMode.BlinnPhong )
{
if (specularMap.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines( Styles.specularMapText, specularMap, specularColor, Styles.smoothnessText, smoothness );
}
else
{
m_MaterialEditor.TexturePropertySingleLine( Styles.specularMapText, specularMap );
m_MaterialEditor.ShaderProperty( reflectanceMin, Styles.reflectanceMinText.text, 2 );
m_MaterialEditor.ShaderProperty( reflectanceMax, Styles.reflectanceMaxText.text, 2 );
}
}
else if ( specularMode == SpecularMode.Metallic )
{
if (metallicMap.textureValue == null)
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap);
}
}
public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
{
switch (blendMode)
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
break;
case BlendMode.AlphaTest:
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 2450;
break;
case BlendMode.AlphaBlend:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;
break;
case BlendMode.Glass:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;
break;
case BlendMode.Additive:
material.SetOverrideTag( "RenderType", "Transparent" );
material.SetInt( "_SrcBlend", ( int )UnityEngine.Rendering.BlendMode.One );
material.SetInt( "_DstBlend", ( int )UnityEngine.Rendering.BlendMode.One );
material.SetInt( "_ZWrite", 0 );
material.DisableKeyword( "_ALPHATEST_ON" );
material.DisableKeyword( "_ALPHABLEND_ON" );
material.DisableKeyword( "_ALPHAPREMULTIPLY_ON" );
material.renderQueue = 3000;
break;
}
}
static bool ShouldEmissionBeEnabled (Color color)
{
return color.maxColorComponent > (0.1f / 255.0f);
}
static void SetMaterialKeywords(Material material)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)
SetKeyword (material, "_NORMALMAP", material.GetTexture ("_BumpMap") || material.GetTexture ("_DetailNormalMap"));
SpecularMode specularMode = ( SpecularMode )material.GetInt( "_SpecularMode" );
if ( specularMode == SpecularMode.BlinnPhong )
{
SetKeyword( material, "_SPECGLOSSMAP", material.GetTexture( "_SpecGlossMap" ) );
}
else if ( specularMode == SpecularMode.Metallic )
{
SetKeyword( material, "_METALLICGLOSSMAP", material.GetTexture( "_MetallicGlossMap" ) );
}
SetKeyword( material, "S_SPECULAR_NONE", specularMode == SpecularMode.None );
SetKeyword( material, "S_SPECULAR_BLINNPHONG", specularMode == SpecularMode.BlinnPhong );
SetKeyword( material, "S_SPECULAR_METALLIC", specularMode == SpecularMode.Metallic );
SetKeyword( material, "S_OCCLUSION", material.GetTexture("_OcclusionMap") );
SetKeyword( material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
SetKeyword( material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
SetKeyword( material, "S_OVERRIDE_LIGHTMAP", material.GetTexture( "g_tOverrideLightmap" ) );
SetKeyword( material, "S_UNLIT", material.GetInt( "g_bUnlit" ) == 1 );
SetKeyword( material, "S_WORLD_ALIGNED_TEXTURE", material.GetInt( "g_bWorldAlignedTexture" ) == 1 );
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material.GetColor("_EmissionColor"));
SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
// Reflectance constants
float flReflectanceMin = material.GetFloat( "g_flReflectanceMin" );
float flReflectanceMax = material.GetFloat( "g_flReflectanceMax" );
material.SetFloat( "g_flReflectanceScale", Mathf.Max( flReflectanceMin, flReflectanceMax ) - flReflectanceMin );
material.SetFloat( "g_flReflectanceBias", flReflectanceMin );
// World aligned texture constants
Vector4 worldAlignedTextureNormal = material.GetVector( "g_vWorldAlignedTextureNormal" );
Vector3 normal = new Vector3( worldAlignedTextureNormal.x, worldAlignedTextureNormal.y, worldAlignedTextureNormal.z );
normal = ( normal.sqrMagnitude > 0.0f ) ? normal : Vector3.up;
Vector3 tangentU = Vector3.zero, tangentV = Vector3.zero;
Vector3.OrthoNormalize( ref normal, ref tangentU, ref tangentV );
material.SetVector( "g_vWorldAlignedNormalTangentU", new Vector4( tangentU.x, tangentU.y, tangentU.z, 0.0f ) );
material.SetVector( "g_vWorldAlignedNormalTangentV", new Vector4( tangentV.x, tangentV.y, tangentV.z, 0.0f ) );
// Static combo skips
if ( material.GetInt( "g_bUnlit" ) == 1 )
{
material.DisableKeyword( "_NORMALMAP" );
material.EnableKeyword( "S_SPECULAR_NONE" );
material.DisableKeyword( "S_SPECULAR_BLINNPHONG" );
material.DisableKeyword( "S_SPECULAR_METALLIC" );
material.DisableKeyword( "_METALLICGLOSSMAP" );
material.DisableKeyword( "_SPECGLOSSMAP" );
material.DisableKeyword( "S_OVERRIDE_LIGHTMAP" );
}
}
bool HasValidEmissiveKeyword (Material material)
{
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (emissionColorForRendering.colorValue))
return false;
else
return true;
}
static void MaterialChanged(Material material)
{
SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
SetMaterialKeywords(material);
}
static void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
}
}
} // namespace UnityEditor
#endif

12
Assets/ScriptableRenderLoop/ForwardRenderLoop/ValveShaderGUI.cs.meta


fileFormatVersion: 2
guid: ff7ac2f83009fce4badf8060688837af
timeCreated: 1439264716
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/RenderPasses.meta


fileFormatVersion: 2
guid: 8944ea3d2dfa541578ffc26bbdd626ed
folderAsset: yes
timeCreated: 1467147697
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

436
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;
namespace UnityEngine.ScriptableRenderLoop
{
[System.Serializable]
public struct ShadowSettings
{
public bool enabled;
public int shadowAtlasWidth;
public int shadowAtlasHeight;
public float maxShadowDistance;
public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
public static ShadowSettings Default
{
get
{
ShadowSettings settings;
settings.enabled = true;
settings.shadowAtlasHeight = settings.shadowAtlasWidth = 4096;
settings.directionalLightCascadeCount = 1;
settings.directionalLightCascades = new Vector3 (0.05F, 0.2F, 0.3F);
settings.directionalLightCascadeCount = 4;
settings.maxShadowDistance = 1000.0F;
return settings;
}
}
}
public struct InputShadowLightData
{
public int lightIndex;
public int shadowResolution;
}
public struct ShadowLight
{
public int shadowSliceIndex;
public int shadowSliceCount;
}
public struct ShadowSliceData
{
public Matrix4x4 shadowTransform;
public int atlasX;
public int atlasY;
public int shadowResolution;
}
public struct ShadowOutput
{
public ShadowSliceData[] shadowSlices;
public ShadowLight[] shadowLights;
public Vector4[] directionalShadowSplitSphereSqr;
public int GetShadowSliceCountShadowIndex(int lightIndex)
{
return shadowLights [lightIndex].shadowSliceCount;
}
public ShadowSliceData GetShadowSliceLightIndex(int lightIndex, int sliceIndex)
{
if (shadowLights[lightIndex].shadowSliceCount >= sliceIndex)
throw new System.IndexOutOfRangeException ();
return shadowSlices[shadowLights[lightIndex].shadowSliceIndex + sliceIndex];
}
public int GetShadowSliceCountLightIndex(int lightIndex)
{
return shadowLights[lightIndex].shadowSliceCount;
}
public int GetShadowSliceIndex(int lightIndex, int sliceIndex)
{
if (sliceIndex >= shadowLights[lightIndex].shadowSliceCount)
throw new System.IndexOutOfRangeException ();
return shadowLights[lightIndex].shadowSliceIndex + sliceIndex;
}
}
public struct ShadowRenderPass : IDisposable
{
ShadowSettings m_Settings;
[NonSerialized]
bool m_bFailedToPackLastTime;
int m_ShadowTexName;
const int kDepthBuffer = 24;
public ShadowRenderPass(ShadowSettings settings)
{
m_Settings = settings;
m_bFailedToPackLastTime = false;
m_ShadowTexName = Shader.PropertyToID("g_tShadowBuffer");
}
public void Dispose()
{
}
struct AtlasEntry
{
public AtlasEntry(int splitIndex, int lightIndex)
{
this.splitIndex = splitIndex;
this.lightIndex = lightIndex;
}
public int splitIndex;
public int lightIndex;
}
int CalculateNumShadowSplits(int index, ActiveLight[] lights)
{
LightType lightType = lights [index].lightType;
if (lightType == LightType.Spot)
return 1;
if (lightType == LightType.Directional)
return m_Settings.directionalLightCascadeCount;
return 6;
}
static public void ClearPackedShadows(ActiveLight[] lights, out ShadowOutput packedShadows)
{
packedShadows.directionalShadowSplitSphereSqr = null;
packedShadows.shadowSlices = null;
packedShadows.shadowLights = new ShadowLight[lights.Length];
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
bool AutoPackLightsIntoShadowTexture(List<InputShadowLightData> shadowLights, ActiveLight[] lights, out ShadowOutput packedShadows)
{
List<int> shadowIndices = new List<int>();
//@TODO: Disallow multiple directional lights
for (int i = 0; i < shadowLights.Count; i++)
{
shadowIndices.Add (shadowLights[i].lightIndex);
}
// World's stupidest sheet packer:
// 1. Sort all lights from largest to smallest
// 2. In a left->right, top->bottom pattern, fill quads until you reach the edge of the texture
// 3. Move position to x=0, y=bottomOfFirstTextureInThisRow
// 4. Goto 2.
// Yes, this will produce holes as the quads shrink, but it's good enough for now. I'll work on this more later to fill the gaps.
// Sort all lights from largest to smallest
shadowIndices.Sort(
delegate( int l1, int l2 )
{
int nCompare = 0;
// Sort shadow-casting lights by shadow resolution
nCompare = shadowLights[l1].shadowResolution.CompareTo(shadowLights[l2].shadowResolution); // Sort by shadow size
if ( nCompare == 0 ) // Same, so sort by range to stabilize sort results
nCompare = lights[l1].range.CompareTo( lights[l2].range ); // Sort by shadow size
if ( nCompare == 0 ) // Still same, so sort by instance ID to stabilize sort results
nCompare = lights[l1].light.GetInstanceID().CompareTo( lights[l2].light.GetInstanceID() );
return nCompare;
}
);
// Start filling lights into texture
List<AtlasEntry> requestedPages = new List<AtlasEntry>();
packedShadows.shadowLights = new ShadowLight[lights.Length];
for (int i = 0; i != shadowIndices.Count;i++)
{
int numShadowSplits = CalculateNumShadowSplits(shadowIndices[i], lights);
packedShadows.shadowLights[shadowIndices [i]].shadowSliceCount = numShadowSplits;
packedShadows.shadowLights[shadowIndices [i]].shadowSliceIndex = requestedPages.Count;
for (int s = 0; s < numShadowSplits; s++)
requestedPages.Add (new AtlasEntry (requestedPages.Count, shadowIndices[i]));
}
int nCurrentX = 0;
int nCurrentY = -1;
int nNextY = 0;
packedShadows.shadowSlices = new ShadowSliceData[requestedPages.Count];
packedShadows.directionalShadowSplitSphereSqr = new Vector4[4];
foreach (AtlasEntry entry in requestedPages)
{
int shadowResolution = shadowLights[entry.lightIndex].shadowResolution;
// Check if first texture is too wide
if ( nCurrentY == -1 )
{
if ( ( shadowResolution > m_Settings.shadowAtlasWidth ) || ( shadowResolution > m_Settings.shadowAtlasHeight ) )
{
Debug.LogError( "ERROR! Shadow packer ran out of space in the " + m_Settings.shadowAtlasWidth + "x" + m_Settings.shadowAtlasHeight + " texture!\n\n" );
m_bFailedToPackLastTime = true;
ClearPackedShadows (lights, out packedShadows);
return false;
}
}
// Goto next scanline
if ( ( nCurrentY == -1 ) || ( ( nCurrentX + shadowResolution ) > m_Settings.shadowAtlasWidth ) )
{
nCurrentX = 0;
nCurrentY = nNextY;
nNextY += shadowResolution;
}
// Check if we've run out of space
if ( ( nCurrentY + shadowResolution ) > m_Settings.shadowAtlasHeight )
{
Debug.LogError( "ERROR! Shadow packer ran out of space in the " + m_Settings.shadowAtlasWidth + "x" + m_Settings.shadowAtlasHeight + " texture!\n\n" );
m_bFailedToPackLastTime = true;
ClearPackedShadows (lights, out packedShadows);
return false;
}
// Save location to light
packedShadows.shadowSlices[entry.splitIndex].atlasX = nCurrentX;
packedShadows.shadowSlices[entry.splitIndex].atlasY = nCurrentY;
packedShadows.shadowSlices[entry.splitIndex].shadowResolution = shadowResolution;
// Move ahead
nCurrentX += shadowResolution;
//Debug.Log( "Sheet packer: " + vl.m_cachedLight.name + " ( " + vl.m_shadowX + ", " + vl.m_shadowY + " ) " + vl.m_shadowResolution + "\n\n" );
}
if ( m_bFailedToPackLastTime )
{
m_bFailedToPackLastTime = false;
Debug.Log( "SUCCESS! Shadow packer can now fit all lights into the " + m_Settings.shadowAtlasWidth + "x" + m_Settings.shadowAtlasHeight + " texture!\n\n" );
}
return requestedPages.Count != 0;
}
static List<InputShadowLightData> GetInputShadowLightData(CullResults cullResults)
{
var shadowCasters = new List<InputShadowLightData> ();
ActiveLight[] lights = cullResults.culledLights;
int directionalLightCount = 0;
for (int i = 0; i < lights.Length; i++)
{
//@TODO: ignore baked. move this logic to c++...
if (lights[i].light.shadows != LightShadows.None)
{
// Only a single directional shadow casting light is supported
if (lights [i].lightType == LightType.Directional)
{
directionalLightCount++;
if (directionalLightCount != 1)
continue;
}
AdditionalLightData additionalLight = lights [i].light.GetComponent<AdditionalLightData> ();
InputShadowLightData light;
light.lightIndex = i;
light.shadowResolution = AdditionalLightData.GetShadowResolution(additionalLight);
shadowCasters.Add (light);
}
}
return shadowCasters;
}
public void UpdateCullingParameters(ref CullingParameters parameters)
{
parameters.shadowDistance = Mathf.Min (m_Settings.maxShadowDistance, parameters.shadowDistance);
}
public void Render(RenderLoop loop, CullResults cullResults, out ShadowOutput packedShadows)
{
if (!m_Settings.enabled)
{
ClearPackedShadows(cullResults.culledLights, out packedShadows);
}
// Pack all shadow quads into the texture
if ( !AutoPackLightsIntoShadowTexture(GetInputShadowLightData(cullResults), cullResults.culledLights, out packedShadows) )
{
// No shadowing lights found, so skip all rendering
return;
}
RenderPackedShadows (loop, cullResults, ref packedShadows);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
// Render shadows
//---------------------------------------------------------------------------------------------------------------------------------------------------
void RenderPackedShadows(RenderLoop loop, CullResults cullResults, ref ShadowOutput packedShadows)
{
var setRenderTargetCommandBuffer = new CommandBuffer ();
setRenderTargetCommandBuffer.GetTemporaryRT (m_ShadowTexName, m_Settings.shadowAtlasWidth, m_Settings.shadowAtlasHeight, kDepthBuffer, FilterMode.Bilinear, RenderTextureFormat.Shadowmap, RenderTextureReadWrite.Linear);
//setRenderTargetCommandBuffer.GetTemporaryRT (m_ShadowTexName, m_Settings.shadowAtlasWidth, m_Settings.shadowAtlasHeight, kDepthBuffer, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
setRenderTargetCommandBuffer.SetRenderTarget (new RenderTargetIdentifier (m_ShadowTexName));
setRenderTargetCommandBuffer.ClearRenderTarget (true, true, Color.green);
loop.ExecuteCommandBuffer (setRenderTargetCommandBuffer);
setRenderTargetCommandBuffer.Dispose ();
ActiveLight[] activeLights = cullResults.culledLights;
var shadowSlices = packedShadows.shadowSlices;
// Render each light's shadow buffer into a subrect of the shared depth texture
for ( int lightIndex = 0; lightIndex < packedShadows.shadowLights.Length; lightIndex++ )
{
int shadowSliceCount = packedShadows.shadowLights[lightIndex].shadowSliceCount;
if (shadowSliceCount == 0)
continue;
Profiler.BeginSample ("Shadows.GetShadowCasterBounds");
Bounds bounds;
if (!cullResults.GetShadowCasterBounds (lightIndex, out bounds))
{
Profiler.EndSample ();
return;
}
Profiler.EndSample ();
Profiler.BeginSample ("Shadows.DrawShadows");
Matrix4x4 proj;
Matrix4x4 view;
LightType lightType = activeLights[lightIndex].lightType;
Vector3 lightDirection = activeLights[lightIndex].light.transform.forward;
var shadowNearClip = activeLights[lightIndex].light.shadowNearPlane;
int shadowSliceIndex = packedShadows.GetShadowSliceIndex (lightIndex, 0);
if (lightType == LightType.Spot)
{
DrawShadowsSettings settings = new DrawShadowsSettings(cullResults, lightIndex);
bool needRendering = cullResults.ComputeSpotShadowsMatricesAndCullingPrimitives(lightIndex, out view, out proj, out settings.splitData);
SetupShadowSplitMatrices(ref packedShadows.shadowSlices[shadowSliceIndex], proj, view);
if (needRendering)
RenderShadowSplit(ref shadowSlices[shadowSliceIndex], lightDirection, proj, view, ref loop, settings);
}
else if (lightType == LightType.Directional)
{
Vector3 splitRatio = m_Settings.directionalLightCascades;
for (int s = 0; s < 4; ++s)
packedShadows.directionalShadowSplitSphereSqr[s] = new Vector4 (0, 0, 0, float.NegativeInfinity);
for (int s = 0; s < shadowSliceCount; ++s, shadowSliceIndex++)
{
var settings = new DrawShadowsSettings(cullResults, lightIndex);
var shadowResolution = shadowSlices [shadowSliceIndex].shadowResolution;
bool needRendering = cullResults.ComputeDirectionalShadowMatricesAndCullingPrimitives(lightIndex, s, shadowSliceCount, splitRatio, shadowResolution, shadowNearClip, out view, out proj, out settings.splitData);
packedShadows.directionalShadowSplitSphereSqr[s] = settings.splitData.cullingSphere;
packedShadows.directionalShadowSplitSphereSqr[s].w *= packedShadows.directionalShadowSplitSphereSqr[s].w;
SetupShadowSplitMatrices(ref shadowSlices[shadowSliceIndex], proj, view);
if (needRendering)
RenderShadowSplit(ref shadowSlices[shadowSliceIndex], lightDirection, proj, view, ref loop, settings);
}
}
else if (lightType == LightType.Point)
{
for(int s = 0; s < shadowSliceCount; ++s, shadowSliceIndex++)
{
DrawShadowsSettings settings = new DrawShadowsSettings(cullResults, lightIndex);
bool needRendering = cullResults.ComputePointShadowsMatricesAndCullingPrimitives(lightIndex, (CubemapFace)s, 2.0f, out view, out proj, out settings.splitData);
SetupShadowSplitMatrices(ref shadowSlices[shadowSliceIndex], proj, view);
if (needRendering)
RenderShadowSplit(ref shadowSlices[shadowSliceIndex], lightDirection, proj, view, ref loop, settings);
}
}
Profiler.EndSample ();
}
}
private void SetupShadowSplitMatrices(ref ShadowSliceData lightData, Matrix4x4 proj, Matrix4x4 view)
{
Matrix4x4 matScaleBias = Matrix4x4.identity;
matScaleBias.m00 = 0.5f;
matScaleBias.m11 = 0.5f;
matScaleBias.m22 = 0.5f;
matScaleBias.m03 = 0.5f;
matScaleBias.m13 = 0.5f;
matScaleBias.m23 = 0.5f;
Matrix4x4 matTile = Matrix4x4.identity;
matTile.m00 = (float)lightData.shadowResolution / (float)m_Settings.shadowAtlasWidth;
matTile.m11 = (float)lightData.shadowResolution / (float)m_Settings.shadowAtlasHeight;
matTile.m03 = (float)lightData.atlasX / (float)m_Settings.shadowAtlasWidth;
matTile.m13 = (float)lightData.atlasY / (float)m_Settings.shadowAtlasHeight;
lightData.shadowTransform = matTile * matScaleBias * proj * view;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
private void RenderShadowSplit(ref ShadowSliceData slice, Vector3 lightDirection, Matrix4x4 proj, Matrix4x4 view, ref RenderLoop loop, DrawShadowsSettings settings)
{
var commandBuffer = new CommandBuffer();
commandBuffer.name = "ShadowSetup";
// Set viewport / matrices etc
commandBuffer.SetViewport(new Rect(slice.atlasX, slice.atlasY, slice.shadowResolution, slice.shadowResolution));
//commandBuffer.ClearRenderTarget (true, true, Color.green);
commandBuffer.SetGlobalVector("g_vLightDirWs", new Vector4(lightDirection.x, lightDirection.y, lightDirection.z));
commandBuffer.SetProjectionAndViewMatrices(proj, view);
// commandBuffer.SetGlobalDepthBias (1.0F, 1.0F);
loop.ExecuteCommandBuffer(commandBuffer);
commandBuffer.Dispose();
// Render
loop.DrawShadows(ref settings);
}
}
}

12
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs.meta


fileFormatVersion: 2
guid: d1deaacd100a44616a48f9864c979976
timeCreated: 1466770019
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
namespace UnityEngine.ScriptableRenderLoop
{
public abstract class ScriptableRenderLoop : ScriptableObject
{
public abstract void Render(Camera[] cameras, RenderLoop renderLoop);
}
}

12
Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs.meta


fileFormatVersion: 2
guid: 4a2689a80c91a4fb8bec214a015b9cdc
timeCreated: 1466769781
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

35
Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;
namespace UnityEngine.ScriptableRenderLoop
{
//@TODO: This should be moved into GraphicsSettings
[ExecuteInEditMode]
public class ScriptableRenderLoopPicker : MonoBehaviour
{
public ScriptableRenderLoop renderLoop;
void OnEnable ()
{
RenderLoop.renderLoopDelegate += Render;
}
void OnDisable ()
{
RenderLoop.renderLoopDelegate -= Render;
}
bool Render(Camera[] cameras, RenderLoop loop)
{
if (renderLoop == null)
return false;
renderLoop.Render (cameras, loop);
return true;
}
}
}

12
Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs.meta


fileFormatVersion: 2
guid: 92bb16b4ee20841929b24d6bd771738d
timeCreated: 1467028218
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes.meta


fileFormatVersion: 2
guid: d3d521215985c1e4d804878dbdca6a99
folderAsset: yes
timeCreated: 1437475569
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/ForwardRenderLoop.meta


fileFormatVersion: 2
guid: 29953ebbc2b204bb6be8f121555f7029
folderAsset: yes
timeCreated: 1467146873
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity
文件差异内容过多而无法显示
查看文件

8
Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity.meta


fileFormatVersion: 2
guid: 3f8b8744e5e874aafaf0f10408073ecd
timeCreated: 1467028075
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/ForwardRenderLoop/Materials.meta


fileFormatVersion: 2
guid: 0a20b0a0d4f032141b8b3ad8eb2eff9a
folderAsset: yes
timeCreated: 1437475138
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

194
Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: gray
m_Shader: {fileID: 4800000, guid: 908b379d4818cd64184b95a21123d909, type: 3}
m_ShaderKeywords: S_RECEIVE_SHADOWS S_SPECULAR_METALLIC
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap:
OriginalShader: Standard (Specular setup)
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _AlternateLightMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: g_tOverrideLightmap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _BumpScale
second: 1
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DstBlend
second: 0
- first:
name: _Glossiness
second: 0.62
- first:
name: _Metallic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _OcclusionStrengthDirectDiffuse
second: 1
- first:
name: _OcclusionStrengthDirectSpecular
second: 1
- first:
name: _OcclusionStrengthIndirectDiffuse
second: 1
- first:
name: _OcclusionStrengthIndirectSpecular
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _SpecularMode
second: 2
- first:
name: _SrcBlend
second: 1
- first:
name: _UVSec
second: 0
- first:
name: _ZWrite
second: 1
- first:
name: g_bEnableMetallic
second: 0
- first:
name: g_bReceiveShadows
second: 1
- first:
name: g_bUnlit
second: 0
- first:
name: g_bWorldAlignedTexture
second: 0
- first:
name: g_flCubeMapScalar
second: 1
- first:
name: g_flReflectanceBias
second: 0
- first:
name: g_flReflectanceMax
second: 1
- first:
name: g_flReflectanceMin
second: 0
- first:
name: g_flReflectanceScale
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _SpecColor
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: g_vWorldAlignedNormalTangentU
second: {r: -1, g: 0, b: 0, a: 0}
- first:
name: g_vWorldAlignedNormalTangentV
second: {r: 0, g: 0, b: 1, a: 0}
- first:
name: g_vWorldAlignedTextureNormal
second: {r: 0, g: 1, b: 0, a: 0}
- first:
name: g_vWorldAlignedTexturePosition
second: {r: 0, g: 0, b: 0, a: 0}
- first:
name: g_vWorldAlignedTextureSize
second: {r: 1, g: 1, b: 1, a: 0}

8
Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat.meta


fileFormatVersion: 2
guid: b4d74419a10f9614aaf2624ff3c83e80
timeCreated: 1441927681
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

14
ProjectSettings/AudioManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!11 &1
AudioManager:
m_ObjectHideFlags: 0
m_Volume: 1
Rolloff Scale: 1
Doppler Factor: 1
Default Speaker Mode: 2
m_SampleRate: 0
m_DSPBufferSize: 0
m_VirtualVoiceCount: 512
m_RealVoiceCount: 32
m_DisableAudio: 0

6
ProjectSettings/ClusterInputManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!236 &1
ClusterInputManager:
m_ObjectHideFlags: 0
m_Inputs: []

14
ProjectSettings/DynamicsManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
m_Gravity: {x: 0, y: -9.81000042, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
m_SleepThreshold: .00499999989
m_DefaultContactOffset: .00999999978
m_SolverIterationCount: 6
m_RaycastsHitTriggers: 1
m_EnableAdaptiveForce: 0
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

7
ProjectSettings/EditorBuildSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1045 &1
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []

15
ProjectSettings/EditorSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!159 &1
EditorSettings:
m_ObjectHideFlags: 0
serializedVersion: 3
m_ExternalVersionControlSupport: Visible Meta Files
m_SerializationMode: 2
m_WebSecurityEmulationEnabled: 0
m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d
m_DefaultBehaviorMode: 0
m_SpritePackerMode: 2
m_SpritePackerPaddingPower: 1
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
m_ProjectGenerationRootNamespace:

72
ProjectSettings/GraphicsSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 7
m_Deferred:
m_Mode: 0
m_Shader: {fileID: 0}
m_DeferredReflections:
m_Mode: 1
m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
m_ScreenSpaceShadows:
m_Mode: 1
m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
m_LegacyDeferred:
m_Mode: 0
m_Shader: {fileID: 0}
m_DepthNormals:
m_Mode: 1
m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
m_MotionVectors:
m_Mode: 1
m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
m_LightHalo:
m_Mode: 1
m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
m_LensFlare:
m_Mode: 1
m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
m_SpritesDefault:
m_Mode: 1
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
m_AlwaysIncludedShaders:
- {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 4800000, guid: 36c23fe83f8e7a54d8fb168fa6cf2a3d, type: 3}
m_PreloadedShaders: []
m_ShaderSettings_Tier1:
useCascadedShadowMaps: 1
useSinglePassStereoRendering: 0
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_ShaderSettings_Tier2:
useCascadedShadowMaps: 1
useSinglePassStereoRendering: 0
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_ShaderSettings_Tier3:
useCascadedShadowMaps: 1
useSinglePassStereoRendering: 0
standardShaderQuality: 2
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
m_BuildTargetShaderSettings: []
m_LightmapStripping: 0
m_FogStripping: 0
m_LightmapKeepPlain: 1
m_LightmapKeepDirCombined: 1
m_LightmapKeepDirSeparate: 1
m_LightmapKeepDynamicPlain: 1
m_LightmapKeepDynamicDirCombined: 1
m_LightmapKeepDynamicDirSeparate: 1
m_FogKeepLinear: 1
m_FogKeepExp: 1
m_FogKeepExp2: 1

295
ProjectSettings/InputManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!13 &1
InputManager:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton: a
altPositiveButton: d
gravity: 3
dead: .00100000005
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
altNegativeButton: s
altPositiveButton: w
gravity: 3
dead: .00100000005
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton: mouse 0
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton: mouse 1
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left shift
altNegativeButton:
altPositiveButton: mouse 2
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: space
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse X
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: .100000001
snap: 0
invert: 0
type: 1
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse Y
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: .100000001
snap: 0
invert: 0
type: 1
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Mouse ScrollWheel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: .100000001
snap: 0
invert: 0
type: 1
axis: 2
joyNum: 0
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: .189999998
sensitivity: 1
snap: 0
invert: 0
type: 2
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: .189999998
sensitivity: 1
snap: 0
invert: 1
type: 2
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 0
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 1
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 2
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 3
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: return
altNegativeButton:
altPositiveButton: joystick button 0
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: enter
altNegativeButton:
altPositiveButton: space
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Cancel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: escape
altNegativeButton:
altPositiveButton: joystick button 1
gravity: 1000
dead: .00100000005
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0

71
ProjectSettings/NavMeshAreas.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!126 &1
NavMeshAreas:
m_ObjectHideFlags: 0
serializedVersion: 2
areas:
- name: Walkable
cost: 1
- name: Not Walkable
cost: 1
- name: Jump
cost: 2
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1
- name:
cost: 1

8
ProjectSettings/NetworkManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!149 &1
NetworkManager:
m_ObjectHideFlags: 0
m_DebugLevel: 0
m_Sendrate: 15
m_AssetToPrefab: {}

24
ProjectSettings/Physics2DSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
m_Gravity: {x: 0, y: -9.81000042}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8
m_PositionIterations: 3
m_VelocityThreshold: 1
m_MaxLinearCorrection: .200000003
m_MaxAngularCorrection: 8
m_MaxTranslationSpeed: 100
m_MaxRotationSpeed: 360
m_MinPenetrationForPenalty: .00999999978
m_BaumgarteScale: .200000003
m_BaumgarteTimeOfImpactScale: .75
m_TimeToSleep: .5
m_LinearSleepTolerance: .00999999978
m_AngularSleepTolerance: 2
m_RaycastsHitTriggers: 1
m_RaycastsStartInColliders: 1
m_ChangeStopsCallbacks: 0
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

544
ProjectSettings/ProjectSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
AndroidProfiler: 0
defaultScreenOrientation: 4
targetDevice: 2
useOnDemandResources: 0
accelerometerFrequency: 60
companyName: DefaultCompany
productName: dev
defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0}
m_SplashScreenStyle: 0
m_ShowUnitySplashScreen: 0
m_VirtualRealitySplashScreen: {fileID: 0}
defaultScreenWidth: 1024
defaultScreenHeight: 768
defaultScreenWidthWeb: 960
defaultScreenHeightWeb: 600
m_RenderingPath: 1
m_MobileRenderingPath: 1
m_ActiveColorSpace: 1
m_MTRendering: 1
m_MobileMTRendering: 0
m_StackTraceTypes: 010000000100000001000000010000000100000001000000
iosShowActivityIndicatorOnLoading: -1
androidShowActivityIndicatorOnLoading: -1
iosAppInBackgroundBehavior: 0
displayResolutionDialog: 2
iosAllowHTTPDownload: 1
allowedAutorotateToPortrait: 1
allowedAutorotateToPortraitUpsideDown: 1
allowedAutorotateToLandscapeRight: 1
allowedAutorotateToLandscapeLeft: 1
useOSAutorotation: 1
use32BitDisplayBuffer: 1
disableDepthAndStencilBuffers: 0
defaultIsFullScreen: 0
defaultIsNativeResolution: 1
runInBackground: 1
captureSingleScreen: 0
Override IPod Music: 0
Prepare IOS For Recording: 0
submitAnalytics: 1
usePlayerLog: 1
bakeCollisionMeshes: 0
forceSingleInstance: 0
resizableWindow: 1
useMacAppStoreValidation: 0
gpuSkinning: 0
graphicsJobs: 1
xboxPIXTextureCapture: 0
xboxEnableAvatar: 0
xboxEnableKinect: 0
xboxEnableKinectAutoTracking: 0
xboxEnableFitness: 0
visibleInBackground: 1
allowFullscreenSwitch: 1
macFullscreenMode: 2
d3d9FullscreenMode: 1
d3d11FullscreenMode: 1
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0
xboxEnablePIXSampling: 0
n3dsDisableStereoscopicView: 0
n3dsEnableSharedListOpt: 1
n3dsEnableVSync: 0
uiUse16BitDepthBuffer: 0
ignoreAlphaClear: 0
xboxOneResolution: 0
ps3SplashScreen: {fileID: 0}
videoMemoryForVertexBuffers: 0
psp2PowerMode: 0
psp2AcquireBGM: 1
wiiUTVResolution: 0
wiiUGamePadMSAA: 1
wiiUSupportsNunchuk: 0
wiiUSupportsClassicController: 0
wiiUSupportsBalanceBoard: 0
wiiUSupportsMotionPlus: 0
wiiUSupportsProController: 0
wiiUAllowScreenCapture: 1
wiiUControllerCount: 0
m_SupportedAspectRatios:
4:3: 1
5:4: 1
16:10: 1
16:9: 1
Others: 1
bundleIdentifier: com.Company.ProductName
bundleVersion: 1.0
preloadedAssets: []
metroEnableIndependentInputSource: 0
xboxOneDisableKinectGpuReservation: 0
singlePassStereoRendering: 0
protectGraphicsMemory: 0
productGUID: 900e9e40d20cd3e44ad40e5b00239dcc
AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 9
AndroidPreferredInstallLocation: 1
aotOptions:
apiCompatibilityLevel: 2
stripEngineCode: 1
iPhoneStrippingLevel: 0
iPhoneScriptCallOptimization: 0
iPhoneBuildNumber: 0
ForceInternetPermission: 0
ForceSDCardPermission: 0
CreateWallpaper: 0
APKExpansionFiles: 0
preloadShaders: 0
StripUnusedMeshComponents: 0
VertexChannelCompressionMask:
serializedVersion: 2
m_Bits: 238
iPhoneSdkVersion: 988
iPhoneTargetOSVersion: 22
tvOSSdkVersion: 0
tvOSTargetOSVersion: 900
uIPrerenderedIcon: 0
uIRequiresPersistentWiFi: 0
uIRequiresFullScreen: 1
uIStatusBarHidden: 1
uIExitOnSuspend: 0
uIStatusBarStyle: 0
iPhoneSplashScreen: {fileID: 0}
iPhoneHighResSplashScreen: {fileID: 0}
iPhoneTallHighResSplashScreen: {fileID: 0}
iPhone47inSplashScreen: {fileID: 0}
iPhone55inPortraitSplashScreen: {fileID: 0}
iPhone55inLandscapeSplashScreen: {fileID: 0}
iPadPortraitSplashScreen: {fileID: 0}
iPadHighResPortraitSplashScreen: {fileID: 0}
iPadLandscapeSplashScreen: {fileID: 0}
iPadHighResLandscapeSplashScreen: {fileID: 0}
appleTVSplashScreen: {fileID: 0}
tvOSSmallIconLayers: []
tvOSLargeIconLayers: []
tvOSTopShelfImageLayers: []
iOSLaunchScreenType: 0
iOSLaunchScreenPortrait: {fileID: 0}
iOSLaunchScreenLandscape: {fileID: 0}
iOSLaunchScreenBackgroundColor:
serializedVersion: 2
rgba: 0
iOSLaunchScreenFillPct: 100
iOSLaunchScreenSize: 100
iOSLaunchScreenCustomXibPath:
iOSLaunchScreeniPadType: 0
iOSLaunchScreeniPadImage: {fileID: 0}
iOSLaunchScreeniPadBackgroundColor:
serializedVersion: 2
rgba: 0
iOSLaunchScreeniPadFillPct: 100
iOSLaunchScreeniPadSize: 100
iOSLaunchScreeniPadCustomXibPath:
iOSDeviceRequirements: []
iOSURLSchemes: []
AndroidTargetDevice: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName:
AndroidKeyaliasName:
AndroidTVCompatibility: 1
AndroidIsGame: 1
androidEnableBanner: 1
m_AndroidBanners:
- width: 320
height: 180
banner: {fileID: 0}
androidGamepadSupportLevel: 0
resolutionDialogBanner: {fileID: 0}
m_BuildTargetIcons:
- m_BuildTarget:
m_Icons:
- serializedVersion: 2
m_Icon: {fileID: 0}
m_Width: 128
m_Height: 128
m_BuildTargetBatching:
- m_BuildTarget: Standalone
m_StaticBatching: 0
m_DynamicBatching: 0
m_BuildTargetGraphicsAPIs:
- m_BuildTarget: WindowsStandaloneSupport
m_APIs: 0200000001000000
m_Automatic: 1
webPlayerTemplate: APPLICATION:Default
m_TemplateCustomTags: {}
wiiUTitleID: 0005000011000000
wiiUGroupID: 00010000
wiiUCommonSaveSize: 4096
wiiUAccountSaveSize: 2048
wiiUOlvAccessKey: 0
wiiUTinCode: 0
wiiUJoinGameId: 0
wiiUJoinGameModeMask: 0000000000000000
wiiUCommonBossSize: 0
wiiUAccountBossSize: 0
wiiUAddOnUniqueIDs: []
wiiUMainThreadStackSize: 3072
wiiULoaderThreadStackSize: 1024
wiiUSystemHeapSize: 128
wiiUTVStartupScreen: {fileID: 0}
wiiUGamePadStartupScreen: {fileID: 0}
wiiUProfilerLibPath:
actionOnDotNetUnhandledException: 1
enableInternalProfiler: 0
logObjCUncaughtExceptions: 1
enableCrashReportAPI: 0
locationUsageDescription:
XboxTitleId:
XboxImageXexPath:
XboxSpaPath:
XboxGenerateSpa: 0
XboxDeployKinectResources: 0
XboxSplashScreen: {fileID: 0}
xboxEnableSpeech: 0
xboxAdditionalTitleMemorySize: 0
xboxDeployKinectHeadOrientation: 0
xboxDeployKinectHeadPosition: 0
ps3TitleConfigPath:
ps3DLCConfigPath:
ps3ThumbnailPath:
ps3BackgroundPath:
ps3SoundPath:
ps3NPAgeRating: 12
ps3TrophyCommId:
ps3NpCommunicationPassphrase:
ps3TrophyPackagePath:
ps3BootCheckMaxSaveGameSizeKB: 128
ps3TrophyCommSig:
ps3SaveGameSlots: 1
ps3TrialMode: 0
ps3VideoMemoryForAudio: 0
ps3EnableVerboseMemoryStats: 0
ps3UseSPUForUmbra: 0
ps3EnableMoveSupport: 1
ps3DisableDolbyEncoding: 0
ps4NPAgeRating: 12
ps4NPTitleSecret:
ps4NPTrophyPackPath:
ps4ParentalLevel: 1
ps4ContentID: ED1633-NPXX51362_00-0000000000000000
ps4Category: 0
ps4MasterVersion: 01.00
ps4AppVersion: 01.00
ps4AppType: 0
ps4ParamSfxPath:
ps4VideoOutPixelFormat: 0
ps4VideoOutResolution: 4
ps4PronunciationXMLPath:
ps4PronunciationSIGPath:
ps4BackgroundImagePath:
ps4StartupImagePath:
ps4SaveDataImagePath:
ps4SdkOverride:
ps4BGMPath:
ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir:
ps4EnterButtonAssignment: 1
ps4ApplicationParam1: 0
ps4ApplicationParam2: 0
ps4ApplicationParam3: 0
ps4ApplicationParam4: 0
ps4DownloadDataSize: 0
ps4GarlicHeapSize: 2048
ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ
ps4UseDebugIl2cppLibs: 0
ps4pnSessions: 1
ps4pnPresence: 1
ps4pnFriends: 1
ps4pnGameCustomData: 1
playerPrefsSupport: 0
ps4ReprojectionSupport: 0
ps4UseAudio3dBackend: 0
ps4SocialScreenEnabled: 0
ps4Audio3dVirtualSpeakerCount: 14
ps4attribCpuUsage: 0
ps4PatchPkgPath:
ps4PatchLatestPkgPath:
ps4PatchChangeinfoPath:
ps4attribUserManagement: 0
ps4attribMoveSupport: 0
ps4attrib3DSupport: 0
ps4attribShareSupport: 0
ps4IncludedModules: []
monoEnv:
psp2Splashimage: {fileID: 0}
psp2NPTrophyPackPath:
psp2NPSupportGBMorGJP: 0
psp2NPAgeRating: 12
psp2NPTitleDatPath:
psp2NPCommsID:
psp2NPCommunicationsID:
psp2NPCommsPassphrase:
psp2NPCommsSig:
psp2ParamSfxPath:
psp2ManualPath:
psp2LiveAreaGatePath:
psp2LiveAreaBackroundPath:
psp2LiveAreaPath:
psp2LiveAreaTrialPath:
psp2PatchChangeInfoPath:
psp2PatchOriginalPackage:
psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui
psp2KeystoneFile:
psp2MemoryExpansionMode: 0
psp2DRMType: 0
psp2StorageType: 0
psp2MediaCapacity: 0
psp2DLCConfigPath:
psp2ThumbnailPath:
psp2BackgroundPath:
psp2SoundPath:
psp2TrophyCommId:
psp2TrophyPackagePath:
psp2PackagedResourcesPath:
psp2SaveDataQuota: 10240
psp2ParentalLevel: 1
psp2ShortTitle: Not Set
psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF
psp2Category: 0
psp2MasterVersion: 01.00
psp2AppVersion: 01.00
psp2TVBootMode: 0
psp2EnterButtonAssignment: 2
psp2TVDisableEmu: 0
psp2AllowTwitterDialog: 1
psp2Upgradable: 0
psp2HealthWarning: 0
psp2UseLibLocation: 0
psp2InfoBarOnStartup: 0
psp2InfoBarColor: 0
psp2UseDebugIl2cppLibs: 0
psmSplashimage: {fileID: 0}
spritePackerPolicy:
scriptingDefineSymbols: {}
metroPackageName: dev
metroPackageVersion:
metroCertificatePath:
metroCertificatePassword:
metroCertificateSubject:
metroCertificateIssuer:
metroCertificateNotAfter: 0000000000000000
metroApplicationDescription: dev
wsaImages: {}
metroTileShortName:
metroCommandLineArgsFile:
metroTileShowName: 0
metroMediumTileShowName: 0
metroLargeTileShowName: 0
metroWideTileShowName: 0
metroDefaultTileSize: 1
metroTileForegroundText: 1
metroTileBackgroundColor: {r: 0, g: 0, b: 0, a: 1}
metroSplashScreenBackgroundColor: {r: 0, g: 0, b: 0, a: 1}
metroSplashScreenUseBackgroundColor: 0
platformCapabilities: {}
metroFTAName:
metroFTAFileTypes: []
metroProtocolName:
metroCompilationOverrides: 1
tizenProductDescription:
tizenProductURL:
tizenSigningProfileName:
tizenGPSPermissions: 0
tizenMicrophonePermissions: 0
n3dsUseExtSaveData: 0
n3dsCompressStaticMem: 1
n3dsExtSaveDataNumber: 0x12345
n3dsStackSize: 131072
n3dsTargetPlatform: 2
n3dsRegion: 7
n3dsMediaSize: 0
n3dsLogoStyle: 3
n3dsTitle: GameName
n3dsProductCode:
n3dsApplicationId: 0xFF3FF
stvDeviceAddress:
stvProductDescription:
stvProductAuthor:
stvProductAuthorEmail:
stvProductLink:
stvProductCategory: 0
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:
XboxOneContentId:
XboxOneTitleId:
XboxOneSCId:
XboxOneGameOsOverridePath:
XboxOnePackagingOverridePath:
XboxOneAppManifestOverridePath:
XboxOnePackageEncryption: 0
XboxOnePackageUpdateGranularity: 2
XboxOneDescription:
XboxOneIsContentPackage: 0
XboxOneEnableGPUVariability: 0
XboxOneSockets: {}
XboxOneSplashScreen: {fileID: 0}
XboxOneAllowedProductIds: []
XboxOnePersistentLocalStorageSize: 0
intPropertyNames:
- Android::ScriptingBackend
- Metro::ScriptingBackend
- Standalone::ScriptingBackend
- WP8::ScriptingBackend
- WebGL::ScriptingBackend
- WebGL::audioCompressionFormat
- WebGL::exceptionSupport
- WebGL::memorySize
- iOS::Architecture
- iOS::EnableIncrementalBuildSupportForIl2cpp
- iOS::ScriptingBackend
Android::ScriptingBackend: 0
Metro::ScriptingBackend: 2
Standalone::ScriptingBackend: 0
WP8::ScriptingBackend: 2
WebGL::ScriptingBackend: 1
WebGL::audioCompressionFormat: 4
WebGL::exceptionSupport: 1
WebGL::memorySize: 256
iOS::Architecture: 2
iOS::EnableIncrementalBuildSupportForIl2cpp: 0
iOS::ScriptingBackend: 1
boolPropertyNames:
- Android::VR::enable
- Metro::VR::enable
- N3DS::VR::enable
- PS3::VR::enable
- PS4::VR::enable
- PSM::VR::enable
- PSP2::VR::enable
- SamsungTV::VR::enable
- Standalone::VR::enable
- Tizen::VR::enable
- WebGL::VR::enable
- WebGL::analyzeBuildSize
- WebGL::dataCaching
- WebGL::useEmbeddedResources
- WebPlayer::VR::enable
- WiiU::VR::enable
- Xbox360::VR::enable
- XboxOne::VR::enable
- XboxOne::enus
- iOS::VR::enable
- tvOS::VR::enable
Android::VR::enable: 0
Metro::VR::enable: 0
N3DS::VR::enable: 0
PS3::VR::enable: 0
PS4::VR::enable: 0
PSM::VR::enable: 0
PSP2::VR::enable: 0
SamsungTV::VR::enable: 0
Standalone::VR::enable: 0
Tizen::VR::enable: 0
WebGL::VR::enable: 0
WebGL::analyzeBuildSize: 0
WebGL::dataCaching: 0
WebGL::useEmbeddedResources: 0
WebPlayer::VR::enable: 0
WiiU::VR::enable: 0
Xbox360::VR::enable: 0
XboxOne::VR::enable: 0
XboxOne::enus: 1
iOS::VR::enable: 0
tvOS::VR::enable: 0
stringPropertyNames:
- Analytics_ServiceEnabled::Analytics_ServiceEnabled
- Build_ServiceEnabled::Build_ServiceEnabled
- Collab_ServiceEnabled::Collab_ServiceEnabled
- ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled
- Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled
- Hub_ServiceEnabled::Hub_ServiceEnabled
- Purchasing_ServiceEnabled::Purchasing_ServiceEnabled
- UNet_ServiceEnabled::UNet_ServiceEnabled
- Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled
- WebGL::emscriptenArgs
- WebGL::template
- additionalIl2CppArgs::additionalIl2CppArgs
Analytics_ServiceEnabled::Analytics_ServiceEnabled: False
Build_ServiceEnabled::Build_ServiceEnabled: False
Collab_ServiceEnabled::Collab_ServiceEnabled: False
ErrorHub_ServiceEnabled::ErrorHub_ServiceEnabled: False
Game_Performance_ServiceEnabled::Game_Performance_ServiceEnabled: False
Hub_ServiceEnabled::Hub_ServiceEnabled: False
Purchasing_ServiceEnabled::Purchasing_ServiceEnabled: False
UNet_ServiceEnabled::UNet_ServiceEnabled: False
Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled: False
WebGL::emscriptenArgs:
WebGL::template: APPLICATION:Default
additionalIl2CppArgs::additionalIl2CppArgs:
vectorPropertyNames:
- Android::VR::enabledDevices
- Metro::VR::enabledDevices
- N3DS::VR::enabledDevices
- PS3::VR::enabledDevices
- PS4::VR::enabledDevices
- PSM::VR::enabledDevices
- PSP2::VR::enabledDevices
- SamsungTV::VR::enabledDevices
- Standalone::VR::enabledDevices
- Tizen::VR::enabledDevices
- WebGL::VR::enabledDevices
- WebPlayer::VR::enabledDevices
- WiiU::VR::enabledDevices
- Xbox360::VR::enabledDevices
- XboxOne::VR::enabledDevices
- iOS::VR::enabledDevices
- tvOS::VR::enabledDevices
Android::VR::enabledDevices:
- Oculus
Metro::VR::enabledDevices: []
N3DS::VR::enabledDevices: []
PS3::VR::enabledDevices: []
PS4::VR::enabledDevices:
- PlayStationVR
PSM::VR::enabledDevices: []
PSP2::VR::enabledDevices: []
SamsungTV::VR::enabledDevices: []
Standalone::VR::enabledDevices:
- Oculus
Tizen::VR::enabledDevices: []
WebGL::VR::enabledDevices: []
WebPlayer::VR::enabledDevices: []
WiiU::VR::enabledDevices: []
Xbox360::VR::enabledDevices: []
XboxOne::VR::enabledDevices: []
iOS::VR::enabledDevices: []
tvOS::VR::enabledDevices: []
cloudProjectId:
projectName:
organizationId:
cloudEnabled: 0

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 5.4.0b19
m_StandardAssetsVersion: 0

182
ProjectSettings/QualitySettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!47 &1
QualitySettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_CurrentQuality: 5
m_QualitySettings:
- serializedVersion: 2
name: Fastest
pixelLightCount: 0
shadows: 0
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 15
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 0
lodBias: 0.3
maximumLODLevel: 0
particleRaycastBudget: 4
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Fast
pixelLightCount: 0
shadows: 0
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 20
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 0
lodBias: 0.4
maximumLODLevel: 0
particleRaycastBudget: 16
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Simple
pixelLightCount: 1
shadows: 1
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 20
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 1
lodBias: 0.7
maximumLODLevel: 0
particleRaycastBudget: 64
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Good
pixelLightCount: 2
shadows: 2
shadowResolution: 1
shadowProjection: 1
shadowCascades: 2
shadowDistance: 40
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 1
maximumLODLevel: 0
particleRaycastBudget: 256
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Beautiful
pixelLightCount: 3
shadows: 2
shadowResolution: 2
shadowProjection: 1
shadowCascades: 2
shadowDistance: 70
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 1.5
maximumLODLevel: 0
particleRaycastBudget: 1024
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Fantastic
pixelLightCount: 4
shadows: 2
shadowResolution: 2
shadowProjection: 1
shadowCascades: 4
shadowDistance: 45.9
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.021409363, y: 0.051549375, z: 0.07213539}
blendWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 2
maximumLODLevel: 0
particleRaycastBudget: 4096
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2
Nintendo 3DS: 5
PS3: 5
PS4: 5
PSM: 5
PSP2: 2
Samsung TV: 2
Standalone: 5
Tizen: 2
Web: 5
WebGL: 3
WiiU: 5
Windows Store Apps: 5
XBOX360: 5
XboxOne: 5
iPhone: 2
tvOS: 5

182
ProjectSettings/QualitySettings.asset.orig


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!47 &1
QualitySettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_CurrentQuality: 5
m_QualitySettings:
- serializedVersion: 2
name: Fastest
pixelLightCount: 0
shadows: 0
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 15
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 0
lodBias: 0.3
maximumLODLevel: 0
particleRaycastBudget: 4
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Fast
pixelLightCount: 0
shadows: 0
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 20
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 0
lodBias: 0.4
maximumLODLevel: 0
particleRaycastBudget: 16
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Simple
pixelLightCount: 1
shadows: 1
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
shadowDistance: 20
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
vSyncCount: 1
lodBias: 0.7
maximumLODLevel: 0
particleRaycastBudget: 64
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Good
pixelLightCount: 2
shadows: 2
shadowResolution: 1
shadowProjection: 1
shadowCascades: 2
shadowDistance: 40
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 1
maximumLODLevel: 0
particleRaycastBudget: 256
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Beautiful
pixelLightCount: 3
shadows: 2
shadowResolution: 2
shadowProjection: 1
shadowCascades: 2
shadowDistance: 70
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
blendWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 1.5
maximumLODLevel: 0
particleRaycastBudget: 1024
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
- serializedVersion: 2
name: Fantastic
pixelLightCount: 4
shadows: 2
shadowResolution: 2
shadowProjection: 1
shadowCascades: 4
shadowDistance: 150
shadowNearPlaneOffset: 2
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.05656562, y: 0.29764313, z: 0.46666664}
blendWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
vSyncCount: 1
lodBias: 2
maximumLODLevel: 0
particleRaycastBudget: 4096
asyncUploadTimeSlice: 2
asyncUploadBufferSize: 4
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2
Nintendo 3DS: 5
PS3: 5
PS4: 5
PSM: 5
PSP2: 2
Samsung TV: 2
Standalone: 5
Tizen: 2
Web: 5
WebGL: 3
WiiU: 5
Windows Store Apps: 5
XBOX360: 5
XboxOne: 5
iPhone: 2
tvOS: 5

43
ProjectSettings/TagManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
layers:
- Default
- TransparentFX
- Ignore Raycast
-
- Water
- UI
-
-
- Don't Shadow Cast
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m_SortingLayers:
- name: Default
uniqueID: 0
locked: 0

8
ProjectSettings/TimeManager.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!5 &1
TimeManager:
m_ObjectHideFlags: 0
Fixed Timestep: .0199999996
Maximum Allowed Timestep: .333333343
m_TimeScale: 1

11
ProjectSettings/UnityAdsSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!292 &1
UnityAdsSettings:
m_ObjectHideFlags: 0
m_Enabled: 0
m_InitializeOnStartup: 1
m_TestMode: 0
m_EnabledPlatforms: 4294967295
m_IosGameId:
m_AndroidGameId:

14
ProjectSettings/UnityConnectSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!310 &1
UnityConnectSettings:
m_ObjectHideFlags: 0
UnityPurchasingSettings:
m_Enabled: 0
m_TestMode: 0
UnityAnalyticsSettings:
m_Enabled: 0
m_InitializeOnStartup: 1
m_TestMode: 0
m_TestEventUrl:
m_TestConfigUrl:
正在加载...
取消
保存