浏览代码

Add Gradient Sky from Laurent

/main
Antoine Lelievre 6 年前
当前提交
0f1f60cb
共有 16 个文件被更改,包括 285 次插入4 次删除
  1. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs
  2. 10
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
  3. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  4. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  5. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky.meta
  6. 8
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky.meta
  7. 42
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs
  8. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs.meta
  9. 32
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs
  10. 11
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs.meta
  11. 81
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader
  12. 9
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader.meta
  13. 63
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs
  14. 11
      com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs.meta

1
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs


newAsset.opaqueAtmosphericScattering = Load<Shader>(HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader");
newAsset.hdriSky = Load<Shader>(HDRenderPipelinePath + "Sky/HDRISky/HDRISky.shader");
newAsset.proceduralSky = Load<Shader>(HDRenderPipelinePath + "Sky/ProceduralSky/ProceduralSky.shader");
newAsset.gradientSky = Load<Shader>(HDRenderPipelinePath + "Sky/GradientSky/GradientSky.shader");
// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap");

10
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset


m_FrameSettings:
enableShadow: 1
enableContactShadows: 1
enableShadowMask: 1
enableSSR: 1
enableSSAO: 1
enableSubsurfaceScattering: 1

enableLightLayers: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0

enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 1
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

supportSSR: 1
supportSSAO: 1
supportSubsurfaceScattering: 1
supportOnlyForward: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
supportLightLayers: 0
supportOnlyForward: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
lightLoopSettings:
cookieSize: 128
cookieTexArraySize: 16

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


hdriSky: {fileID: 4800000, guid: 9bd32a6ece529fd4f9408b8d7e00c10d, type: 3}
proceduralSky: {fileID: 4800000, guid: ec63f47fd265df243a7b1d40f9ef7fe7, type: 3}
skyboxCubemap: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
gradientSky: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3}
preIntegratedFGD_GGXDisneyDiffuse: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, type: 3}
preIntegratedFGD_CharlieClothLambert: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, type: 3}
encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3}

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader hdriSky;
public Shader proceduralSky;
public Shader skyboxCubemap;
public Shader gradientSky;
// Material
public Shader preIntegratedFGD_GGXDisneyDiffuse;

8
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky.meta


fileFormatVersion: 2
guid: d02d7d4257904854f91435453078fd44
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky.meta


fileFormatVersion: 2
guid: 4eaf64d2d64c8fb45b1e85eefff62dd7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

42
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[VolumeComponentEditor(typeof(GradientSky))]
public class GradientSkySettingsEditor : SkySettingsEditor
{
SerializedDataParameter m_Bottom;
SerializedDataParameter m_Middle;
SerializedDataParameter m_Top;
SerializedDataParameter m_GradientMultiplier;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<GradientSky>(serializedObject);
m_Bottom = Unpack(o.Find(x => x.bottom));
m_Middle = Unpack(o.Find(x => x.middle));
m_Top = Unpack(o.Find(x => x.top));
m_GradientMultiplier = Unpack(o.Find(x => x.gradientDiffusion));
}
public override void OnInspectorGUI()
{
PropertyField(m_Top);
PropertyField(m_Middle);
PropertyField(m_Bottom);
PropertyField(m_GradientMultiplier);
EditorGUILayout.Space();
m_CommonUIElementsMask = (uint)SkySettingsUIElement.UpdateMode;
base.CommonSkySettingsGUI();
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs.meta


fileFormatVersion: 2
guid: 8d9ef3fb3b5232a4abaebf916d7a1108
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

32
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[SkyUniqueID(150)]
public class GradientSky : SkySettings
{
public ColorParameter top = new ColorParameter(Color.blue, true, false, true);
public ColorParameter middle = new ColorParameter(new Color(0.3f, 0.7f, 1f), true, false, true);
public ColorParameter bottom = new ColorParameter(Color.white, true, false, true);
public FloatParameter gradientDiffusion = new FloatParameter(1);
public override SkyRenderer CreateRenderer()
{
return new GradientSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = 13;
hash = hash * 23 + bottom.GetHashCode();
hash = hash * 23 + top.GetHashCode();
hash = hash * 23 + middle.GetHashCode();
hash = hash * 23 + gradientDiffusion.GetHashCode();
}
return hash;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs.meta


fileFormatVersion: 2
guid: a81bcacc415a1f743bfdf703afc52027
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

81
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader


Shader "Hidden/HDRenderPipeline/Sky/GradientSky"
{
HLSLINCLUDE
#pragma vertex Vert
#pragma fragment Frag
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "CoreRP/ShaderLibrary/CommonLighting.hlsl"
#include "HDRP/ShaderVariables.hlsl"
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _GradientBottom;
float4 _GradientMiddle;
float4 _GradientTop;
float _GradientDiffusion;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID, UNITY_RAW_FAR_CLIP_VALUE);
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float3 viewDirWS = normalize(mul(float3(input.positionCS.xy, 1.0), (float3x3)_PixelCoordToViewDirWS));
float verticalGradient = viewDirWS.y * _GradientDiffusion;
float topLerpFactor = saturate(-verticalGradient);
float bottomLerpFactor = saturate(verticalGradient);
float3 color = lerp(_GradientMiddle,_GradientBottom,bottomLerpFactor);
color = lerp(color.xyz,_GradientTop,topLerpFactor);
return float4 (color.xyz,1);
}
ENDHLSL
SubShader
{
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
Pass
{
ZWrite Off
ZTest LEqual
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
}
Fallback Off
}

9
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader.meta


fileFormatVersion: 2
guid: 2b5d4f1b26f03dc4a873b093e0c4adb1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

63
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class GradientSkyRenderer : SkyRenderer
{
Material m_GradientSkyMaterial; // Renders a cubemap into a render texture (can be cube or 2D)
MaterialPropertyBlock m_PropertyBlock;
GradientSky m_GradientSkyParams;
readonly int _GradientBottom = Shader.PropertyToID("_GradientBottom");
readonly int _GradientMiddle = Shader.PropertyToID("_GradientMiddle");
readonly int _GradientTop = Shader.PropertyToID("_GradientTop");
readonly int _GradientDiffusion = Shader.PropertyToID("_GradientDiffusion");
public GradientSkyRenderer(GradientSky GradientSkyParams)
{
m_GradientSkyParams = GradientSkyParams;
m_PropertyBlock = new MaterialPropertyBlock();
}
public override void Build()
{
var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
m_GradientSkyMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.gradientSky);
}
public override void Cleanup()
{
CoreUtils.Destroy(m_GradientSkyMaterial);
}
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)
{
if (builtinParams.depthBuffer == BuiltinSkyParameters.nullRT)
{
HDUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.hdCamera, builtinParams.colorBuffer);
}
else
{
HDUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.hdCamera, builtinParams.colorBuffer, builtinParams.depthBuffer);
}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
{
m_GradientSkyMaterial.SetColor(_GradientBottom, m_GradientSkyParams.bottom);
m_GradientSkyMaterial.SetColor(_GradientMiddle, m_GradientSkyParams.middle);
m_GradientSkyMaterial.SetColor(_GradientTop, m_GradientSkyParams.top);
m_GradientSkyMaterial.SetFloat(_GradientDiffusion, m_GradientSkyParams.gradientDiffusion);
// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_GradientSkyMaterial, m_PropertyBlock, renderForCubemap ? 0 : 1);
}
public override bool IsValid()
{
return m_GradientSkyParams != null && m_GradientSkyMaterial != null;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs.meta


fileFormatVersion: 2
guid: 932fb63537938154fbe7249e1bbeb2e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存