cartoon plugins for unreal engine

Related tags

Graphics ToonShader
Overview

卡通材质

最终效果

使用方式

在材质编辑器中添加Toon Shading节点,ShadingModel即切换为SHADINGMODELID_STYLIZED_SHADOW
注意:添加节点后不再受编辑器中的ShadingModel变量控制

How to use

Add Toon Shading node in material editor, and ShadingModel property will be replaced as toon shading model.

插件添加ShadingModel大致流程

注意该教程在引擎版本4.26时作成

  • 继承UMaterialExpressionCustomOutput
    使用虚幻中UMaterialExpressionCustomOutput类型可在代码编译时插入条件编译宏的特性将自定义的ShadingModelId添加进Shader编译流程
    插件中重写的GetFunctionName返回的GetToonShading在shader对应的宏为NUM_MATERIAL_OUTPUTS_GETTOONSHADING

  • 进入引擎Engine/Shader目录修改和添加Shader文件

  • 修改ShadingCommon.ush中添加新的ShadingModel宏定义

    • 添加宏SHADINGMODELID_STYLIZED_SHADOW,且修改SHADINGMODELID_NUM的数量(注意当前最多支持16个)

      #define SHADINGMODELID_STYLIZED_SHADOW        12
      #define SHADINGMODELID_NUM                    13
    • 修改GetShadingModelColor函数,新增SHADINGMODELID_STYLIZED_SHADOW的调试颜色

  • 修改BasePassCommon.ushDeferredShadingCommon.ush开启自定义GBuffer的CustomData写入

    • BasePassCommon.ush WRITES_CUSTOMDATA_TO_GBUFFER宏,支持SHADINGMODELID_STYLIZED_SHADOW写入

      #define WRITES_CUSTOMDATA_TO_GBUFFER        (USES_GBUFFER && (MATERIAL_SHADINGMODEL_SUBSURFACE || MATERIAL_SHADINGMODEL_PREINTEGRATED_SKIN || MATERIAL_SHADINGMODEL_SUBSURFACE_PROFILE || MATERIAL_SHADINGMODEL_CLEAR_COAT || MATERIAL_SHADINGMODEL_TWOSIDED_FOLIAGE || MATERIAL_SHADINGMODEL_HAIR || MATERIAL_SHADINGMODEL_CLOTH || MATERIAL_SHADINGMODEL_EYE || SHADINGMODELID_STYLIZED_SHADOW))
    • DeferredShadingCommon.ush 修改HasCustomGBufferData函数,支持SHADINGMODELID_STYLIZED_SHADOW写入

      bool HasCustomGBufferData(int ShadingModelID)
      {
        return ShadingModelID == SHADINGMODELID_SUBSURFACE
          || ShadingModelID == SHADINGMODELID_PREINTEGRATED_SKIN
          || ShadingModelID == SHADINGMODELID_CLEAR_COAT
          || ShadingModelID == SHADINGMODELID_SUBSURFACE_PROFILE
          || ShadingModelID == SHADINGMODELID_TWOSIDED_FOLIAGE
          || ShadingModelID == SHADINGMODELID_HAIR
          || ShadingModelID == SHADINGMODELID_CLOTH
          || ShadingModelID == SHADINGMODELID_EYE
          || ShadingModelID == SHADINGMODELID_STYLIZED_SHADOW;
      }
  • 修改BasePassPixelShader.usf中ShadingModel的初始化

    #if NUM_MATERIAL_OUTPUTS_GETTOONSHADING
        uint ShadingModel = SHADINGMODELID_STYLIZED_SHADOW;
    #else
        uint ShadingModel = GetMaterialShadingModel(PixelMaterialInputs);
    #endif
  • 修改ShadingModelsMaterial.ush将额外的数据写入GBuffer的CustomData

    // 支持 MaterialExpressionCustomOutput 形式
    #if NUM_MATERIAL_OUTPUTS_GETTOONSHADING
        else if (ShadingModel == SHADINGMODELID_STYLIZED_SHADOW)
        {
            GBuffer.CustomData.x = saturate( GetToonShading0(MaterialParameters) );  // SpecularRange
            GBuffer.CustomData.y = saturate( GetToonShading1(MaterialParameters) );  // Offset
        }
    // 支持 ShadingModelId 形式
    #elif SHADINGMODELID_STYLIZED_SHADOW
        else if (ShadingModel == SHADINGMODELID_STYLIZED_SHADOW)
        {
            GBuffer.CustomData.x = saturate( GetMaterialCustomData0(MaterialParameters) );  // SpecularRange
            GBuffer.CustomData.y = saturate( GetMaterialCustomData1(MaterialParameters) );  // Offset
        }
    #endif
  • 修改ShadingModels.ush支持添加的ShadingModel的自定义BxDF函数
    IntegrateBxDF函数中添加SHADINGMODELID_STYLIZED_SHADOW的case

    case SHADINGMODELID_STYLIZED_SHADOW:
       return StylizedShadowBxDF(GBuffer, N, V, L, Falloff, NoL, AreaLight, Shadow);
  • 修改DeferredLightingCommon.ush自定义光照
    修改GetDynamicLightingSplit函数,通过GBuffer.ShadingModelID判断SHADINGMODELID_STYLIZED_SHADOW执行自定义光照逻辑

    // STYLIZEDSHADOW SHADING 
    if (GBuffer.ShadingModelID == SHADINGMODELID_STYLIZED_SHADOW)
    {
      float3 Attenuation = 1;
    
      float offset = GBuffer.CustomData.y;
      float TerminatorRange = saturate(GBuffer.Roughness - 0.5);
      
      offset = offset * 2 - 1;
      
      BRANCH
      if (offset >= 1)
      {
        Attenuation = 1;
      }
      else
      {
        float NoL = (dot(N, L) + 1) / 2;
        float NoLOffset = saturate(NoL + offset);
        float LightAttenuationOffset = saturate( Shadow.SurfaceShadow + offset);
        float ToonSurfaceShadow = smoothstep(0.5 - TerminatorRange, 0.5 + TerminatorRange, LightAttenuationOffset);
    
        Attenuation = smoothstep(0.5 - TerminatorRange, 0.5 + TerminatorRange, NoLOffset) * ToonSurfaceShadow;
      }
    
      LightAccumulator_AddSplit( LightAccumulator, Lighting.Diffuse, Lighting.Specular, Lighting.Diffuse, LightColor * LightMask * Shadow.SurfaceShadow * Attenuation * 0.25, > bNeedsSeparateSubsurfaceLightAccumulation);
    }
    else
    {
      LightAccumulator_AddSplit( LightAccumulator, Lighting.Diffuse, Lighting.Specular, Lighting.Diffuse, LightColor * LightMask * Shadow.SurfaceShadow, bNeedsSeparateSubsurfaceLightAccumulation );
    }

