アウトラインを描画する仕組みを実装

This commit is contained in:
notargs 2023-04-28 17:32:06 +09:00
parent ee88a56c35
commit 2dc6cd0758
8 changed files with 140 additions and 7 deletions

View File

@ -12,8 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
m_Name: UniversalRenderPipelineAsset_Renderer
m_EditorClassIdentifier:
m_RendererFeatures: []
m_RendererFeatureMap:
m_RendererFeatures:
- {fileID: 6807519784255233043}
m_RendererFeatureMap: 131cfa0d2d2b795e
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
shaders:
@ -43,3 +44,16 @@ MonoBehaviour:
m_ShadowTransparentReceive: 1
m_RenderingMode: 0
m_AccurateGbufferNormals: 0
--- !u!114 &6807519784255233043
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: 5b6d00cd3f0249a2b4ee7dc86f9a8d63, type: 3}
m_Name: MToonOutlineRenderFeature
m_EditorClassIdentifier:
m_Active: 1

View File

@ -55,8 +55,7 @@ half4 MToonFragment(const FragmentInput fragmentInput) : SV_Target
mtoonInput.alpha = alpha;
half4 col = GetMToonLighting(unityLighting, mtoonInput);
#ifdef MTOON_URP
#ifdef _ADDITIONAL_LIGHTS
#if defined(MTOON_URP) && defined(_ADDITIONAL_LIGHTS) && !defined(MTOON_PASS_OUTLINE)
uint pixelLightCount = GetAdditionalLightsCount();
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
{
@ -64,7 +63,6 @@ half4 MToonFragment(const FragmentInput fragmentInput) : SV_Target
col.rgb += GetMToonURPAdditionalLighting(additionalUnityLighting, mtoonInput).rgb;
}
#endif
#endif
// Apply Fog
#ifdef MTOON_URP

View File

@ -117,6 +117,46 @@ Shader "VRM10/MToon10_URP"
ENDHLSL
}
// Built-in Forward Base Pass
Pass
{
Name "MToonOutline"
Tags { "LightMode" = "MToonOutline" }
Cull Front
Blend [_M_SrcBlend] [_M_DstBlend]
ZWrite [_M_ZWrite]
ZTest LEqual
Offset 1, 1
BlendOp Add, Max
AlphaToMask [_M_AlphaToMask]
HLSLPROGRAM
#pragma target 3.0
// Unity defined keywords
#pragma multi_compile_fwdbase nolightmap nodynlightmap nodirlightmap novertexlight
#pragma multi_compile_fog
#pragma multi_compile_instancing
#pragma multi_compile __ _ALPHATEST_ON _ALPHABLEND_ON
#pragma multi_compile __ _NORMALMAP
#pragma multi_compile __ _MTOON_EMISSIVEMAP
#pragma multi_compile __ _MTOON_RIMMAP
#pragma multi_compile __ _MTOON_PARAMETERMAP
#pragma multi_compile __ _MTOON_OUTLINE_WORLD _MTOON_OUTLINE_SCREEN
#pragma vertex MToonVertex
#pragma fragment MToonFragment
#define MTOON_URP
#define MTOON_PASS_OUTLINE
#include "./vrmc_materials_mtoon_forward_vertex.hlsl"
#include "./vrmc_materials_mtoon_forward_fragment.hlsl"
ENDHLSL
}
// Shadow rendering pass
Pass
{

View File

@ -0,0 +1,24 @@
#if MTOON_URP
using UnityEngine.Rendering.Universal;
namespace VRMShaders.VRM10.MToon10.Runtime
{
public sealed class MToonOutlineRenderFeature : ScriptableRendererFeature
{
private MToonOutlineRenderPass _pass;
public override void Create()
{
_pass = new MToonOutlineRenderPass
{
renderPassEvent = RenderPassEvent.AfterRenderingOpaques
};
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(_pass);
}
}
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5b6d00cd3f0249a2b4ee7dc86f9a8d63
timeCreated: 1682661280

View File

@ -0,0 +1,41 @@
#if MTOON_URP
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace VRMShaders.VRM10.MToon10.Runtime
{
public sealed class MToonOutlineRenderPass : ScriptableRenderPass
{
private const string ProfilerTag = nameof(MToonOutlineRenderPass);
private readonly ProfilingSampler _profilingSampler = new ProfilingSampler(ProfilerTag);
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, _profilingSampler))
{
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var camera = renderingData.cameraData.camera;
var shaderTagId = new ShaderTagId("MToonOutline");
var sortingSettings = new SortingSettings(camera);
var drawingSettings = new DrawingSettings(shaderTagId, sortingSettings)
{
perObjectData = PerObjectData.ReflectionProbes | PerObjectData.Lightmaps |
PerObjectData.LightProbe | PerObjectData.LightData | PerObjectData.OcclusionProbe |
PerObjectData.ShadowMask
};
var filteringSettings = FilteringSettings.defaultValue;
var renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing);
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings,
ref renderStateBlock);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
}
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df162971c1034acdbe28ff1ec94d8601
timeCreated: 1682665616

View File

@ -1,6 +1,10 @@
{
"name": "VRMShaders.VRM10.MToon10.Runtime",
"references": [],
"rootNamespace": "",
"references": [
"GUID:15fc0a57446b3144c949da3e2b9737a9",
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
@ -8,6 +12,12 @@
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.render-pipelines.core",
"expression": "",
"define": "MTOON_URP"
}
],
"noEngineReferences": false
}