Skip to content

Commit

Permalink
Change Layer Mask (#8)
Browse files Browse the repository at this point in the history
* Change Layer Mask

* Refactor KawaseBlur

* Update FluidRendering scene
  • Loading branch information
Karm0tr1ne authored Jun 25, 2023
1 parent 3781ecb commit 79295c6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Assets/Soft2D/Samples/01_FluidRendering/FluidRendering.unity
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ MonoBehaviour:
smoothness: 0
metallic: 0
occlusionSize: 0
layerIndex: 3
layerIndex: 4
debugQuad: {fileID: 0}
colliderCol: {r: 0.3647059, g: 0.90588236, b: 0, a: 1}
triggerCol: {r: 0.9647059, g: 0.93333334, b: 0.023529412, a: 1}
Expand Down Expand Up @@ -673,7 +673,7 @@ Camera:
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 55
m_Bits: 39
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
Expand Down
59 changes: 54 additions & 5 deletions Assets/Soft2D/Samples/02_2DGame/Level 1.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,55 @@ MonoBehaviour:
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!1 &659387453
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 659387455}
- component: {fileID: 659387454}
m_Layer: 0
m_Name: Global Volume
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &659387454
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 659387453}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 172515602e62fb746b5d573b38a5fe58, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IsGlobal: 1
priority: 0
blendDistance: 0
weight: 1
sharedProfile: {fileID: 11400000, guid: 1c821155a8cecdc4bb9df511090c5cbd, type: 2}
--- !u!4 &659387455
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 659387453}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &695549631 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1161309370464670779, guid: abd937719b287894a8cbc2e4595bdf57,
Expand All @@ -1908,7 +1957,7 @@ MonoBehaviour:
m_RendererIndex: 1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 8
m_Bits: 16
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
Expand Down Expand Up @@ -1952,7 +2001,7 @@ Camera:
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 8
m_Bits: 16
m_RenderingPath: -1
m_TargetTexture: {fileID: 8400000, guid: 4464763efa2a71845b5091474e900b86, type: 2}
m_TargetDisplay: 0
Expand Down Expand Up @@ -35505,7 +35554,7 @@ PrefabInstance:
- target: {fileID: 3785404050484907311, guid: 3fdcf0379bda1bb42a480291814196e0,
type: 3}
propertyPath: layerIndex
value: 3
value: 4
objectReference: {fileID: 0}
- target: {fileID: 3785404050484907311, guid: 3fdcf0379bda1bb42a480291814196e0,
type: 3}
Expand Down Expand Up @@ -35684,12 +35733,12 @@ PrefabInstance:
- target: {fileID: 3949743919671436436, guid: dcf12b49f3b24a84abf5c8e11c6156d8,
type: 3}
propertyPath: orthographic size
value: 1.0618955
value: 1.1836563
objectReference: {fileID: 0}
- target: {fileID: 3949743919671436436, guid: dcf12b49f3b24a84abf5c8e11c6156d8,
type: 3}
propertyPath: m_CullingMask.m_Bits
value: 55
value: 39
objectReference: {fileID: 0}
- target: {fileID: 3949743919671436438, guid: dcf12b49f3b24a84abf5c8e11c6156d8,
type: 3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Active: 1
settings:
renderPassEvent: 500
blurMaterial: {fileID: 2100000, guid: 25648eedecbf8044bb546f64d3ce04f1, type: 2}
blurPasses: 2
downsample: 1
copyToFramebuffer: 0
outputTexture: {fileID: 8400000, guid: 964b3c2d2238578b1910f96eafc84f00, type: 2}
--- !u!114 &11400000
MonoBehaviour:
Expand Down
29 changes: 7 additions & 22 deletions Assets/Soft2D/Samples/02_2DGame/Resources/Materials/KawaseBlur.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ public class KawaseBlur : ScriptableRendererFeature
[System.Serializable]
public class KawaseBlurSettings
{
public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
public Material blurMaterial = null;
public Material blurMaterial;

[Range(2,15)]
public int blurPasses = 2;

[Range(1,4)]
public int downsample = 1;
public bool copyToFramebuffer = true;
public RenderTexture outputTexture;
}

Expand All @@ -26,9 +24,7 @@ class CustomRenderPass : ScriptableRenderPass
public Material blurMaterial;
public int passes;
public int downsample;
public bool copyToFramebuffer;
public RenderTexture outputTexture;
string profilerTag;
public RenderTexture outputTexture;

int tmpId1;
int tmpId2;
Expand All @@ -38,11 +34,6 @@ class CustomRenderPass : ScriptableRenderPass

RenderTargetIdentifier cameraColorTexture;

public CustomRenderPass(string profilerTag)
{
this.profilerTag = profilerTag;
}

public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
var width = cameraTextureDescriptor.width / downsample;
Expand All @@ -63,7 +54,7 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
cameraColorTexture = renderingData.cameraData.renderer.cameraColorTarget;
CommandBuffer cmd = CommandBufferPool.Get(profilerTag);
CommandBuffer cmd = CommandBufferPool.Get("KawaseBlur");

RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
opaqueDesc.depthBufferBits = 0;
Expand All @@ -74,18 +65,13 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
for (var i=1; i<passes-1; i++) {
cmd.SetGlobalFloat("_offset", 0.5f + i);
cmd.Blit(tmpRT1, tmpRT2, blurMaterial);

(tmpRT1, tmpRT2) = (tmpRT2, tmpRT1);
}

// final pass
cmd.SetGlobalFloat("_offset", 0.5f + passes - 1f);
if (copyToFramebuffer) {
cmd.Blit(tmpRT1, cameraColorTexture, blurMaterial);
} else {
cmd.Blit(tmpRT1, tmpRT2, blurMaterial);
cmd.Blit(tmpRT2, outputTexture);
}
cmd.Blit(tmpRT1, tmpRT2, blurMaterial);
cmd.Blit(tmpRT2, outputTexture);

context.ExecuteCommandBuffer(cmd);
cmd.Clear();
Expand All @@ -100,13 +86,12 @@ public override void FrameCleanup(CommandBuffer cmd) { }

public override void Create()
{
scriptablePass = new CustomRenderPass("KawaseBlur");
scriptablePass = new CustomRenderPass();
scriptablePass.blurMaterial = settings.blurMaterial;
scriptablePass.passes = settings.blurPasses;
scriptablePass.downsample = settings.downsample;
scriptablePass.copyToFramebuffer = settings.copyToFramebuffer;
scriptablePass.outputTexture = settings.outputTexture;
scriptablePass.renderPassEvent = settings.renderPassEvent;
scriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
}

public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Camera:
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 72
m_Bits: 80
m_RenderingPath: -1
m_TargetTexture: {fileID: 8400000, guid: 4464763efa2a71845b5091474e900b86, type: 2}
m_TargetDisplay: 0
Expand Down Expand Up @@ -96,7 +96,7 @@ MonoBehaviour:
m_RendererIndex: 1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 8
m_Bits: 4294967295
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MonoBehaviour:
smoothness: 0
metallic: 0
occlusionSize: 0
layerIndex: 3
layerIndex: 4
debugQuad: {fileID: 0}
colliderCol: {r: 0.3647059, g: 0.90588236, b: 0, a: 1}
triggerCol: {r: 0.9647059, g: 0.93333334, b: 0.023529412, a: 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 1.0397489
orthographic size: 1.0440302
m_Depth: -1
m_CullingMask:
serializedVersion: 2
Expand Down Expand Up @@ -119,7 +119,7 @@ MonoBehaviour:
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 55
m_Bits: 39
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
Expand Down
1 change: 0 additions & 1 deletion Assets/Soft2D/Scripts/Soft2D/Soft2DManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ private void SetDebugTools()
enableRandomWrite = true,
useMipMap = false
};
// outputRT.antiAliasing =1;
outputRT.Create();
debugMaterial.SetTexture(MainTex, outputRT);

Expand Down

0 comments on commit 79295c6

Please sign in to comment.