无法支持From Material Expression的原因

FMaterialShadingModelField::AddShadingModel 存在check(InShadingModel < MSM_NUM)检查导致没法Hack,导致新增的ShadingModel数量肯定超过MSM_NUM,引发断言导致编辑器crash

插件支持ShadingModel的方式

  • ToonShader模块
    该模块实现了UMaterialExpressionCustomOutput的子类,为运行时模块

  • ToonShaderBootstrap模块
    该模块会在引擎启动Shader编译前加载,用以向虚幻引擎Shader文件夹中替换默认Shader文件
    ShadersOverride文件夹下存放了shader文件

    • Default文件用来恢复
    • Override用来做替换,新增的Shader文件都需要存放在Toon目录下
You might also like...
3D engine from scratch (without OpenGL or any other 3D graphics library)
3D engine from scratch (without OpenGL or any other 3D graphics library)

Simple 3d engine based on SFML library. I tried to make this engine powerful and easy to understand.

Dear PyGui 3D Engine (early development) and Graphics API demos.
Dear PyGui 3D Engine (early development) and Graphics API demos.

Marvel This repo is the working location of the eventual Dear PyGui 3D Engine. It also contains several single file examples of creating a triangle wi

Orbit is a multiplatform-focus graphical engine build on top of OpenGl, ImGui
Orbit is a multiplatform-focus graphical engine build on top of OpenGl, ImGui

Orbit Engine Orbit is a multiplatform-focus graphical engine build on top of OpenGl, ImGui and more... The development of the engine is documented via

PainterEngine is a application/game engine with software renderer,PainterEngine can be transplanted to any platform that supports C
PainterEngine is a application/game engine with software renderer,PainterEngine can be transplanted to any platform that supports C

