浏览代码

Added skybox feature to render objects at scaled size

/feature-new-clouds
Andre McGrail 4 年前
当前提交
163f5887
共有 11 个文件被更改,包括 2224 次插入590 次删除
  1. 72
      Assets/Data/UniversalRP/BoatDemoRenderer.asset
  2. 23
      Assets/Data/UniversalRP/PlanarReflectionRenderer.asset
  3. 998
      Assets/Objects/environment/Clouds/Clouds.FBDA.tif.meta
  4. 8
      Assets/Objects/environment/Clouds/Clouds.LURD.tif.meta
  5. 3
      Assets/Objects/environment/Clouds/Clouds.mat
  6. 748
      Assets/Objects/environment/Clouds/Clouds.shadergraph
  7. 800
      Assets/Objects/environment/Clouds/ComputeLightmap.shadersubgraph
  8. 7
      Assets/Objects/environment/Clouds/Shader Graphs_Clouds.mat
  9. 31
      Assets/Shaders/CustomLighting.hlsl
  10. 113
      Assets/Scripts/Environment/SkyboxFeature.cs
  11. 11
      Assets/Scripts/Environment/SkyboxFeature.cs.meta

72
Assets/Data/UniversalRP/BoatDemoRenderer.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-6815688936837802928
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6b3d386ba5cd94485973aee1479b272e, type: 3}
m_Name: NewRenderObjects
m_EditorClassIdentifier:
m_Active: 0
settings:
passTag: NewRenderObjects
Event: 300
filterSettings:
RenderQueueType: 1
LayerMask:
serializedVersion: 2
m_Bits: 256
PassNames: []
overrideMaterial: {fileID: 0}
overrideMaterialPassIndex: 0
overrideDepthState: 0
depthCompareFunction: 4
enableWrite: 1
stencilSettings:
overrideStencilState: 0
stencilReference: 0
stencilCompareFunction: 8
passOperation: 0
failOperation: 0
zFailOperation: 0
cameraSettings:
overrideCamera: 1
restoreCamera: 1
offset: {x: -9.82, y: 32.74, z: 9.93, w: 1}
cameraFieldOfView: 60
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0

m_EditorClassIdentifier:
m_RendererFeatures:
- {fileID: 770174969183694509}
m_RendererFeatureMap: ad6e17cd0d36b00a
- {fileID: 7959035961846237700}
- {fileID: -6815688936837802928}
m_RendererFeatureMap: ad6e17cd0d36b00a048a67dc092d746e501439e405cf69a1
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}

fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3}
m_OpaqueLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_Bits: 2147614263
m_Bits: 4294967295
m_Bits: 2147614263
overrideStencilState: 0
overrideStencilState: 1
failOperation: 0
failOperation: 2
m_ShadowTransparentReceive: 1
m_ShadowTransparentReceive: 0
--- !u!114 &770174969183694509
MonoBehaviour:
m_ObjectHideFlags: 0

causticBlendDistance: 3.36
debug: 0
causticShader: {fileID: 4800000, guid: 90939d2e4b62841d29c136c866715501, type: 3}
causticTexture: {fileID: 2800000, guid: f395b7d64f44848c6a3cba1f1173fe90, type: 3}
--- !u!114 &7959035961846237700
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 73a60ff029db77a498e020817f4aa301, type: 3}
m_Name: NewSkyboxFeature
m_EditorClassIdentifier:
m_Active: 1
injectionPoint: 400
mask:
serializedVersion: 2
m_Bits: 256
ratioScale: 64

23
Assets/Data/UniversalRP/PlanarReflectionRenderer.asset


m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
m_Name: PlanarReflectionRenderer
m_EditorClassIdentifier:
m_RendererFeatures: []
m_RendererFeatures:
- {fileID: 2592635787774994150}
m_RendererFeatureMap: e6264b3a83e4fa23
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}

passOperation: 2
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 1
--- !u!114 &2592635787774994150
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 73a60ff029db77a498e020817f4aa301, type: 3}
m_Name: NewSkyboxFeature
m_EditorClassIdentifier:
m_Active: 1
injectionPoint: 400
mask:
serializedVersion: 2
m_Bits: 256
ratioScale: 64

998
Assets/Objects/environment/Clouds/Clouds.FBDA.tif.meta
文件差异内容过多而无法显示
查看文件

8
Assets/Objects/environment/Clouds/Clouds.LURD.tif.meta


externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
mipMapMode: 1
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0

maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
filterMode: 0
aniso: -1
mipBias: -100
wrapU: -1

3
Assets/Objects/environment/Clouds/Clouds.mat


m_Name: Clouds
m_Shader: {fileID: -6465566751694194690, guid: 0b74f0b1b09e147efb2d08ef50ff0a6c,
type: 3}
m_ShaderKeywords:
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []

748
Assets/Objects/environment/Clouds/Clouds.shadergraph
文件差异内容过多而无法显示
查看文件

800
Assets/Objects/environment/Clouds/ComputeLightmap.shadersubgraph
文件差异内容过多而无法显示
查看文件

7
Assets/Objects/environment/Clouds/Shader Graphs_Clouds.mat


m_Name: Shader Graphs_Clouds
m_Shader: {fileID: -6465566751694194690, guid: db0b334ed7edc2149a5c784f34eefeba,
type: 3}
m_ShaderKeywords:
m_ShaderKeywords: BOOLEAN_68600FB702FC441CA4969E5B54503936_ON ETC1_EXTERNAL_ALPHA
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- BOOLEAN_68600FB702FC441CA4969E5B54503936: 1
- Vector1_10DA9AB3: 0
- Vector1_10DA9AB3: 0.02
- Vector1_33982692: 0.08
- Vector1_33982692: 2.3
m_Colors: []
m_BuildTextureStacks: []

31
Assets/Shaders/CustomLighting.hlsl


#endif
}
void MainLight_half(out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#ifdef SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
Light mainLight = GetMainLight();
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = mainLight.shadowAttenuation;
#endif
}
void SampleSH_half(half3 normalWS, out half3 Ambient)
{
// LPPV is not supported in Ligthweight Pipeline

SHCoefficients[6] = unity_SHC;
Ambient = max(half3(0, 0, 0), SampleSH9(SHCoefficients, normalWS));
}
void SampleSH_float(float3 normalWS, out float3 Ambient)
{
// LPPV is not supported in Ligthweight Pipeline
real4 SHCoefficients[7];
SHCoefficients[0] = unity_SHAr;
SHCoefficients[1] = unity_SHAg;
SHCoefficients[2] = unity_SHAb;
SHCoefficients[3] = unity_SHBr;
SHCoefficients[4] = unity_SHBg;
SHCoefficients[5] = unity_SHBb;
SHCoefficients[6] = unity_SHC;
Ambient = max(float3(0, 0, 0), SampleSH9(SHCoefficients, normalWS));
}

113
Assets/Scripts/Environment/SkyboxFeature.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class SkyboxFeature : ScriptableRendererFeature
{
class SkyboxPass : ScriptableRenderPass
{
private const string ProfilerTag = "3D Skybox Pass";
FilteringSettings m_OpaqueFilteringSettings;
FilteringSettings m_TransparentFilteringSettings;
RenderStateBlock m_RenderStateBlock;
readonly ProfilingSampler _profilingSampler = new ProfilingSampler("3D Skybox Pass");
List<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>{new ShaderTagId("SRPDefaultUnlit"),
new ShaderTagId("UniversalForward"),
new ShaderTagId("LightweightForward")};
public float Scale;
public LayerMask mask;
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
// When empty this render pass will render to the active camera render target.
// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
// The render pipeline will ensure target setup and clearing happens in an performance manner.
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
m_RenderStateBlock.mask = RenderStateMask.Stencil | RenderStateMask.Depth;
StencilState stencilState = StencilState.defaultValue;
stencilState.SetCompareFunction(CompareFunction.Equal);
m_RenderStateBlock.stencilReference = 0;
m_RenderStateBlock.stencilState = stencilState;
//DepthState depthState = new DepthState(false, CompareFunction.Less);
//m_RenderStateBlock.depthState = depthState;
m_OpaqueFilteringSettings = new FilteringSettings(RenderQueueRange.opaque, mask);
m_TransparentFilteringSettings = new FilteringSettings(RenderQueueRange.transparent, mask);
}
// Here you can implement the rendering logic.
// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cameraData = renderingData.cameraData;
DrawingSettings opaqueDrawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);
DrawingSettings transparentDrawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);
CommandBuffer cmd = CommandBufferPool.Get(ProfilerTag);
using (new ProfilingScope(cmd, _profilingSampler))
{
// setup skybox cam
{
var viewMatrix = cameraData.GetViewMatrix();
var cameraTranslation = viewMatrix.GetColumn(3);
var camScale = cameraTranslation * Scale;
Debug.Log($"scale is {Scale}");
cameraTranslation = new Vector4(camScale.x, camScale.y, camScale.z, cameraTranslation.w);
viewMatrix.SetColumn(3, cameraTranslation);
RenderingUtils.SetViewAndProjectionMatrices(cmd, viewMatrix, cameraData.GetGPUProjectionMatrix(), true);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraData.camera.transform.position * Scale);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
//draw opaque skybox
context.DrawRenderers(renderingData.cullResults, ref opaqueDrawingSettings, ref m_OpaqueFilteringSettings,
ref m_RenderStateBlock);
//draw transparent skybox
context.DrawRenderers(renderingData.cullResults, ref transparentDrawingSettings, ref m_TransparentFilteringSettings,
ref m_RenderStateBlock);
//return normal cam
{
RenderingUtils.SetViewAndProjectionMatrices(cmd, cameraData.GetViewMatrix(), cameraData.GetGPUProjectionMatrix(), true);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraData.camera.transform.position);
}
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
/// Cleanup any allocated resources that were created during the execution of this render pass.
public override void OnCameraCleanup(CommandBuffer cmd)
{
base.OnCameraCleanup(cmd);
}
}
SkyboxPass m_ScriptablePass;
private RenderObjectsPass opaquePass;
public RenderPassEvent injectionPoint;
public LayerMask mask;
public int ratioScale = 64;
public override void Create()
{
m_ScriptablePass = new SkyboxPass {renderPassEvent = injectionPoint, Scale = 1.0f / ratioScale, mask = mask};
}
// Here you can inject one or multiple render passes in the renderer.
// This method is called when setting up the renderer once per-camera.
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(m_ScriptablePass);
}
}

11
Assets/Scripts/Environment/SkyboxFeature.cs.meta


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