GitHub
6 年前
当前提交
6a81a760
共有 17 个文件被更改,包括 287 次插入 和 5 次删除
-
1com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs
-
10com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
-
1com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
-
1com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
-
3com.unity.render-pipelines.high-definition/HDRP/Sky/VisualEnvironment.cs
-
8com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky.meta
-
8com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky.meta
-
42com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/GradientSky/GradientSkyEditor.cs.meta
-
11com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs.meta
-
81com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader
-
9com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.shader.meta
-
63com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSkyRenderer.cs.meta
-
32com.unity.render-pipelines.high-definition/HDRP/Sky/GradientSky/GradientSky.cs
|
|||
fileFormatVersion: 2 |
|||
guid: d02d7d4257904854f91435453078fd44 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4eaf64d2d64c8fb45b1e85eefff62dd7 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8d9ef3fb3b5232a4abaebf916d7a1108 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a81bcacc415a1f743bfdf703afc52027 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2b5d4f1b26f03dc4a873b093e0c4adb1 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 932fb63537938154fbe7249e1bbeb2e3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[SkyUniqueID((int)SkyType.Gradient)] |
|||
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; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue