提交破碎效果

This commit is contained in:
2025-05-22 19:00:40 +08:00
parent a6d2f1f199
commit c54db1085e
11 changed files with 541 additions and 0 deletions
@@ -0,0 +1,45 @@
fileFormatVersion: 2
guid: 32b86414a60202441bd5c0f4415a2a7f
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
@@ -0,0 +1,45 @@
fileFormatVersion: 2
guid: 560508b9f7b81b84a87c8a53029f2540
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
+126
View File
@@ -0,0 +1,126 @@
Shader "Hidden/BrokenGlassEffect"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_MainTex2 ("Glass Texture", 2D) = "white" {}
_Value ("Distortion Strength", Float) = 1.0
_Bullet_1 ("Bullet 1", Float) = 1.0
_Bullet_2 ("Bullet 2", Float) = 1.0
_Bullet_3 ("Bullet 3", Float) = 1.0
_Bullet_4 ("Bullet 4", Float) = 1.0
_Bullet_5 ("Bullet 5", Float) = 1.0
_Bullet_6 ("Bullet 6", Float) = 1.0
_Bullet_7 ("Bullet 7", Float) = 1.0
_Bullet_8 ("Bullet 8", Float) = 1.0
_Bullet_9 ("Bullet 9", Float) = 1.0
_Bullet_10 ("Bullet 10", Float) = 1.0
_Bullet_11 ("Bullet 11", Float) = 1.0
_Bullet_12 ("Bullet 12", Float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }
LOD 100
Pass
{
Name "BrokenGlassEffect"
ZTest Always Cull Off ZWrite Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _MainTex2;
float4 _MainTex_TexelSize;
float _Value;
float _Bullet_1;
float _Bullet_2;
float _Bullet_3;
float _Bullet_4;
float _Bullet_5;
float _Bullet_6;
float _Bullet_7;
float _Bullet_8;
float _Bullet_9;
float _Bullet_10;
float _Bullet_11;
float _Bullet_12;
Varyings Vert(Attributes input)
{
Varyings output;
output.positionHCS = TransformObjectToHClip(input.positionOS.xyz);
output.uv = input.uv;
return output;
}
half4 Frag(Varyings i) : SV_Target
{
float2 uv = i.uv;
float2 uv2 = uv;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
uv.y = 1-uv.y;
#endif
uv /= 2;
float col = 0;
// Red channel sampling
col = (tex2D(_MainTex2, uv).rgb * _Bullet_1).r;
uv += float2(0.5, 0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_2).r;
uv += float2(0, 0.5);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_3).r;
uv -= float2(0.5, 0.0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_4).r;
// Green channel sampling
col += (tex2D(_MainTex2, uv).rgb * _Bullet_5).g;
uv += float2(0.5, 0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_6).g;
uv += float2(0, 0.5);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_7).g;
uv -= float2(0.5, 0.0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_8).g;
// Blue channel sampling
col += (tex2D(_MainTex2, uv).rgb * _Bullet_9).b;
uv += float2(0.5, 0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_10).b;
uv += float2(0, 0.5);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_11).b;
uv -= float2(0.5, 0.0);
col += (tex2D(_MainTex2, uv).rgb * _Bullet_12).b;
uv2 += float2(col, col) / 4;
float3 col2 = tex2D(_MainTex, uv2).rgb;
float c = col;
col2 = col2 + float3(c, c, c);
return float4(col2, 1.0);
}
ENDHLSL
}
}
}
+152
View File
@@ -0,0 +1,152 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class BrokenGlassRenderFeature : ScriptableRendererFeature
{
class BrokenGlassPass : ScriptableRenderPass
{
static readonly string ProfilerTag = "Broken Glass Effect";
Material material;
RenderTargetIdentifier source;
RenderTargetHandle tempTexture;
public float Value = 1f;
public float Bullet_1 = 1f;
public float Bullet_2 = 1f;
public float Bullet_3 = 1f;
public float Bullet_4 = 1f;
public float Bullet_5 = 1f;
public float Bullet_6 = 1f;
public float Bullet_7 = 1f;
public float Bullet_8 = 1f;
public float Bullet_9 = 1f;
public float Bullet_10 = 1f;
public float Bullet_11 = 1f;
public float Bullet_12 = 1f;
public Texture2D GlassTexture;
public BrokenGlassPass(Material mat)
{
material = mat;
tempTexture.Init("_TempBrokenGlassTex");
}
public void Setup(RenderTargetIdentifier src)
{
source = src;
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (material == null)
{
Debug.LogError("BrokenGlassPass: Material is null!");
return;
}
if (GlassTexture == null)
{
Debug.LogError("BrokenGlassPass: GlassTexture is null!");
return;
}
CommandBuffer cmd = CommandBufferPool.Get(ProfilerTag);
source = renderingData.cameraData.renderer.cameraColorTarget;
RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
opaqueDesc.depthBufferBits = 0;
cmd.GetTemporaryRT(tempTexture.id, opaqueDesc);
cmd.SetGlobalTexture("_MainTex2", GlassTexture);
cmd.SetGlobalFloat("_Value", Value);
cmd.SetGlobalFloat("_Bullet_1", Bullet_1);
cmd.SetGlobalFloat("_Bullet_2", Bullet_2);
cmd.SetGlobalFloat("_Bullet_3", Bullet_3);
cmd.SetGlobalFloat("_Bullet_4", Bullet_4);
cmd.SetGlobalFloat("_Bullet_5", Bullet_5);
cmd.SetGlobalFloat("_Bullet_6", Bullet_6);
cmd.SetGlobalFloat("_Bullet_7", Bullet_7);
cmd.SetGlobalFloat("_Bullet_8", Bullet_8);
cmd.SetGlobalFloat("_Bullet_9", Bullet_9);
cmd.SetGlobalFloat("_Bullet_10", Bullet_10);
cmd.SetGlobalFloat("_Bullet_11", Bullet_11);
cmd.SetGlobalFloat("_Bullet_12", Bullet_12);
Debug.Log($"BrokenGlassPass Parameters - Value: {Value}, Bullet_1: {Bullet_1}, Bullet_2: {Bullet_2}, Bullet_3: {Bullet_3}, Bullet_4: {Bullet_4}, Bullet_5: {Bullet_5}, Bullet_6: {Bullet_6}, Bullet_7: {Bullet_7}, Bullet_8: {Bullet_8}, Bullet_9: {Bullet_9}, Bullet_10: {Bullet_10}, Bullet_11: {Bullet_11}, Bullet_12: {Bullet_12}");
Blit(cmd, source, tempTexture.Identifier(), material, 0);
Blit(cmd, tempTexture.Identifier(), source);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void FrameCleanup(CommandBuffer cmd)
{
if (tempTexture != RenderTargetHandle.CameraTarget)
cmd.ReleaseTemporaryRT(tempTexture.id);
}
}
[System.Serializable]
public class BrokenGlassSettings
{
public Material Material;
public Texture2D GlassTexture;
[Range(0f, 2f)] public float Value = 1f;
[Range(0f, 2f)] public float Bullet_1 = 1f;
[Range(0f, 2f)] public float Bullet_2 = 1f;
[Range(0f, 2f)] public float Bullet_3 = 1f;
[Range(0f, 2f)] public float Bullet_4 = 1f;
[Range(0f, 2f)] public float Bullet_5 = 1f;
[Range(0f, 2f)] public float Bullet_6 = 1f;
[Range(0f, 2f)] public float Bullet_7 = 1f;
[Range(0f, 2f)] public float Bullet_8 = 1f;
[Range(0f, 2f)] public float Bullet_9 = 1f;
[Range(0f, 2f)] public float Bullet_10 = 1f;
[Range(0f, 2f)] public float Bullet_11 = 1f;
[Range(0f, 2f)] public float Bullet_12 = 1f;
public RenderPassEvent RenderPassEvent = RenderPassEvent.AfterRenderingTransparents;
}
public BrokenGlassSettings settings = new BrokenGlassSettings();
BrokenGlassPass pass;
public override void Create()
{
if (settings.Material == null)
return;
pass = new BrokenGlassPass(settings.Material)
{
Value = settings.Value,
Bullet_1 = settings.Bullet_1,
Bullet_2 = settings.Bullet_2,
Bullet_3 = settings.Bullet_3,
Bullet_4 = settings.Bullet_4,
Bullet_5 = settings.Bullet_5,
Bullet_6 = settings.Bullet_6,
Bullet_7 = settings.Bullet_7,
Bullet_8 = settings.Bullet_8,
Bullet_9 = settings.Bullet_9,
Bullet_10 = settings.Bullet_10,
Bullet_11 = settings.Bullet_11,
Bullet_12 = settings.Bullet_12,
GlassTexture = settings.GlassTexture,
renderPassEvent = settings.RenderPassEvent
};
Debug.Log("BrokenGlassRenderFeature Created");
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (settings.Material != null)
{
renderer.EnqueuePass(pass);
}
Debug.Log($"Material is null: {settings.Material == null}");
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96e615a1ffda3624d856e8a0000aa411
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+70
View File
@@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: crack1
m_Shader: {fileID: 4800000, guid: 79a9caf74ebe6b144a8f342b9a657be0, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 8400000, guid: f279841145311074a93b610689725867, type: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex2:
m_Texture: {fileID: 2800000, guid: 560508b9f7b81b84a87c8a53029f2540, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Bullet_1: 1
- _Bullet_10: 0
- _Bullet_11: 0
- _Bullet_12: 0
- _Bullet_2: 0
- _Bullet_3: 0
- _Bullet_4: 0
- _Bullet_5: 0
- _Bullet_6: 0
- _Bullet_7: 0
- _Bullet_8: 0
- _Bullet_9: 0
- _EnableExternalAlpha: 0
- _Value: 1
- _Value2: 103.57
- _Value3: 100
- _Value4: 100
- _Value5: 100
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be8f68a2f1f1c5641b2b8ab944bec364
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
+70
View File
@@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: crack2
m_Shader: {fileID: 4800000, guid: 79a9caf74ebe6b144a8f342b9a657be0, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 8400000, guid: f279841145311074a93b610689725867, type: 2}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex2:
m_Texture: {fileID: 2800000, guid: 560508b9f7b81b84a87c8a53029f2540, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Bullet_1: 1
- _Bullet_10: 0
- _Bullet_11: 0
- _Bullet_12: 0
- _Bullet_2: 0
- _Bullet_3: 0
- _Bullet_4: 0
- _Bullet_5: 0
- _Bullet_6: 0
- _Bullet_7: 0
- _Bullet_8: 0
- _Bullet_9: 0
- _EnableExternalAlpha: 0
- _Value: 1
- _Value2: 103.57
- _Value3: 100
- _Value4: 100
- _Value5: 100
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8d2b4d7587eb8fa489452211ed3df633
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant: