浏览代码

HDRenderLoop: Clean some formatting error + fix issue with define

/main
sebastienlagarde 8 年前
当前提交
8cac0660
共有 5 个文件被更改,包括 118 次插入118 次删除
  1. 177
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader
  2. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  3. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl
  4. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  5. 37
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl

177
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader


Shader "Hidden/HDRenderLoop/DebugViewTiles"
{
SubShader
SubShader
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertViewTiles
#pragma fragment FragViewTiles
#define LIGHTLOOP_TILE_PASS 1
#define USE_FPTL_LIGHTLIST 1 //TODO: make it also work with clustered
#define LIGHTLOOP_TILE_ALL 1
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#include "Common.hlsl"
#pragma vertex VertViewTiles
#pragma fragment FragViewTiles
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl
#define LIGHTLOOP_TILE_PASS 1
#define USE_FPTL_LIGHTLIST 1 //TODO: make it also work with clustered
#define LIGHTLOOP_TILE_ALL 1
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
uint _ViewTilesFlags;
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
#include "Common.hlsl"
float4 VertViewTiles(float3 positionOS : POSITION): SV_POSITION
{
return TransformWorldToHClip(TransformObjectToWorld(positionOS));
}
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl
float4 OverlayHeatMap(uint2 pixCoord, uint numLights)
{
const float4 kRadarColors[12] =
{
float4(0.0, 0.0, 0.0, 0.0), // black
float4(0.0, 0.0, 0.6, 0.5), // dark blue
float4(0.0, 0.0, 0.9, 0.5), // blue
float4(0.0, 0.6, 0.9, 0.5), // light blue
float4(0.0, 0.9, 0.9, 0.5), // cyan
float4(0.0, 0.9, 0.6, 0.5), // blueish green
float4(0.0, 0.9, 0.0, 0.5), // green
float4(0.6, 0.9, 0.0, 0.5), // yellowish green
float4(0.9, 0.9, 0.0, 0.5), // yellow
float4(0.9, 0.6, 0.0, 0.5), // orange
float4(0.9, 0.0, 0.0, 0.5), // red
float4(1.0, 0.0, 0.0, 0.9) // strong red
};
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
float maxNrLightsPerTile = 31;
uint _ViewTilesFlags;
int nColorIndex = numLights == 0 ? 0 : (1 + (int)floor(10 * (log2((float)numLights) / log2(maxNrLightsPerTile))));
nColorIndex = nColorIndex<0 ? 0 : nColorIndex;
float4 col = nColorIndex>11 ? float4(1.0, 1.0, 1.0, 1.0) : kRadarColors[nColorIndex];
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
int2 coord = pixCoord - int2(1, 1);
float4 VertViewTiles(float3 positionOS : POSITION): SV_POSITION
{
return TransformWorldToHClip(TransformObjectToWorld(positionOS));
}
float4 color = float4(pow(col.xyz, 2.2), 0.3*col.w);
if (numLights > 0)
{
if (SampleDebugFontNumber(coord, numLights)) // Shadow
color = float4(0, 0, 0, 1);
if (SampleDebugFontNumber(coord + 1, numLights)) // Text
color = float4(1, 1, 1, 1);
}
return color;
}
float4 FragViewTiles(float4 positionCS : SV_POSITION) : SV_Target
{
Coordinate coord = GetCoordinate(positionCS.xy, _ScreenSize.zw);
float4 FragViewTiles(float4 positionCS : SV_POSITION) : SV_Target
{
Coordinate coord = GetCoordinate(positionCS.xy, _ScreenSize.zw);
#if USE_FPTL_LIGHTLIST
float linearDepth = 0.0f;
#else
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).x;
float linearDepth = GetLinearDepth(depth);
#endif
int n = 0;
if(_ViewTilesFlags & DEBUGVIEWTILESFLAGS_DIRECT_LIGHTING)
{
uint punctualLightStart;
uint punctualLightCount;
GetCountAndStart(coord, DIRECT_LIGHT, linearDepth, punctualLightStart, punctualLightCount);
n += punctualLightCount;
}
#if USE_FPTL_LIGHTLIST
float linearDepth = 0.0;
#else
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, coord.unPositionSS).x;
float linearDepth = GetLinearDepth(depth);
#endif
if(_ViewTilesFlags & DEBUGVIEWTILESFLAGS_REFLECTION)
{
uint envLightStart;
uint envLightCount;
GetCountAndStart(coord, REFLECTION_LIGHT, linearDepth, envLightStart, envLightCount);
n += envLightCount;
}
int n = 0;
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_DIRECT_LIGHTING)
{
uint punctualLightStart;
uint punctualLightCount;
GetCountAndStart(coord, DIRECT_LIGHT, linearDepth, punctualLightStart, punctualLightCount);
n += punctualLightCount;
}
if(n > 0)
{
return OverlayHeatMap(int2(coord.unPositionSS.xy) & 15, n);
}
else
{
return 0.0f;
}
}
if (_ViewTilesFlags & DEBUGVIEWTILESFLAGS_REFLECTION)
{
uint envLightStart;
uint envLightCount;
GetCountAndStart(coord, REFLECTION_LIGHT, linearDepth, envLightStart, envLightCount);
n += envLightCount;
}
ENDHLSL
}
if (n > 0)
{
return OverlayHeatMap(int2(coord.unPositionSS.xy) & 15, n);
}
else
{
return 0.0;
}
}
ENDHLSL
}
Fallback Off
}
Fallback Off
}

