浏览代码
Started refactoring for sky framework.
Started refactoring for sky framework.
- New SkyManager as central class - Base class for user defined sky renderers and parameters - Implemented HDRI sky with this abstraction./main
Julien Ignace
8 年前
当前提交
4f8f27fc
共有 25 个文件被更改,包括 709 次插入 和 362 次删除
-
30Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
-
23Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
313Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs.meta
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
-
68Assets/TestScenes/HDTest/GlobalIlluminationTest.unity
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources/SkyHDRI.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky.meta
-
330Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs.meta
-
72Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Editor.meta
-
61Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Editor/HDRISkyEditor.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Editor/HDRISkyEditor.cs.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyParameters.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyParameters.cs.meta
-
67Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyRenderer.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyRenderer.cs.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources.meta
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources/SkyHDRI.shader.meta
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources/SkyHDRI.shader
|
|||
fileFormatVersion: 2 |
|||
guid: 3dc75ec23ead9c94fa152d2c7c33aee4 |
|||
folderAsset: yes |
|||
timeCreated: 1481626018 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using System.Collections.Generic; |
|||
using System; |
|||
|
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
[Serializable] |
|||
public enum SkyResolution |
|||
{ |
|||
SkyResolution128 = 128, |
|||
SkyResolution256 = 256, |
|||
SkyResolution512 = 512, |
|||
SkyResolution1024 = 1024, |
|||
// TODO: Anything above 1024 cause a crash in Unity...
|
|||
//SkyResolution2048 = 2048,
|
|||
//SkyResolution4096 = 4096
|
|||
} |
|||
|
|||
public class BuiltinSkyParameters |
|||
{ |
|||
public Matrix4x4 invViewProjMatrix; |
|||
public Mesh skyMesh; |
|||
public RenderLoop renderLoop; |
|||
} |
|||
|
|||
public class SkyManager |
|||
{ |
|||
RenderTexture m_SkyboxCubemapRT = null; |
|||
RenderTexture m_SkyboxGGXCubemapRT = null; |
|||
|
|||
Material m_StandardSkyboxMaterial = null; // This is the Unity standard skybox material. Used to pass the correct cubemap to Enlighten.
|
|||
Material m_GGXConvolveMaterial = null; // Apply GGX convolution to cubemap
|
|||
|
|||
Matrix4x4[] m_faceCameraInvViewProjectionMatrix = new Matrix4x4[6]; |
|||
Mesh[] m_CubemapFaceMesh = new Mesh[6]; |
|||
|
|||
BuiltinSkyParameters m_BuiltinParameters = new BuiltinSkyParameters(); |
|||
SkyRenderer m_Renderer = new HDRISkyRenderer(); |
|||
int m_SkyParametersHash = 0; |
|||
|
|||
protected Mesh BuildSkyMesh(Vector3 cameraPosition, Matrix4x4 cameraInvViewProjectionMatrix, bool forceUVBottom) |
|||
{ |
|||
Vector4 vertData0 = new Vector4(-1.0f, -1.0f, 1.0f, 1.0f); |
|||
Vector4 vertData1 = new Vector4(1.0f, -1.0f, 1.0f, 1.0f); |
|||
Vector4 vertData2 = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); |
|||
Vector4 vertData3 = new Vector4(-1.0f, 1.0f, 1.0f, 1.0f); |
|||
|
|||
Vector3[] vertData = new Vector3[4]; |
|||
vertData[0] = new Vector3(vertData0.x, vertData0.y, vertData0.z); |
|||
vertData[1] = new Vector3(vertData1.x, vertData1.y, vertData1.z); |
|||
vertData[2] = new Vector3(vertData2.x, vertData2.y, vertData2.z); |
|||
vertData[3] = new Vector3(vertData3.x, vertData3.y, vertData3.z); |
|||
|
|||
// Get view vector based on the frustum, i.e (invert transform frustum get position etc...)
|
|||
Vector3[] eyeVectorData = new Vector3[4]; |
|||
|
|||
Matrix4x4 transformMatrix = cameraInvViewProjectionMatrix; |
|||
|
|||
Vector4 posWorldSpace0 = transformMatrix * vertData0; |
|||
Vector4 posWorldSpace1 = transformMatrix * vertData1; |
|||
Vector4 posWorldSpace2 = transformMatrix * vertData2; |
|||
Vector4 posWorldSpace3 = transformMatrix * vertData3; |
|||
|
|||
Vector4 cameraPos = new Vector4(cameraPosition.x, cameraPosition.y, cameraPosition.z, 0.0f); |
|||
|
|||
Vector4 direction0 = (posWorldSpace0 / posWorldSpace0.w - cameraPos); |
|||
Vector4 direction1 = (posWorldSpace1 / posWorldSpace1.w - cameraPos); |
|||
Vector4 direction2 = (posWorldSpace2 / posWorldSpace2.w - cameraPos); |
|||
Vector4 direction3 = (posWorldSpace3 / posWorldSpace3.w - cameraPos); |
|||
|
|||
if (SystemInfo.graphicsUVStartsAtTop && !forceUVBottom) |
|||
{ |
|||
eyeVectorData[3] = new Vector3(direction0.x, direction0.y, direction0.z).normalized; |
|||
eyeVectorData[2] = new Vector3(direction1.x, direction1.y, direction1.z).normalized; |
|||
eyeVectorData[1] = new Vector3(direction2.x, direction2.y, direction2.z).normalized; |
|||
eyeVectorData[0] = new Vector3(direction3.x, direction3.y, direction3.z).normalized; |
|||
} |
|||
else |
|||
{ |
|||
eyeVectorData[0] = new Vector3(direction0.x, direction0.y, direction0.z).normalized; |
|||
eyeVectorData[1] = new Vector3(direction1.x, direction1.y, direction1.z).normalized; |
|||
eyeVectorData[2] = new Vector3(direction2.x, direction2.y, direction2.z).normalized; |
|||
eyeVectorData[3] = new Vector3(direction3.x, direction3.y, direction3.z).normalized; |
|||
} |
|||
|
|||
// Write out the mesh
|
|||
var triangles = new int[6] { 0, 1, 2, 2, 3, 0 }; |
|||
|
|||
return new Mesh |
|||
{ |
|||
vertices = vertData, |
|||
normals = eyeVectorData, |
|||
triangles = triangles |
|||
}; |
|||
} |
|||
|
|||
void RebuildTextures(SkyParameters skyParameters) |
|||
{ |
|||
int resolution = 256; |
|||
// Parameters not set yet. We need them for the resolution.
|
|||
if (skyParameters != null) |
|||
resolution = (int)skyParameters.resolution; |
|||
|
|||
if ((m_SkyboxCubemapRT != null) && (m_SkyboxCubemapRT.width != resolution)) |
|||
{ |
|||
Utilities.Destroy(m_SkyboxCubemapRT); |
|||
Utilities.Destroy(m_SkyboxGGXCubemapRT); |
|||
} |
|||
|
|||
if (m_SkyboxCubemapRT == null) |
|||
{ |
|||
m_SkyboxCubemapRT = new RenderTexture(resolution, resolution, 1, RenderTextureFormat.ARGBHalf); |
|||
m_SkyboxCubemapRT.dimension = TextureDimension.Cube; |
|||
m_SkyboxCubemapRT.useMipMap = true; |
|||
m_SkyboxCubemapRT.autoGenerateMips = true; // Generate regular mipmap for filtered importance sampling
|
|||
m_SkyboxCubemapRT.filterMode = FilterMode.Trilinear; |
|||
m_SkyboxCubemapRT.Create(); |
|||
|
|||
m_SkyboxGGXCubemapRT = new RenderTexture(resolution, resolution, 1, RenderTextureFormat.ARGBHalf); |
|||
m_SkyboxGGXCubemapRT.dimension = TextureDimension.Cube; |
|||
m_SkyboxGGXCubemapRT.useMipMap = true; |
|||
m_SkyboxGGXCubemapRT.autoGenerateMips = false; |
|||
m_SkyboxGGXCubemapRT.filterMode = FilterMode.Trilinear; |
|||
m_SkyboxGGXCubemapRT.Create(); |
|||
} |
|||
} |
|||
|
|||
void RebuildSkyMeshes() |
|||
{ |
|||
if(m_CubemapFaceMesh[0] == null) |
|||
{ |
|||
Matrix4x4 cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, 0.1f, 1.0f); |
|||
|
|||
Vector3[] lookAtList = { |
|||
new Vector3(1.0f, 0.0f, 0.0f), |
|||
new Vector3(-1.0f, 0.0f, 0.0f), |
|||
new Vector3(0.0f, 1.0f, 0.0f), |
|||
new Vector3(0.0f, -1.0f, 0.0f), |
|||
new Vector3(0.0f, 0.0f, 1.0f), |
|||
new Vector3(0.0f, 0.0f, -1.0f), |
|||
}; |
|||
|
|||
Vector3[] UpVectorList = { |
|||
new Vector3(0.0f, 1.0f, 0.0f), |
|||
new Vector3(0.0f, 1.0f, 0.0f), |
|||
new Vector3(0.0f, 0.0f, -1.0f), |
|||
new Vector3(0.0f, 0.0f, 1.0f), |
|||
new Vector3(0.0f, 1.0f, 0.0f), |
|||
new Vector3(0.0f, 1.0f, 0.0f), |
|||
}; |
|||
|
|||
for (int i = 0; i < 6; ++i) |
|||
{ |
|||
Matrix4x4 lookAt = Matrix4x4.LookAt(Vector3.zero, lookAtList[i], UpVectorList[i]); |
|||
m_faceCameraInvViewProjectionMatrix[i] = Utilities.GetViewProjectionMatrix(lookAt, cubeProj).inverse; |
|||
|
|||
// When rendering into a texture the render will be flip (due to legacy unity openGL behavior), so we need to flip UV here...
|
|||
m_CubemapFaceMesh[i] = BuildSkyMesh(Vector3.zero, m_faceCameraInvViewProjectionMatrix[i], true); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Sets the global MIP-mapped cubemap '_SkyTexture' in the shader.
|
|||
// The texture being set is the sky (environment) map pre-convolved with GGX.
|
|||
public void SetGlobalSkyTexture() |
|||
{ |
|||
Shader.SetGlobalTexture("_SkyTexture", m_SkyboxGGXCubemapRT); |
|||
} |
|||
|
|||
public void Resize(SkyParameters skyParameters) |
|||
{ |
|||
// When loading RenderDoc, RenderTextures will go null
|
|||
RebuildTextures(skyParameters); |
|||
RebuildSkyMeshes(); |
|||
} |
|||
|
|||
public void Build() |
|||
{ |
|||
m_Renderer.Build(); |
|||
|
|||
// 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_GGXConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/GGXConvolve"); |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
Utilities.Destroy(m_StandardSkyboxMaterial); |
|||
Utilities.Destroy(m_GGXConvolveMaterial); |
|||
Utilities.Destroy(m_SkyboxCubemapRT); |
|||
Utilities.Destroy(m_SkyboxGGXCubemapRT); |
|||
|
|||
m_Renderer.Cleanup(); |
|||
} |
|||
|
|||
public bool IsSkyValid(SkyParameters parameters) |
|||
{ |
|||
return m_Renderer != null && m_Renderer.IsSkyValid(parameters); |
|||
} |
|||
|
|||
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, RenderTexture target) |
|||
{ |
|||
for (int i = 0; i < 6; ++i) |
|||
{ |
|||
Utilities.SetRenderTarget(builtinParams.renderLoop, target, ClearFlag.ClearNone, 0, (CubemapFace)i); |
|||
|
|||
builtinParams.invViewProjMatrix = m_faceCameraInvViewProjectionMatrix[i]; |
|||
builtinParams.skyMesh = m_CubemapFaceMesh[i]; |
|||
m_Renderer.RenderSky(builtinParams, skyParameters); |
|||
} |
|||
} |
|||
|
|||
private void RenderCubemapGGXConvolution(RenderLoop renderLoop, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target) |
|||
{ |
|||
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderLoop)) |
|||
{ |
|||
int mipCount = 1 + (int)Mathf.Log(input.width, 2.0f); |
|||
if (mipCount < ((int)EnvConstants.SpecCubeLodStep + 1)) |
|||
{ |
|||
Debug.LogWarning("RenderCubemapGGXConvolution: Cubemap size is too small for GGX convolution, needs at least " + ((int)EnvConstants.SpecCubeLodStep + 1) + " mip levels"); |
|||
return; |
|||
} |
|||
|
|||
// Copy the first mip.
|
|||
|
|||
// WARNING:
|
|||
// Since we can't instanciate the parameters anymore (we don't know the final type here)
|
|||
// we can't make sure that exposure/multiplier etc are at neutral values
|
|||
// This will be solved with proper CopyTexture
|
|||
|
|||
// TEMP code until CopyTexture is implemented for command buffer
|
|||
// All parameters are neutral because exposure/multiplier have already been applied in the first copy.
|
|||
//SkyParameters skyParams = new SkyParameters();
|
|||
//skyParams.exposure = 0.0f;
|
|||
//skyParams.multiplier = 1.0f;
|
|||
//skyParams.rotation = 0.0f;
|
|||
//skyParams.skyHDRI = input;
|
|||
RenderSkyToCubemap(builtinParams, skyParams, target); |
|||
// End temp
|
|||
|
|||
//for (int f = 0; f < 6; f++)
|
|||
// Graphics.CopyTexture(input, f, 0, target, f, 0);
|
|||
|
|||
// Do the convolution on remaining mipmaps
|
|||
float invOmegaP = (6.0f * input.width * input.width) / (4.0f * Mathf.PI); // Solid angle associated to a pixel of the cubemap;
|
|||
|
|||
m_GGXConvolveMaterial.SetTexture("_MainTex", input); |
|||
m_GGXConvolveMaterial.SetFloat("_MipMapCount", mipCount); |
|||
m_GGXConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); |
|||
|
|||
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) |
|||
{ |
|||
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock(); |
|||
propertyBlock.SetFloat("_Level", mip); |
|||
|
|||
for (int face = 0; face < 6; ++face) |
|||
{ |
|||
Utilities.SetRenderTarget(renderLoop, target, ClearFlag.ClearNone, mip, (CubemapFace)face); |
|||
|
|||
var cmd = new CommandBuffer { name = "" }; |
|||
cmd.DrawMesh(m_CubemapFaceMesh[face], Matrix4x4.identity, m_GGXConvolveMaterial, 0, 0, propertyBlock); |
|||
renderLoop.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public void RenderSky(Camera camera, SkyParameters skyParameters, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, RenderLoop renderLoop) |
|||
{ |
|||
using (new Utilities.ProfilingSample("Sky Pass", renderLoop)) |
|||
{ |
|||
if (IsSkyValid(skyParameters)) |
|||
{ |
|||
m_BuiltinParameters.renderLoop = renderLoop; |
|||
|
|||
if (skyParameters.GetHash() != m_SkyParametersHash) |
|||
{ |
|||
using (new Utilities.ProfilingSample("Sky Pass: Render Cubemap", renderLoop)) |
|||
{ |
|||
// Render sky into a cubemap - doesn't happen every frame, can be controlled
|
|||
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT); |
|||
// Convolve downsampled cubemap
|
|||
RenderCubemapGGXConvolution(renderLoop, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT); |
|||
|
|||
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
|
|||
m_StandardSkyboxMaterial.SetTexture("_Tex", m_SkyboxCubemapRT); |
|||
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
|
|||
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
|
|||
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
|
|||
RenderSettings.reflectionIntensity = 1.0f; |
|||
RenderSettings.customReflection = null; |
|||
DynamicGI.UpdateEnvironment(); |
|||
} |
|||
|
|||
m_SkyParametersHash = skyParameters.GetHash(); |
|||
} |
|||
|
|||
// Render the sky itself
|
|||
Utilities.SetRenderTarget(renderLoop, colorBuffer, depthBuffer); |
|||
m_BuiltinParameters.invViewProjMatrix = Utilities.GetViewProjectionMatrix(camera).inverse; |
|||
m_BuiltinParameters.skyMesh = BuildSkyMesh(camera.GetComponent<Transform>().position, m_BuiltinParameters.invViewProjMatrix, false); |
|||
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters); |
|||
} |
|||
else |
|||
{ |
|||
if(m_SkyParametersHash != 0) |
|||
{ |
|||
// Clear sky light probe
|
|||
RenderSettings.skybox = null; |
|||
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
|
|||
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
|
|||
RenderSettings.reflectionIntensity = 1.0f; |
|||
RenderSettings.customReflection = null; |
|||
DynamicGI.UpdateEnvironment(); |
|||
|
|||
// Clear temp cubemap and redo GGX from black
|
|||
Utilities.SetRenderTarget(renderLoop, m_SkyboxCubemapRT, ClearFlag.ClearColor); |
|||
RenderCubemapGGXConvolution(renderLoop, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT); |
|||
|
|||
m_SkyParametersHash = 0; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8bd4c656fd5e14747b942575f2e7e185 |
|||
timeCreated: 1481626426 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.ScriptableRenderLoop; |
|||
using System.Reflection; |
|||
using System.Linq; |
|||
|
|||
|
|||
[ExecuteInEditMode] |
|||
public class SkyParameters : MonoBehaviour |
|||
{ |
|||
public float rotation = 0.0f; |
|||
public float exposure = 0.0f; |
|||
public float multiplier = 1.0f; |
|||
public SkyResolution resolution = SkyResolution.SkyResolution256; |
|||
|
|||
private FieldInfo[] m_Properties; |
|||
|
|||
HDRenderLoop GetHDRenderLoop() |
|||
{ |
|||
HDRenderLoop renderLoop = UnityEngine.Rendering.GraphicsSettings.GetRenderPipeline() as HDRenderLoop; |
|||
if (renderLoop == null) |
|||
{ |
|||
Debug.LogWarning("SkyParameters component can only be used with HDRenderLoop custom RenderPipeline."); |
|||
return null; |
|||
} |
|||
|
|||
return renderLoop; |
|||
} |
|||
|
|||
protected void OnEnable() |
|||
{ |
|||
HDRenderLoop renderLoop = GetHDRenderLoop(); |
|||
if(renderLoop == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
// Enumerate properties in order to compute the hash more quickly later on.
|
|||
m_Properties = GetType() |
|||
.GetFields(BindingFlags.Public | BindingFlags.Instance) |
|||
.ToArray(); |
|||
|
|||
if (renderLoop.skyParameters == null) |
|||
renderLoop.skyParameters = this; |
|||
else if(renderLoop.skyParameters != this) |
|||
Debug.LogWarning("Tried to setup another SkyParameters component although there is already one enabled."); |
|||
} |
|||
|
|||
protected void OnDisable() |
|||
{ |
|||
HDRenderLoop renderLoop = GetHDRenderLoop(); |
|||
if (renderLoop == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (renderLoop.skyParameters == this) |
|||
renderLoop.skyParameters = null; |
|||
} |
|||
|
|||
public int GetHash() |
|||
{ |
|||
unchecked |
|||
{ |
|||
int hash = 13; |
|||
foreach (var p in m_Properties) |
|||
hash = hash * 23 + p.GetValue(this).GetHashCode(); |
|||
return hash; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: be80eb13382d90f4cb2738f69185b60c |
|||
timeCreated: 1481625888 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 132564d35bbdac3458d90dc38649e882 |
|||
folderAsset: yes |
|||
timeCreated: 1481635912 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[CustomEditor(typeof(HDRISkyParameters))] |
|||
public class TestClassEditor |
|||
: Editor |
|||
{ |
|||
private class Styles |
|||
{ |
|||
public readonly GUIContent skyHDRI = new GUIContent("HDRI"); |
|||
public readonly GUIContent skyResolution = new GUIContent("Resolution"); |
|||
public readonly GUIContent skyExposure = new GUIContent("Exposure"); |
|||
public readonly GUIContent skyRotation = new GUIContent("Rotation"); |
|||
public readonly GUIContent skyMultiplier = new GUIContent("Multiplier"); |
|||
} |
|||
|
|||
private static Styles s_Styles = null; |
|||
private static Styles styles |
|||
{ |
|||
get |
|||
{ |
|||
if (s_Styles == null) |
|||
s_Styles = new Styles(); |
|||
return s_Styles; |
|||
} |
|||
} |
|||
|
|||
private SerializedProperty m_SkyHDRI; |
|||
private SerializedProperty m_SkyResolution; |
|||
private SerializedProperty m_SkyExposure; |
|||
private SerializedProperty m_SkyMultiplier; |
|||
private SerializedProperty m_SkyRotation; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
m_SkyHDRI = serializedObject.FindProperty("skyHDRI"); |
|||
m_SkyResolution = serializedObject.FindProperty("resolution"); |
|||
m_SkyExposure = serializedObject.FindProperty("exposure"); |
|||
m_SkyMultiplier = serializedObject.FindProperty("multiplier"); |
|||
m_SkyRotation = serializedObject.FindProperty("rotation"); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI); |
|||
EditorGUILayout.PropertyField(m_SkyResolution, styles.skyResolution); |
|||
EditorGUILayout.PropertyField(m_SkyExposure, styles.skyExposure); |
|||
EditorGUILayout.PropertyField(m_SkyMultiplier, styles.skyMultiplier); |
|||
EditorGUILayout.PropertyField(m_SkyRotation, styles.skyRotation); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 09663e580f1cc7b409d7ddc7923ec152 |
|||
timeCreated: 1481635925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public class HDRISkyParameters |
|||
: SkyParameters |
|||
{ |
|||
public Cubemap skyHDRI; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 59b6606ef2548734bb6d11b9d160bc7e |
|||
timeCreated: 1481631764 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public class HDRISkyRenderer |
|||
: SkyRenderer |
|||
{ |
|||
MaterialPropertyBlock m_PropertyBlock = null; |
|||
Material m_SkyHDRIMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
|
|||
|
|||
override public void Build() |
|||
{ |
|||
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("HDRenderLoop/Sky/SkyHDRI"); |
|||
m_PropertyBlock = new MaterialPropertyBlock(); |
|||
} |
|||
|
|||
override public void Cleanup() |
|||
{ |
|||
Utilities.Destroy(m_SkyHDRIMaterial); |
|||
} |
|||
|
|||
HDRISkyParameters GetHDRISkyParameters(SkyParameters parameters) |
|||
{ |
|||
HDRISkyParameters hdriSkyParams = parameters as HDRISkyParameters; |
|||
if (hdriSkyParams == null) |
|||
{ |
|||
Debug.LogWarning("HDRISkyRenderer needs an instance of HDRISkyParameters to be able to render."); |
|||
return null; |
|||
} |
|||
|
|||
return hdriSkyParams; |
|||
} |
|||
|
|||
override public bool IsSkyValid(SkyParameters skyParameters) |
|||
{ |
|||
HDRISkyParameters hdriSkyParams = GetHDRISkyParameters(skyParameters); |
|||
if (hdriSkyParams == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return hdriSkyParams.skyHDRI != null; |
|||
} |
|||
|
|||
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters) |
|||
{ |
|||
HDRISkyParameters hdriSkyParams = GetHDRISkyParameters(skyParameters); |
|||
if(hdriSkyParams == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
m_PropertyBlock.SetTexture("_Cubemap", hdriSkyParams.skyHDRI); |
|||
m_PropertyBlock.SetVector("_SkyParam", new Vector4(hdriSkyParams.exposure, hdriSkyParams.multiplier, hdriSkyParams.rotation, 0.0f)); |
|||
//m_RenderSkyPropertyBlock.SetMatrix("_InvViewProjMatrix", invViewProjectionMatrix);
|
|||
|
|||
var cmd = new CommandBuffer { name = "" }; |
|||
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial, 0, 0, m_PropertyBlock); |
|||
builtinParams.renderLoop.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 85b456caa9945824bb71f0ab97b1dabe |
|||
timeCreated: 1481631774 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 45faf85c8e652e744a3ce8ead527369d |
|||
folderAsset: yes |
|||
timeCreated: 1481636169 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue