浏览代码

Added the possibility to override lighting with a user specified cubemap (this will be provided to both enlighten and the default reflection probe)

/fptl_cleanup
Julien Ignace 8 年前
当前提交
27b86771
共有 7 个文件被更改,包括 105 次插入2 次删除
  1. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
  2. 29
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  3. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs
  4. 9
      Assets/ScriptableRenderPipeline/common/Resources.meta
  5. 55
      Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader
  6. 9
      Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader.meta

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs


public readonly GUIContent skyMultiplier = new GUIContent("Multiplier", "Intensity multiplier for the sky.");
public readonly GUIContent environmentUpdateMode = new GUIContent("Environment Update Mode", "Specify how the environment lighting should be updated.");
public readonly GUIContent environmentUpdatePeriod = new GUIContent("Environment Update Period", "If environment update is set to realtime, period in seconds at which it is updated (0.0 means every frame).");
public readonly GUIContent lightingOverride = new GUIContent("Lighting Override", "If a lighting override cubemap is provided, this cubemap will be used to compute lighting instead of the result from the visible sky.");
}
private static Styles s_Styles = null;

private SerializedProperty m_SkyRotation;
private SerializedProperty m_EnvUpdateMode;
private SerializedProperty m_EnvUpdatePeriod;
private SerializedProperty m_LightingOverride;
void OnEnable()
{

m_SkyRotation = serializedObject.FindProperty("rotation");
m_EnvUpdateMode = serializedObject.FindProperty("updateMode");
m_EnvUpdatePeriod = serializedObject.FindProperty("updatePeriod");
m_LightingOverride = serializedObject.FindProperty("lightingOverride");
}
public override void OnInspectorGUI()

{
EditorGUILayout.PropertyField(m_EnvUpdatePeriod, styles.environmentUpdatePeriod);
}
EditorGUILayout.PropertyField(m_LightingOverride, styles.lightingOverride);
serializedObject.ApplyModifiedProperties();
}

29
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


RenderTexture m_SkyboxConditionalCdfRT = null;
Material m_StandardSkyboxMaterial = null; // This is the Unity standard skybox material. Used to pass the correct cubemap to Enlighten.
Material m_BlitCubemapMaterial = null;
IBLFilterGGX m_iblFilterGgx = null;

m_iblFilterGgx = new IBLFilterGGX();
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_BlitCubemapMaterial = Utilities.CreateEngineMaterial("Hidden/BlitCubemap");
m_CurrentUpdateTime = 0.0f;
}

Utilities.SetRenderTarget(builtinParams.renderContext, target, ClearFlag.ClearNone, 0, (CubemapFace)i);
m_Renderer.RenderSky(builtinParams, skySettings, true);
}
}
private void BlitCubemap(ScriptableRenderContext renderContext, Cubemap source, RenderTexture dest)
{
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
for (int i = 0; i < 6; ++i)
{
Utilities.SetRenderTarget(renderContext, dest, ClearFlag.ClearNone, 0, (CubemapFace)i);
var cmd = new CommandBuffer { name = "" };
propertyBlock.SetTexture("_MainTex", source);
propertyBlock.SetFloat("_faceIndex", (float)i);
cmd.DrawProcedural(Matrix4x4.identity, m_BlitCubemapMaterial, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkySettings skyParams, Texture input, RenderTexture target)

)
{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
if(m_SkySettings.lightingOverride == null)
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
// In case the user overrides the lighting, we already have a cubemap ready but we need to blit it anyway for potential resize and so that we can generate proper mipmaps for enlighten.
else
BlitCubemap(renderContext, m_SkySettings.lightingOverride, m_SkyboxCubemapRT);
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skySettings, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


public SkyResolution resolution = SkyResolution.SkyResolution256;
public EnvironementUpdateMode updateMode = EnvironementUpdateMode.OnChanged;
public float updatePeriod = 0.0f;
public Cubemap lightingOverride = null;
private FieldInfo[] m_Properties;

9
Assets/ScriptableRenderPipeline/common/Resources.meta


fileFormatVersion: 2
guid: 1e02c245110074e4aa88a9b408060d4f
folderAsset: yes
timeCreated: 1491318329
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

55
Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader


Shader "Hidden/BlitCubemap" {
SubShader {
// Cubemap blit. Takes a face index.
Pass {
ZTest Always Cull Off ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.5
#include "../../ShaderLibrary/Common.hlsl"
TEXTURECUBE(_MainTex);
SAMPLERCUBE(sampler_MainTex);
float _faceIndex;
struct appdata_t {
uint vertexID : SV_VertexID;
};
struct v2f {
float4 vertex : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
static const float3 faceU[6] = { float3(0, 0, -1), float3(0, 0, 1), float3(1, 0, 0), float3(1, 0, 0), float3(1, 0, 0), float3(-1, 0, 0) };
static const float3 faceV[6] = { float3(0, -1, 0), float3(0, -1, 0), float3(0, 0, 1), float3(0, 0, -1), float3(0, -1, 0), float3(0, -1, 0) };
v2f vert (appdata_t v)
{
v2f o;
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
float2 uv = GetFullScreenTriangleTexcoord(v.vertexID) * 2.0 - 1.0;
int idx = (int)_faceIndex;
float3 transformU = faceU[idx];
float3 transformV = faceV[idx];
float3 n = cross(transformV, transformU);
o.texcoord = n + uv.x * transformU + uv.y * transformV;
return o;
}
float4 frag (v2f i) : SV_Target
{
return SAMPLE_TEXTURECUBE(_MainTex, sampler_MainTex, i.texcoord);
}
ENDHLSL
}
}
Fallback Off
}

9
Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader.meta


fileFormatVersion: 2
guid: d05913e251bed7a4992c921c62e1b647
timeCreated: 1491318357
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存