PainterEngine is a application/game engine with software renderer,PainterEngine can be transplanted to any platform that supports C

An integration of Live++ for Open 3D Engine

LivePlusPlus_O3DE_Gem An integration of https://liveplusplus.tech/ for Open 3D Engine (Windows only). See Open 3D Engine at https://github.com/o3de/o3

Voxelight is a simple voxel engine/sandbox
Voxelight is a simple voxel engine/sandbox

Voxelight is a learning project, I have no prior experience with OpenGL or any other graphics API for that matter.

Software RayTracing engine written in C++ without the usage of any libraries.
Software RayTracing engine written in C++ without the usage of any libraries.

Software Raytracing Engine This is a software unidirectional raytracing engine, fully written in C++17, with no dependencies or external libraries use

Tesseract Open Source OCR Engine (main repository)

Tesseract OCR Table of Contents Tesseract OCR About Brief history Installing Tesseract Running Tesseract For developers Support License Dependencies L

A completely free, open-source, 2D game engine built on proven torque technology.
A completely free, open-source, 2D game engine built on proven torque technology.

Torque2D 4.0 Early Access 1 MIT Licensed Open Source version of Torque2D from GarageGames. Maintained by the Torque Game Engines team and contribution

Comments
Releases(V1.0)
Owner
null
Procedural Mesh Modeling Toolkit for Unreal Engine Artists

OpenLand Mesh Procedural Mesh Modeling Toolkit for Unreal Engine Artists. Installation Get it via the marketplace ??️ For non-commercial projects, you

GameDev4K 25 Sep 3, 2022
A library in Javascript to create graphs in the browser similar to Unreal Blueprints.

A graph node engine and editor written in Javascript similar to PD or UDK Blueprints, comes with its own editor in HTML5 Canvas2D. The engine can run client side or server side using Node. It allows to export graphs as JSONs to be included in applications independently.

Javi Agenjo 3.1k Sep 25, 2022
Horde3D is a small 3D rendering and animation engine. It is written in an effort to create an engine being as lightweight and conceptually clean as possible.

Horde3D Horde3D is a 3D rendering engine written in C++ with an effort being as lightweight and conceptually clean as possible. Horde3D requires a ful

Volker Vogelhuber 1.3k Sep 29, 2022
Open 3D Engine (O3DE) is an Apache 2.0-licensed multi-platform AAA Open 3D Engine

Open 3D Engine (O3DE) is an Apache 2.0-licensed multi-platform 3D engine that enables developers and content creators to build AAA games, cinema-quality 3D worlds, and high-fidelity simulations without any fees or commercial obligations.

O3DE 5.4k Oct 4, 2022
Brand new engine with new and QoL features. Grafex is Psych engine with some additions and Better graphics

Friday Night Funkin' - Graphex Engine Credits: Grafex Mod aka Psych Graphic Rework: Xale - Lead Coding, Artist PurpleSnake - Second Coder Psych Engine

Xale 3 Sep 5, 2022
ORE (OpenGL Rendering Engine) is a rendering engine developed for my college minor project assessment.

ORE (OPENGL RENDERING ENGINE) What is ORE? ORE(OpenGL Rendering Engine) is a rendering engine with great and easy to use UI that allows the user to lo

HARSHIT BARGUJAR 3 Sep 23, 2022
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

bgfx - Cross-platform rendering library GitHub Discussions Discord Chat What is it? Cross-platform, graphics API agnostic, "Bring Your Own Engine/Fram

Бранимир Караџић 12.2k Oct 5, 2022
2D Vector Graphics Engine Powered by a JIT Compiler

Blend2D 2D Vector Graphics Powered by a JIT Compiler. Official Home Page (blend2d.com) Official Repository (blend2d/blend2d) Public Chat Channel Zlib

Blend2D 1.1k Oct 2, 2022
Cross-platform 2D and 3D game engine.

Urho3D Urho3D is a free lightweight, cross-platform 2D and 3D game engine implemented in C++ and released under the MIT license. Greatly inspired by O

null 4.1k Sep 30, 2022
Pure C Game Engine

Corange game engine Version 0.8.0 Written in Pure C, SDL and OpenGL. Running Corange is a library, but to take a quick look at some of the things it d

Daniel Holden 1.5k Sep 27, 2022