浏览代码

Merge pull request #102 from Unity-Technologies/Branch_fix-ps4-hdrenderloop

Branch fix ps4 hdrenderloop
/main
GitHub 8 年前
当前提交
d23fdad9
共有 9 个文件被更改,包括 88 次插入61 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  2. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  3. 113
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
  4. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  5. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
  6. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
  7. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  8. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs
  9. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


Texture2D tex = new Texture2D(width, height, format, false /*mipmap*/, true /*linear*/);
tex.hideFlags = HideFlags.HideAndDontSave;
tex.wrapMode = TextureWrapMode.Clamp;
tex.filterMode = FilterMode.Bilinear;
tex.SetPixels(pixels);
tex.Apply();
return tex;

// TODO: switch to RGBA64 when it becomes available.
m_PreIntegratedFGD = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGBHalf);
m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
m_PreIntegratedFGD.wrapMode = TextureWrapMode.Clamp;
m_PreIntegratedFGD.Create();
m_LtcGGXMatrix = LoadLUT(TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
m_LtcDisneyDiffuseMatrix = LoadLUT(TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


return GetParameters(skyParameters).skyHDRI != null;
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters)
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
{
HDRISkyParameters hdriSkyParams = GetParameters(skyParameters);

var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial);
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial, 0, renderForCubemap ? 0 : 1);
builtinParams.renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

113
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader


Shader "Hidden/HDRenderPipeline/Sky/SkyHDRI"
{
SubShader
HLSLINCLUDE
#pragma vertex Vert
#pragma fragment Frag
#pragma target 5.0
#pragma only_renderers d3d11 ps4// TEMP: unitl we go futher in dev
#include "Color.hlsl"
#include "Common.hlsl"
#include "CommonLighting.hlsl"
TEXTURECUBE(_Cubemap);
SAMPLERCUBE(sampler_Cubemap);
float4 _SkyParam; // x exposure, y multiplier, z rotation
struct Attributes
Pass
{
ZWrite Off
ZTest LEqual
Blend One Zero
float3 positionCS : POSITION;
float3 eyeVector : NORMAL;
};
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 ps4 // TEMP: unitl we go futher in dev
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 eyeVector : TEXCOORD0;
};
#pragma vertex Vert
#pragma fragment Frag
Varyings Vert(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
Varyings output;
output.positionCS = float4(input.positionCS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0);
output.eyeVector = input.eyeVector;
#include "Color.hlsl"
#include "Common.hlsl"
#include "CommonLighting.hlsl"
return output;
}
TEXTURECUBE(_Cubemap);
SAMPLERCUBE(sampler_Cubemap);
float4 Frag(Varyings input) : SV_Target
{
float3 dir = normalize(input.eyeVector);
float4 _SkyParam; // x exposure, y multiplier, z rotation
struct Attributes
{
float3 positionCS : POSITION;
float3 eyeVector : NORMAL;
};
// Rotate direction
float phi = DegToRad(_SkyParam.z);
float cosPhi, sinPhi;
sincos(phi, sinPhi, cosPhi);
float3 rotDirX = float3(cosPhi, 0, -sinPhi);
float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 eyeVector : TEXCOORD0;
};
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
return float4(skyColor, 1.0);
}
Varyings Vert(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
Varyings output;
output.positionCS = float4(input.positionCS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0);
output.eyeVector = input.eyeVector;
ENDHLSL
return output;
}
SubShader
{
Pass
{
ZWrite Off
ZTest Always
Blend One Zero
float4 Frag(Varyings input) : SV_Target
{
float3 dir = normalize(input.eyeVector);
HLSLPROGRAM
ENDHLSL
// Rotate direction
float phi = DegToRad(_SkyParam.z);
float cosPhi, sinPhi;
sincos(phi, sinPhi, cosPhi);
float3 rotDirX = float3(cosPhi, 0, -sinPhi);
float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
}
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
return float4(skyColor, 1.0);
}
Pass
{
ZWrite Off
ZTest LEqual
Blend One Zero
HLSLPROGRAM
ENDHLSL
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters)
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
{
ProceduralSkyParameters proceduralSkyParams = GetParameters(skyParameters);

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader


Pass
{
ZWrite Off
ZTest LEqual
ZTest Always
Blend One OneMinusSrcAlpha, Zero One
HLSLPROGRAM

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader


Pass
{
ZWrite Off
ZTest LEqual
ZTest Always
Blend One Zero
HLSLPROGRAM

float3 V = N;
float perceptualRoughness = MipmapLevelToPerceptualRoughness(_Level);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
uint sampleCount = GetIBLRuntimeFilterSampleCount(_Level);
#ifdef USE_MIS

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


builtinParams.skyMesh = m_CubemapFaceMesh[i];
builtinParams.colorBuffer = target;
builtinParams.depthBuffer = BuiltinSkyParameters.invalidRTI;
m_Renderer.RenderSky(builtinParams, skyParameters);
m_Renderer.RenderSky(builtinParams, skyParameters, true);
}
}

m_BuiltinParameters.depthBuffer = depthBuffer;
Utilities.SetRenderTarget(renderContext, colorBuffer, depthBuffer);
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters);
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters, false);
}
}
}

3
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs


{
abstract public void Build();
abstract public void Cleanup();
abstract public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters);
// renderForCubemap: When rendering into a cube map, no depth buffer is available so user has to make sure not to use depth testing or the depth texture.
abstract public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap);
abstract public bool IsSkyValid(SkyParameters skyParameters);
virtual public bool IsParameterValid(SkyParameters skyParameters) { return false; }

13
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


// Render Target Management.
public const ClearFlag kClearAll = ClearFlag.ClearDepth | ClearFlag.ClearColor;
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
if (clearFlag != ClearFlag.ClearNone)
cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
SetRenderTarget(renderContext, buffer, clearFlag, Color.black, miplevel, cubemapFace);
}
SetRenderTarget(renderContext, colorBuffer, depthBuffer, ClearFlag.ClearNone, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
SetRenderTarget(renderContext, colorBuffer, depthBuffer, ClearFlag.ClearNone, Color.black, miplevel, cubemapFace);
SetRenderTarget(renderContext, colorBuffer, depthBuffer, clearFlag, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
SetRenderTarget(renderContext, colorBuffer, depthBuffer, clearFlag, Color.black, miplevel, cubemapFace);
}
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)

正在加载...
取消
保存