Started on graphics configuration and rendering setup. Updated to DirectX 12 back-end, Rendergraph API and introduced some better graphics configuration options and post-processing.
parent
fa27693984
commit
017c769324
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a55ee4efaad27d948ba5f03fc6d7bc80
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed9b95dc6ed6d0647ad7f1a8f305385d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@ -1,63 +1,97 @@
|
||||
#nullable enable
|
||||
using System ;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
public class OutlineRenderFeature : ScriptableRendererFeature
|
||||
{
|
||||
class OutlinePass : ScriptableRenderPass
|
||||
{
|
||||
private RenderTargetHandle tempColorTexture;
|
||||
private Material outlineMaterial;
|
||||
private RenderTargetIdentifier cameraTarget;
|
||||
|
||||
public OutlinePass(Material material)
|
||||
{
|
||||
outlineMaterial = material;
|
||||
tempColorTexture.Init("_TemporaryColorTexture");
|
||||
}
|
||||
public class OutlineRenderFeature: ScriptableRendererFeature {
|
||||
static Material? outlineMaterial ;
|
||||
OutlinePass? outlinePass ;
|
||||
|
||||
class OutlinePass: ScriptableRenderPass {
|
||||
RTHandle? tempColorTexture,
|
||||
cameraRTHandle ;
|
||||
RenderTargetIdentifier cameraTarget ;
|
||||
|
||||
public OutlinePass( Material material ) => outlineMaterial = material ;
|
||||
|
||||
[Obsolete( "This rendering path is for compatibility mode only (when Render Graph is disabled). " +
|
||||
"Use Render Graph API instead.", false )]
|
||||
public override void Configure( CommandBuffer cmd,
|
||||
RenderTextureDescriptor cameraTextureDescriptor ) {
|
||||
/*cmd.GetTemporaryRT(tempColorTexture.id, cameraTextureDescriptor); // Create temp texture
|
||||
ConfigureTarget(tempColorTexture.Identifier());*/
|
||||
|
||||
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
|
||||
{
|
||||
cmd.GetTemporaryRT(tempColorTexture.id, cameraTextureDescriptor); // Create temp texture
|
||||
ConfigureTarget(tempColorTexture.Identifier());
|
||||
// Allocate RTHandles properly
|
||||
tempColorTexture = RTHandles.Alloc( cameraTextureDescriptor.width,
|
||||
cameraTextureDescriptor.height ) ;
|
||||
cameraRTHandle = RTHandles.Alloc( cameraTextureDescriptor.width,
|
||||
cameraTextureDescriptor.height ) ;
|
||||
|
||||
cmd.GetTemporaryRT( Shader.PropertyToID( tempColorTexture?.name ),
|
||||
cameraTextureDescriptor ) ; // Create temp texture
|
||||
|
||||
ConfigureTarget( tempColorTexture ) ;
|
||||
}
|
||||
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
if (outlineMaterial == null) return;
|
||||
[Obsolete( "This rendering path is for compatibility mode only (when Render Graph is disabled). " +
|
||||
"Use Render Graph API instead.", false )]
|
||||
public override void Execute( ScriptableRenderContext context,
|
||||
ref RenderingData renderingData ) {
|
||||
/*
|
||||
if ( !outlineMaterial ) return ;
|
||||
|
||||
CommandBuffer cmd = CommandBufferPool.Get("Outline Pass");
|
||||
cameraTarget = renderingData.cameraData.renderer.cameraColorTargetHandle; // ✅ Safe usage here
|
||||
Blit(cmd, cameraTarget, tempColorTexture ); // Copy to temp texture
|
||||
Blit(cmd, tempColorTexture, cameraTarget, outlineMaterial); // Apply outline effect
|
||||
|
||||
// Use new RTHandles API:
|
||||
Blitter.BlitCameraTexture( cmd, cameraRTHandle, tempColorTexture, Vector4.one ) ;
|
||||
Blitter.BlitCameraTexture( cmd, tempColorTexture,
|
||||
cameraRTHandle, 1, outlineMaterial ) ;
|
||||
|
||||
Blit(cmd, cameraTarget, tempColorTexture.Identifier()); // Copy to temp texture
|
||||
Blit(cmd, tempColorTexture.Identifier(), cameraTarget, outlineMaterial); // Apply outline effect
|
||||
// Copy to tempRT
|
||||
|
||||
context.ExecuteCommandBuffer( cmd ) ;
|
||||
CommandBufferPool.Release( cmd ) ;
|
||||
*/
|
||||
if (!outlineMaterial || tempColorTexture == null || cameraRTHandle == null) return;
|
||||
|
||||
CommandBuffer cmd = CommandBufferPool.Get("Outline Pass");
|
||||
|
||||
// Copy camera render target into temp texture
|
||||
Blitter.BlitCameraTexture( cmd, renderingData.cameraData.renderer.cameraColorTargetHandle,
|
||||
tempColorTexture, Vector4.one ) ;
|
||||
|
||||
// Apply outline material and write back to camera target
|
||||
Blitter.BlitCameraTexture(cmd, tempColorTexture,
|
||||
renderingData.cameraData.renderer.cameraColorTargetHandle,
|
||||
0, outlineMaterial ) ;
|
||||
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
CommandBufferPool.Release(cmd);
|
||||
}
|
||||
|
||||
public override void OnCameraCleanup(CommandBuffer cmd)
|
||||
{
|
||||
cmd.ReleaseTemporaryRT(tempColorTexture.id); // Cleanup
|
||||
public override void OnCameraCleanup( CommandBuffer cmd ) {
|
||||
tempColorTexture?.Release();
|
||||
cameraRTHandle?.Release();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private Material outlineMaterial;
|
||||
private OutlinePass outlinePass;
|
||||
public override void Create( ) {
|
||||
if ( !outlineMaterial ) {
|
||||
Debug.LogError( "Outline material is not assigned." ) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
outlinePass = new OutlinePass(outlineMaterial)
|
||||
{
|
||||
renderPassEvent = RenderPassEvent.AfterRenderingOpaques // ✅ Executes after opaque objects
|
||||
};
|
||||
outlinePass = new( outlineMaterial ) {
|
||||
renderPassEvent = RenderPassEvent.AfterRenderingOpaques, // ✅ Executes after opaque objects
|
||||
} ;
|
||||
}
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
if (outlinePass != null)
|
||||
{
|
||||
renderer.EnqueuePass(outlinePass);
|
||||
}
|
||||
public override void AddRenderPasses( ScriptableRenderer renderer,
|
||||
ref RenderingData renderingData ) {
|
||||
if ( outlinePass is not null ) renderer.EnqueuePass( outlinePass ) ;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue