浏览代码

Merge remote-tracking branch 'origin/master' into Create-MaterialUtilities

/main
Paul Demeulenaere 8 年前
当前提交
862a569a
共有 8 个文件被更改,包括 46 次插入38 次删除
  1. 1
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  2. 1
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ShaderBase.hlsl
  4. 44
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs
  5. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
  6. 9
      Assets/ScriptableRenderLoop/common/ShaderBase.h
  7. 2
      Assets/ScriptableRenderLoop/common/TextureSettings.cs
  8. 6
      Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl

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


if (EditorGUI.EndChangeCheck())
{
renderLoop.textureSettings = textureParameters;
EditorUtility.SetDirty(renderLoop); // Repaint
}
EditorGUI.indentLevel--;

1
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public TextureSettings textureSettings
{
get { return m_TextureSettings; }
set { m_TextureSettings = value; }
}
// Various set of material use in render loop

9
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ShaderBase.hlsl


#ifndef __SHADERBASE_H__
#define __SHADERBASE_H__
// can't use UNITY_REVERSED_Z since it's not enabled in compute shaders
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#define REVERSE_ZBUF
#endif
#ifdef SHADER_API_PSSL
#ifndef Texture2DMS

float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
{
float zdpth = LOAD_TEXTURE2D(depthTexture, pixCoord.xy).x;
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#ifdef REVERSE_ZBUF
zdpth = 1.0 - zdpth;
#endif
return zdpth;

{
float zdpth = LOAD_TEXTURE2D_MSAA(depthTexture, pixCoord.xy, sampleIdx).x;
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#ifdef REVERSE_ZBUF
zdpth = 1.0 - zdpth;
#endif
return zdpth;

44
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs


MaterialPropertyBlock m_RenderSkyPropertyBlock = null;
GameObject[] m_CubemapFaceCamera = new GameObject[6];
Matrix4x4[] m_faceCameraInvViewProjectionMatrix = new Matrix4x4[6];
Mesh BuildSkyMesh(Camera camera, bool forceUVBottom)
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);

// Get view vector based on the frustum, i.e (invert transform frustum get position etc...)
Vector3[] eyeVectorData = new Vector3[4];
Matrix4x4 transformMatrix = camera.cameraToWorldMatrix * camera.projectionMatrix.inverse;
Matrix4x4 transformMatrix = cameraInvViewProjectionMatrix;
Vector4 posWorldSpace0 = transformMatrix * vertData0;
Vector4 posWorldSpace1 = transformMatrix * vertData1;

Vector3 temp = camera.GetComponent<Transform>().position;
Vector4 cameraPosition = new Vector4(temp.x, temp.y, temp.z, 0.0f);
Vector4 cameraPos = new Vector4(cameraPosition.x, cameraPosition.y, cameraPosition.z, 0.0f);
Vector4 direction0 = (posWorldSpace0 / posWorldSpace0.w - cameraPosition);
Vector4 direction1 = (posWorldSpace1 / posWorldSpace1.w - cameraPosition);
Vector4 direction2 = (posWorldSpace2 / posWorldSpace2.w - cameraPosition);
Vector4 direction3 = (posWorldSpace3 / posWorldSpace3.w - cameraPosition);
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)
{

for (int i = 0; i < 6; ++i)
{
m_CubemapFaceCamera[i] = new GameObject();
m_CubemapFaceCamera[i].hideFlags = HideFlags.HideAndDontSave;
Camera camera = m_CubemapFaceCamera[i].AddComponent<Camera>();
camera.projectionMatrix = cubeProj;
Transform transform = camera.GetComponent<Transform>();
transform.LookAt(lookAtList[i], UpVectorList[i]);
Matrix4x4 lookAt = Matrix4x4.LookAt(Vector3.zero, lookAtList[i], UpVectorList[i]);
m_faceCameraInvViewProjectionMatrix[i] = Utilities.GetViewProjectionMatrix(lookAt, cubeProj).inverse;
m_CubemapFaceMesh[i] = BuildSkyMesh(camera, true);
m_CubemapFaceMesh[i] = BuildSkyMesh(Vector3.zero, m_faceCameraInvViewProjectionMatrix[i], true);
}
}

