浏览代码

Remove multiple definitions of the light sampling texture dimensions

/main
Evgenii Golubev 8 年前
当前提交
fff4efdf
共有 4 个文件被更改,包括 59 次插入40 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/BuildProbabilityTables.compute
  2. 59
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/GGXConvolve.shader
  3. 22
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
  4. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs.hlsl

4
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/BuildProbabilityTables.compute


/* --- Input --- */
#define TEXTURE_HEIGHT 256 // MIS equiareal texture map: cos(theta) = 1.0 - 2.0 * v
#define TEXTURE_WIDTH 2 * TEXTURE_HEIGHT // MIS equiareal texture map: phi = TWO_PI * (1.0 - u)
#define TEXTURE_HEIGHT 256 // Equiareal texture map: cos(theta) = 1.0 - 2.0 * v
#define TEXTURE_WIDTH 2 * TEXTURE_HEIGHT // Equiareal texture map: phi = TWO_PI * (1.0 - u)
TEXTURECUBE(envMap); // Input cubemap
SAMPLERCUBE(sampler_envMap);

59
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/GGXConvolve.shader


#include "Common.hlsl"
#include "ImageBasedLighting.hlsl"
#include "../SkyManager.cs.hlsl"
struct Attributes
{

SAMPLERCUBE(sampler_MainTex);
#ifdef USE_MIS
#define TEXTURE_HEIGHT_MIS 256
#define TEXTURE_WIDTH_MIS 2 * TEXTURE_HEIGHT_MIS
TEXTURE2D(_MarginalRowDensities);
TEXTURE2D(_ConditionalDensities);
#endif

float perceptualRoughness = mipmapLevelToPerceptualRoughness(_Level);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
#ifdef USE_MIS
float4 val = IntegrateLD_MIS(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
_MarginalRowDensities, _ConditionalDensities,
V, N,
roughness,
_InvOmegaP,
TEXTURE_WIDTH_MIS,
TEXTURE_HEIGHT_MIS,
1024,
false);
#else
uint sampleCount = 0;
switch (_Level)
{
case 1: sampleCount = 21; break;
case 2: sampleCount = 34; break;
case 3: sampleCount = 55; break;
case 4: sampleCount = 89; break;
case 5: sampleCount = 89; break;
case 6: sampleCount = 89; break; // UNITY_SPECCUBE_LOD_STEPS
}
float4 val = IntegrateLD(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
#ifdef USE_MIS
float4 val = IntegrateLD_MIS(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
_MarginalRowDensities, _ConditionalDensities,
_MaxLevel,
sampleCount, // Must be a Fibonacci number
true);
#endif
LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH,
LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT,
1024,
false);
#else
uint sampleCount = 0;
switch (_Level)
{
case 1: sampleCount = 21; break;
case 2: sampleCount = 34; break;
case 3: sampleCount = 55; break;
case 4: sampleCount = 89; break;
case 5: sampleCount = 89; break;
case 6: sampleCount = 89; break; // UNITY_SPECCUBE_LOD_STEPS
}
float4 val = IntegrateLD(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
V, N,
roughness,
_MaxLevel,
_InvOmegaP,
sampleCount, // Must be a Fibonacci number
true);
#endif
return val;
}

22
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using System.Collections.Generic;
using System;
namespace UnityEngine.Experimental.ScriptableRenderLoop

// TODO: Anything above 1024 cause a crash in Unity...
//SkyResolution2048 = 2048,
//SkyResolution4096 = 4096
}
[GenerateHLSL(PackingRules.Exact)]
public enum LightSamplingParameters
{
TextureHeight = 256,
TextureWidth = 512
}
public enum EnvironementUpdateMode

bool m_UpdateRequired = true;
float m_CurrentUpdateTime = 0.0f;
// Configuration parameters for Multiple Importance Sampling.
const bool m_useMIS = false;
const int m_TextureHeightMIS = 256;
const int m_TextureWidthMIS = m_TextureHeightMIS * 2;
const bool m_useMIS = false;
SkyParameters m_SkyParameters = null;

if (m_useMIS)
{
int width = (int)LightSamplingParameters.TextureWidth;
int height = (int)LightSamplingParameters.TextureHeight;
m_SkyboxMarginalRowCdfRT = new RenderTexture(m_TextureHeightMIS + 1, 1, 1, RenderTextureFormat.RFloat);
m_SkyboxMarginalRowCdfRT = new RenderTexture(height + 1, 1, 1, RenderTextureFormat.RFloat);
m_SkyboxMarginalRowCdfRT.dimension = TextureDimension.Tex2D;
m_SkyboxMarginalRowCdfRT.useMipMap = false;
m_SkyboxMarginalRowCdfRT.autoGenerateMips = false;

// TODO: switch the format to R16 (once it's available) to save some bandwidth.
m_SkyboxConditionalCdfRT = new RenderTexture(m_TextureWidthMIS, m_TextureHeightMIS, 1, RenderTextureFormat.RFloat);
m_SkyboxConditionalCdfRT = new RenderTexture(width, height, 1, RenderTextureFormat.RFloat);
m_SkyboxConditionalCdfRT.dimension = TextureDimension.Tex2D;
m_SkyboxConditionalCdfRT.useMipMap = false;
m_SkyboxConditionalCdfRT.autoGenerateMips = false;

m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", m_SkyboxMarginalRowCdfRT);
var cmd = new CommandBuffer() { name = "" };
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, m_TextureHeightMIS, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, (int)LightSamplingParameters.TextureHeight, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();

14
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs. Please don't edit by hand.
//
#ifndef SKYMANAGER_CS_HLSL
#define SKYMANAGER_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.LightSamplingParameters: static fields
//
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT (256)
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH (512)
#endif
正在加载...
取消
保存