Andre McGrail
4 年前
当前提交
bc4fd53b
共有 10 个文件被更改,包括 180 次插入 和 0 次删除
-
8Assets/Scripts/_Test/CustomPP/PsudoLensFlare.meta
-
10Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PseudoFlareVolume.cs
-
11Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PseudoFlareVolume.cs.meta
-
74Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PseudoLensflareFeature.cs
-
11Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PseudoLensflareFeature.cs.meta
-
57Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PsudoLenflare.shader
-
9Assets/Scripts/_Test/CustomPP/PsudoLensFlare/PsudoLenflare.shader.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 796c339a8a7dfa94e813c5a16792e893 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
|
|||
[Serializable, VolumeComponentMenu("Custom/Pseudo Lensflare")] |
|||
public class PseudoFlareVolume : VolumeComponent |
|||
{ |
|||
[Range(0f, 1f), Tooltip("Grayscale effect intensity")] |
|||
public FloatParameter blend = new FloatParameter(0.5f); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 89201a0f12f0ed4479dc17dd1184d946 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
public class PseudoLensflareFeature : ScriptableRendererFeature |
|||
{ |
|||
class PseudoLensflarePass : ScriptableRenderPass |
|||
{ |
|||
public Material blitMaterial; |
|||
private PseudoFlareVolume component { get; set; } |
|||
private RenderTargetIdentifier source { get; set; } |
|||
private RenderTargetHandle destination { get; set; } |
|||
|
|||
string m_ProfilerTag; |
|||
|
|||
public PseudoLensflarePass(Material blitMaterial) |
|||
{ |
|||
this.blitMaterial = blitMaterial; |
|||
renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing; |
|||
m_ProfilerTag = "Grayscale"; |
|||
} |
|||
|
|||
public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination, PseudoFlareVolume component) |
|||
{ |
|||
this.component = component; |
|||
this.source = source; |
|||
this.destination = destination; |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
if (component == null || !component.active) return; |
|||
|
|||
blitMaterial.SetFloat(Blend, component.blend.value); |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); |
|||
|
|||
RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor; |
|||
opaqueDesc.depthBufferBits = 0; |
|||
|
|||
Blit(cmd, source, destination.Identifier(), blitMaterial); |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
|
|||
public Material blitMaterial; |
|||
PseudoLensflarePass _blitPass; |
|||
private static readonly int Blend = Shader.PropertyToID("_Blend"); |
|||
|
|||
public override void Create() |
|||
{ |
|||
_blitPass = new PseudoLensflarePass(blitMaterial); |
|||
} |
|||
|
|||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) |
|||
{ |
|||
var component = VolumeManager.instance.stack.GetComponent<PseudoFlareVolume>(); |
|||
if (component == null || !component.active) return; |
|||
|
|||
if (blitMaterial == null) |
|||
{ |
|||
Debug.LogWarningFormat("Missing Blit Material. {0} blit pass will not execute. Check for missing reference in the assigned renderer.", GetType().Name); |
|||
return; |
|||
} |
|||
|
|||
var src = renderer.cameraColorTarget; |
|||
var dest = RenderTargetHandle.CameraTarget; |
|||
|
|||
_blitPass.Setup(src, dest, component); |
|||
renderer.EnqueuePass(_blitPass); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ece83f81b0823f4e8ecbebfee7c04f0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/PostFX/PseudoLensFlare" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", 2D) = "white" {} |
|||
} |
|||
HLSLINCLUDE |
|||
|
|||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
|||
|
|||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); |
|||
float _Blend; |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 vertex : POSITION; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
float4 Frag(Varyings i) : SV_Target |
|||
{ |
|||
float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord); |
|||
float luminance = dot(color.rgb, float3(0.2126729, 0.7151522, 0.0721750)); |
|||
color.rgb = lerp(color.rgb, luminance.xxx, _Blend.xxx); |
|||
return color; |
|||
} |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Cull Off ZWrite Off ZTest Always |
|||
|
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
Varyings VertDefault(Attributes v) |
|||
{ |
|||
Varyings o; |
|||
o.vertex = float4(v.vertex.xy * 2.0 - 1.0, 0.0, 1.0); |
|||
o.texcoord = v.vertex.xy; |
|||
return o; |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 933b5941d4ae5084a92ee525b3fe5d28 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue