浏览代码

Solved culling issue by having skybox follow camera, downside is shader code(world position etc)

/feature-new-clouds
André McGrail 4 年前
当前提交
b3469914
共有 7 个文件被更改,包括 1331 次插入116 次删除
  1. 44
      Assets/Data/UniversalRP/BoatDemoRenderer.asset
  2. 359
      Assets/Objects/environment/Clouds/Clouds.shadergraph
  3. 16
      Assets/Objects/environment/Clouds/Shader Graphs_Clouds.mat
  4. 25
      Assets/Scripts/Environment/SkyboxFeature.cs
  5. 962
      Assets/scenes/demo_Island.unity
  6. 30
      Assets/Scripts/Utility/SkyboxSystem.cs
  7. 11
      Assets/Scripts/Utility/SkyboxSystem.cs.meta

44
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_RendererFeatures:
- {fileID: 770174969183694509}
- {fileID: 7959035961846237700}
- {fileID: -6815688936837802928}
m_RendererFeatureMap: ad6e17cd0d36b00a048a67dc092d746e501439e405cf69a1
m_RendererFeatureMap: ad6e17cd0d36b00a048a67dc092d746e
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
shaders:

failOperation: 2
zFailOperation: 0
m_ShadowTransparentReceive: 0
m_RenderingMode: 0
m_AccurateGbufferNormals: 0
--- !u!114 &770174969183694509
MonoBehaviour:
m_ObjectHideFlags: 0

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

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


m_Texture: {fileID: 2800000, guid: dfb2be980b2d27e4391744b60ca78600, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Vector1_10DA9AB3: 0.02
- Vector1_10DA9AB3: -0.32
- Vector1_33982692: 2.3
- Vector1_33982692: 1.29
m_Colors: []
m_BuildTextureStacks: []

25
Assets/Scripts/Environment/SkyboxFeature.cs


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);
}

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cameraData = renderingData.cameraData;
var cameraPosition = cameraData.camera.transform.position;
CommandBuffer cmd = CommandBufferPool.Get(ProfilerTag);
using (new ProfilingScope(cmd, _profilingSampler))
{

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);
var camPosition = viewMatrix.GetColumn(3);
var camScale = camPosition * Scale + camPosition;
var cameraTranslation = new Vector4(camScale.x, camScale.y, camScale.z, camPosition.w);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraData.camera.transform.position * Scale);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraPosition * Scale + cameraPosition);
//cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraPosition * Scale);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraData.camera.transform.position);
cmd.SetGlobalVector("_WorldSpaceCameraPos", cameraPosition);
}
}
context.ExecuteCommandBuffer(cmd);

962
Assets/scenes/demo_Island.unity
文件差异内容过多而无法显示
查看文件

30
Assets/Scripts/Utility/SkyboxSystem.cs


using UnityEngine;
using UnityEngine.Rendering;
[ExecuteAlways]
public class SkyboxSystem : MonoBehaviour
{
public int scalefactor = 64;
private void OnEnable()
{
RenderPipelineManager.beginCameraRendering += OnCamera;
RenderPipelineManager.endCameraRendering += OnCameraFinish;
}
private void OnDisable()
{
RenderPipelineManager.beginCameraRendering -= OnCamera;
RenderPipelineManager.endCameraRendering -= OnCameraFinish;
}
private void OnCamera(ScriptableRenderContext context, Camera camera)
{
transform.position = Vector3.Lerp(camera.transform.position, Vector3.zero, 1f / scalefactor);
}
private void OnCameraFinish(ScriptableRenderContext context, Camera camera)
{
transform.position = Vector3.zero;
}
}

11
Assets/Scripts/Utility/SkyboxSystem.cs.meta


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