6
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


index++;
localIndex++;
}
}
}
public override void OnInspectorGUI()
{

EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.tileLightLoopSettings);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUI.BeginChangeCheck();
renderLoop.tilePassLightLoop.debugViewTilesFlags = (TilePass.DebugViewTilesFlags)EditorGUILayout.EnumMaskField("DebugView Tiles", renderLoop.tilePassLightLoop.debugViewTilesFlags);
renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass = EditorGUILayout.Toggle(styles.directIndirectSinglePass, renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass);
renderLoop.tilePassLightLoop.enableBigTilePrepass = EditorGUILayout.Toggle(styles.bigTilePrepass, renderLoop.tilePassLightLoop.enableBigTilePrepass);

4
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl


#ifdef LIGHTLOOP_SINGLE_PASS
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl"
#elif LIGHTLOOP_TILE_PASS
#elif defined(LIGHTLOOP_TILE_PASS)
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.hlsl"
#endif

// LightLoop use evaluation BSDF function for light type define in Material.hlsl
#ifdef LIGHTLOOP_SINGLE_PASS
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePassLoop.hlsl"
#elif LIGHTLOOP_TILE_PASS
#elif defined(LIGHTLOOP_TILE_PASS)
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl"
#endif

12
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs


public static int NR_LIGHT_MODELS = 2;
public static int DIRECT_LIGHT = 0;
public static int REFLECTION_LIGHT = 1;
}
}
[GenerateHLSL]
public enum DebugViewTilesFlags
{

public Vector3 center; // a center in camera space inside the bounding volume of the light source.
public Vector2 scaleXY;
public float radius;
};
};
[GenerateHLSL]
public struct SFiniteLightData

}
//}
if(debugViewTilesFlags != 0)
{
cmd.Blit(null, cameraColorBufferRT, m_DebugViewTilesMaterial, 0);
if(debugViewTilesFlags != 0)
{
cmd.Blit(null, cameraColorBufferRT, m_DebugViewTilesMaterial, 0);
}
renderLoop.ExecuteCommandBuffer(cmd);

37
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl


// LightLoop
// ----------------------------------------------------------------------------
float4 OverlayHeatMap(uint2 pixCoord, uint numLights)
{
const float4 kRadarColors[12] =
{
float4(0.0,0.0,0.0,0.0), // black
float4(0.0,0.0,0.6,0.5), // dark blue
float4(0.0,0.0,0.9,0.5), // blue
float4(0.0,0.6,0.9,0.5), // light blue
float4(0.0,0.9,0.9,0.5), // cyan
float4(0.0,0.9,0.6,0.5), // blueish green
float4(0.0,0.9,0.0,0.5), // green
float4(0.6,0.9,0.0,0.5), // yellowish green
float4(0.9,0.9,0.0,0.5), // yellow
float4(0.9,0.6,0.0,0.5), // orange
float4(0.9,0.0,0.0,0.5), // red
float4(1.0,0.0,0.0,0.9) // strong red
};
float maxNrLightsPerTile = 31;
int nColorIndex = numLights == 0 ? 0 : (1 + (int)floor(10 * (log2((float)numLights) / log2(maxNrLightsPerTile))));
nColorIndex = nColorIndex<0 ? 0 : nColorIndex;
float4 col = nColorIndex>11 ? float4(1.0, 1.0, 1.0, 1.0) : kRadarColors[nColorIndex];
int2 coord = pixCoord - int2(1, 1);
float4 color = float4(pow(col.xyz, 2.2), 0.3*col.w);
if (numLights > 0)
{
if (SampleDebugFontNumber(coord, numLights)) // Shadow
color = float4(0,0,0,1);
if (SampleDebugFontNumber(coord + 1, numLights)) // Text
color = float4(1,1,1,1);
}
return color;
}
// Calculate the offset in global light index light for current light category
int GetTileOffset(Coordinate coord, uint lightCategory)
{

正在加载...
取消
保存