Utilities.Destroy(m_GGXConvolveMaterial);
Utilities.Destroy(m_SkyboxCubemapRT);
Utilities.Destroy(m_SkyboxGGXCubemapRT);
for(int i = 0 ; i < 6 ; ++i)
{
Utilities.Destroy(m_CubemapFaceCamera[i]);
}
}
public bool IsSkyValid(SkyParameters parameters)

}
private void RenderSky(Camera camera, SkyParameters skyParameters, Mesh skyMesh, RenderLoop renderLoop)
private void RenderSky(Matrix4x4 invViewProjectionMatrix, SkyParameters skyParameters, Mesh skyMesh, RenderLoop renderLoop)
m_RenderSkyPropertyBlock.SetMatrix("_InvViewProjMatrix", Utilities.GetViewProjectionMatrix(camera).inverse);
m_RenderSkyPropertyBlock.SetMatrix("_InvViewProjMatrix", invViewProjectionMatrix);
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial, 0, 0, m_RenderSkyPropertyBlock);

for (int i = 0; i < 6; ++i)
{
Utilities.SetRenderTarget(renderLoop, target, 0, (CubemapFace)i);
Camera faceCamera = m_CubemapFaceCamera[i].GetComponent<Camera>();
RenderSky(faceCamera, skyParameters, m_CubemapFaceMesh[i], renderLoop);
RenderSky(m_faceCameraInvViewProjectionMatrix[i], skyParameters, m_CubemapFaceMesh[i], renderLoop);
}
}

// Render the sky itself
Utilities.SetRenderTarget(renderLoop, colorBuffer, depthBuffer);
RenderSky(camera, skyParameters, BuildSkyMesh(camera, false), renderLoop);
Matrix4x4 invViewProjectionMatrix = Utilities.GetViewProjectionMatrix(camera).inverse;
RenderSky(invViewProjectionMatrix, skyParameters, BuildSkyMesh(camera.GetComponent<Transform>().position, invViewProjectionMatrix, false), renderLoop);
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs


disposed = true;
}
}
public static Matrix4x4 GetViewProjectionMatrix(Camera camera)
public static Matrix4x4 GetViewProjectionMatrix(Matrix4x4 worldToViewMatrix, Matrix4x4 projectionMatrix)
var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
var gpuVP = gpuProj * camera.worldToCameraMatrix;
var gpuProj = GL.GetGPUProjectionMatrix(projectionMatrix, false);
var gpuVP = gpuProj * worldToViewMatrix;
}
public static Matrix4x4 GetViewProjectionMatrix(Camera camera)
{
return GetViewProjectionMatrix(camera.worldToCameraMatrix, camera.projectionMatrix);
}
public static Vector4 ComputeScreenSize(Camera camera)

9
Assets/ScriptableRenderLoop/common/ShaderBase.h


#ifndef __SHADERBASE_H__
#define __SHADERBASE_H__
// can't use UNITY_REVERSED_Z since it's not enabled in compute shaders
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#define REVERSE_ZBUF
#endif
#ifdef SHADER_API_PSSL
#ifndef Texture2DMS

float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
{
float zdpth = depthTexture.Load(uint3(pixCoord.xy, 0)).x;
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#ifdef REVERSE_ZBUF
zdpth = 1.0 - zdpth;
#endif
return zdpth;

{
float zdpth = depthTexture.Load(uint3(pixCoord.xy, 0), sampleIdx).x;
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
#ifdef REVERSE_ZBUF
zdpth = 1.0 - zdpth;
#endif
return zdpth;

2
Assets/ScriptableRenderLoop/common/TextureSettings.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[System.Serializable]
public class TextureSettings
public struct TextureSettings
{
public int spotCookieSize;
public int pointCookieSize;

6
Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl


#define DECLARE_SHADOWMAP( tex ) Texture2D tex; SamplerComparisonState sampler##tex
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, (coord).z )
#ifdef REVERSE_ZBUF
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, (coord).z )
#else
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, 1.0-(coord).z )
#endif
DECLARE_SHADOWMAP(g_tShadowBuffer);

正在加载...
取消
保存