From 2b1d765df780880d38ce165bf0b052db07202c9b Mon Sep 17 00:00:00 2001 From: "tomotaco(Tomotaka Ogino)" Date: Thu, 16 Jun 2022 17:30:39 +0900 Subject: [PATCH] =?UTF-8?q?5.0=E3=81=AB=E3=82=A2=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=82=B0=E3=83=AC=E3=83=BC=E3=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FVector等のfloat→double問題でRenderTargetに描画されない問題を修正。 Deprecated警告が出た箇所を修正。 --- .../Sketch/Source/Sketch/Private/Sketch.cpp | 2 +- .../Source/Sketch/Private/SketchComponent.cpp | 31 +++++++++-------- .../Source/Sketch/Private/SketchShader.cpp | 14 +------- .../Source/Sketch/Public/SketchShader.h | 10 +++--- UsfPluginProject/UsfPluginProject.uproject | 2 +- .../Source/ShaderModule/ShaderModule.cpp | 2 +- .../Source/ShaderModule/SketchComponent.cpp | 33 ++++++++++--------- .../Source/ShaderModule/SketchShader.cpp | 13 +------- UsfProject/Source/ShaderModule/SketchShader.h | 12 +++---- UsfProject/UsfProject.uproject | 2 +- 10 files changed, 46 insertions(+), 75 deletions(-) diff --git a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/Sketch.cpp b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/Sketch.cpp index 429b773..e96d8d0 100644 --- a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/Sketch.cpp +++ b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/Sketch.cpp @@ -7,7 +7,7 @@ void FSketchModule::StartupModule() { -#if (ENGINE_MINOR_VERSION >= 21) +#if (ENGINE_MINOR_VERSION >= 21 || ENGINE_MAJOR_VERSION >= 5) FString PluginDirectory = IPluginManager::Get().FindPlugin(TEXT("Sketch"))->GetBaseDir(); if(!AllShaderSourceDirectoryMappings().Contains("/Plugins/Sketch")) AddShaderSourceDirectoryMapping("/Plugins/Sketch", PluginDirectory); diff --git a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchComponent.cpp b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchComponent.cpp index 7093e4a..8c66000 100644 --- a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchComponent.cpp +++ b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchComponent.cpp @@ -58,18 +58,18 @@ void USketchComponent::ExecuteInRenderThread(FRHICommandListImmediate& RHICmdLis RHICmdList.ApplyCachedRenderTargets(PSOInitializer); PSOInitializer.PrimitiveType = PT_TriangleList; PSOInitializer.BoundShaderState.VertexDeclarationRHI = VertexDec.VertexDeclarationRHI; - PSOInitializer.BoundShaderState.VertexShaderRHI = GETSAFERHISHADER_VERTEX(*shaderVS); - PSOInitializer.BoundShaderState.PixelShaderRHI = GETSAFERHISHADER_PIXEL(*shaderPS); + PSOInitializer.BoundShaderState.VertexShaderRHI = shaderVS.GetVertexShader(); + PSOInitializer.BoundShaderState.PixelShaderRHI = shaderPS.GetPixelShader(); PSOInitializer.RasterizerState = TStaticRasterizerState::GetRHI(); PSOInitializer.BlendState = TStaticBlendState<>::GetRHI(); PSOInitializer.DepthStencilState = TStaticDepthStencilState::GetRHI(); - SetGraphicsPipelineState(RHICmdList, PSOInitializer); + SetGraphicsPipelineState(RHICmdList, PSOInitializer, 0); static const FSketchVertex Vertices[4] = { - { FVector4(-1.0f, 1.0f, 0.0f, 1.0f), FVector2D(0.0f, 0.0f)}, - { FVector4( 1.0f, 1.0f, 0.0f, 1.0f), FVector2D(1.0f, 0.0f)}, - { FVector4(-1.0f, -1.0f, 0.0f, 1.0f), FVector2D(0.0f, 1.0f)}, - { FVector4( 1.0f, -1.0f, 0.0f, 1.0f), FVector2D(1.0f, 1.0f)}, + { FVector4f(-1.0f, 1.0f, 0.0f, 1.0f), FVector2f(0.0f, 0.0f)}, + { FVector4f( 1.0f, 1.0f, 0.0f, 1.0f), FVector2f(1.0f, 0.0f)}, + { FVector4f(-1.0f, -1.0f, 0.0f, 1.0f), FVector2f(0.0f, 1.0f)}, + { FVector4f( 1.0f, -1.0f, 0.0f, 1.0f), FVector2f(1.0f, 1.0f)}, }; static const uint16 Indices[6] = @@ -78,8 +78,7 @@ void USketchComponent::ExecuteInRenderThread(FRHICommandListImmediate& RHICmdLis 2, 1, 3 }; - DrawIndexedPrimitiveUP(RHICmdList, PT_TriangleList, 0, ARRAY_COUNT(Vertices), 2, Indices, sizeof(Indices[0]), Vertices, sizeof(Vertices[0])); - + DrawIndexedPrimitiveUP(RHICmdList, PT_TriangleList, 0, UE_ARRAY_COUNT(Vertices), 2, Indices, sizeof(Indices[0]), Vertices, sizeof(Vertices[0])); // Resolve render target. RHICmdList.CopyToResolveTarget( OutputRenderTargetResource->GetRenderTargetTexture(), @@ -102,16 +101,16 @@ void USketchComponent::DrawIndexedPrimitiveUP( { const uint32 NumIndices = GetVertexCountForPrimitiveCount( NumPrimitives, PrimitiveType ); - FRHIResourceCreateInfo CreateInfo; - FVertexBufferRHIRef VertexBufferRHI = RHICreateVertexBuffer(VertexDataStride * NumVertices, BUF_Volatile, CreateInfo); - void* VoidPtr = RHILockVertexBuffer(VertexBufferRHI, 0, VertexDataStride * NumVertices, RLM_WriteOnly); + FRHIResourceCreateInfo CreateInfo(TEXT("FRHIResourceCreateInfo")); + FBufferRHIRef VertexBufferRHI = RHICreateVertexBuffer(VertexDataStride * NumVertices, BUF_Volatile, CreateInfo); + void* VoidPtr = RHILockBuffer(VertexBufferRHI, 0, VertexDataStride * NumVertices, RLM_WriteOnly); FPlatformMemory::Memcpy(VoidPtr, VertexData, VertexDataStride * NumVertices); - RHIUnlockVertexBuffer(VertexBufferRHI); + RHIUnlockBuffer(VertexBufferRHI); - FIndexBufferRHIRef IndexBufferRHI = RHICreateIndexBuffer(IndexDataStride, IndexDataStride * NumIndices, BUF_Volatile, CreateInfo); - void* VoidPtr2 = RHILockIndexBuffer(IndexBufferRHI, 0, IndexDataStride * NumIndices, RLM_WriteOnly); + FBufferRHIRef IndexBufferRHI = RHICreateIndexBuffer(IndexDataStride, IndexDataStride * NumIndices, BUF_Volatile, CreateInfo); + void* VoidPtr2 = RHILockBuffer(IndexBufferRHI, 0, IndexDataStride * NumIndices, RLM_WriteOnly); FPlatformMemory::Memcpy(VoidPtr2, IndexData, IndexDataStride * NumIndices); - RHIUnlockIndexBuffer(IndexBufferRHI); + RHIUnlockBuffer(IndexBufferRHI); RHICmdList.SetStreamSource(0, VertexBufferRHI, 0); RHICmdList.DrawIndexedPrimitive(IndexBufferRHI, MinVertexIndex, 0, NumVertices, 0, NumPrimitives, 1); diff --git a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchShader.cpp b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchShader.cpp index f6b9dfd..5a72084 100644 --- a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchShader.cpp +++ b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Private/SketchShader.cpp @@ -1,5 +1,5 @@ #include "SketchShader.h" - +#include FSketchShaderVS::FSketchShaderVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) @@ -12,13 +12,6 @@ void FSketchShaderVS::ModifyCompilationEnvironment(const FGlobalShaderPermutatio OutEnvironment.CompilerFlags.Add(CFLAG_StandardOptimization); } -bool FSketchShaderVS::Serialize(FArchive& Ar) -{ - return FGlobalShader::Serialize(Ar); -} - - - FSketchShaderPS::FSketchShaderPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) { @@ -30,11 +23,6 @@ void FSketchShaderPS::ModifyCompilationEnvironment(const FGlobalShaderPermutatio OutEnvironment.CompilerFlags.Add(CFLAG_StandardOptimization); } -bool FSketchShaderPS::Serialize(FArchive& Ar) -{ - return FGlobalShader::Serialize(Ar); -} - //////////////////////////////////////////////////////////////////////////////////////////////// IMPLEMENT_SHADER_TYPE(, FSketchShaderVS, TEXT("/Plugins/Sketch/Shaders/SketchShader.usf"), TEXT("MainVS"), SF_Vertex); IMPLEMENT_SHADER_TYPE(, FSketchShaderPS, TEXT("/Plugins/Sketch/Shaders/SketchShader.usf"), TEXT("MainPS"), SF_Pixel); diff --git a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Public/SketchShader.h b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Public/SketchShader.h index 138573c..07f1810 100644 --- a/UsfPluginProject/Plugins/Sketch/Source/Sketch/Public/SketchShader.h +++ b/UsfPluginProject/Plugins/Sketch/Source/Sketch/Public/SketchShader.h @@ -12,10 +12,9 @@ class FSketchShaderVS : public FGlobalShader FSketchShaderVS() {} explicit FSketchShaderVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer); - static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES2); } + static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1); } static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& PermutationParams) { return true; } static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment); - virtual bool Serialize(FArchive& Ar) override; }; @@ -27,16 +26,15 @@ class FSketchShaderPS : public FGlobalShader FSketchShaderPS() {} explicit FSketchShaderPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer); - static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES2); } + static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1); } static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& PermutationParams) { return true; } static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment); - virtual bool Serialize(FArchive& Ar) override; }; struct FSketchVertex { - FVector4 Position; - FVector2D UV; + FVector4f Position; + FVector2f UV; }; class FSketchVertexDeclaration : public FRenderResource diff --git a/UsfPluginProject/UsfPluginProject.uproject b/UsfPluginProject/UsfPluginProject.uproject index fcfe991..a208c98 100644 --- a/UsfPluginProject/UsfPluginProject.uproject +++ b/UsfPluginProject/UsfPluginProject.uproject @@ -1,6 +1,6 @@ { "FileVersion": 3, - "EngineAssociation": "4.22", + "EngineAssociation": "5.0", "Category": "", "Description": "", "Modules": [ diff --git a/UsfProject/Source/ShaderModule/ShaderModule.cpp b/UsfProject/Source/ShaderModule/ShaderModule.cpp index 8b7f4c0..da5d87a 100644 --- a/UsfProject/Source/ShaderModule/ShaderModule.cpp +++ b/UsfProject/Source/ShaderModule/ShaderModule.cpp @@ -5,7 +5,7 @@ void FShaderModule::StartupModule() { -#if (ENGINE_MINOR_VERSION >= 21) +#if (ENGINE_MINOR_VERSION >= 21 || ENGINE_MAJOR_VERSION >= 5) FString ShaderDirectory = FPaths::Combine(FPaths::ProjectDir(), TEXT("Shader")); if(!AllShaderSourceDirectoryMappings().Contains("/Project")) AddShaderSourceDirectoryMapping("/Project", ShaderDirectory); diff --git a/UsfProject/Source/ShaderModule/SketchComponent.cpp b/UsfProject/Source/ShaderModule/SketchComponent.cpp index 7093e4a..7875ffe 100644 --- a/UsfProject/Source/ShaderModule/SketchComponent.cpp +++ b/UsfProject/Source/ShaderModule/SketchComponent.cpp @@ -1,6 +1,7 @@ #include "SketchComponent.h" #include "SketchShader.h" -#include "Classes/Engine/TextureRenderTarget2D.h" +#include "Engine/TextureRenderTarget2D.h" +#include "RHI.h" //#include "RHICommandList.h" // RHI module #include "RHIResources.h" @@ -58,18 +59,18 @@ void USketchComponent::ExecuteInRenderThread(FRHICommandListImmediate& RHICmdLis RHICmdList.ApplyCachedRenderTargets(PSOInitializer); PSOInitializer.PrimitiveType = PT_TriangleList; PSOInitializer.BoundShaderState.VertexDeclarationRHI = VertexDec.VertexDeclarationRHI; - PSOInitializer.BoundShaderState.VertexShaderRHI = GETSAFERHISHADER_VERTEX(*shaderVS); - PSOInitializer.BoundShaderState.PixelShaderRHI = GETSAFERHISHADER_PIXEL(*shaderPS); + PSOInitializer.BoundShaderState.VertexShaderRHI = shaderVS.GetVertexShader(); + PSOInitializer.BoundShaderState.PixelShaderRHI = shaderPS.GetPixelShader(); PSOInitializer.RasterizerState = TStaticRasterizerState::GetRHI(); PSOInitializer.BlendState = TStaticBlendState<>::GetRHI(); PSOInitializer.DepthStencilState = TStaticDepthStencilState::GetRHI(); - SetGraphicsPipelineState(RHICmdList, PSOInitializer); + SetGraphicsPipelineState(RHICmdList, PSOInitializer, 0); static const FSketchVertex Vertices[4] = { - { FVector4(-1.0f, 1.0f, 0.0f, 1.0f), FVector2D(0.0f, 0.0f)}, - { FVector4( 1.0f, 1.0f, 0.0f, 1.0f), FVector2D(1.0f, 0.0f)}, - { FVector4(-1.0f, -1.0f, 0.0f, 1.0f), FVector2D(0.0f, 1.0f)}, - { FVector4( 1.0f, -1.0f, 0.0f, 1.0f), FVector2D(1.0f, 1.0f)}, + { FVector4f(-1.0f, 1.0f, 0.0f, 1.0f), FVector2f(0.0f, 0.0f)}, + { FVector4f( 1.0f, 1.0f, 0.0f, 1.0f), FVector2f(1.0f, 0.0f)}, + { FVector4f(-1.0f, -1.0f, 0.0f, 1.0f), FVector2f(0.0f, 1.0f)}, + { FVector4f( 1.0f, -1.0f, 0.0f, 1.0f), FVector2f(1.0f, 1.0f)}, }; static const uint16 Indices[6] = @@ -78,7 +79,7 @@ void USketchComponent::ExecuteInRenderThread(FRHICommandListImmediate& RHICmdLis 2, 1, 3 }; - DrawIndexedPrimitiveUP(RHICmdList, PT_TriangleList, 0, ARRAY_COUNT(Vertices), 2, Indices, sizeof(Indices[0]), Vertices, sizeof(Vertices[0])); + DrawIndexedPrimitiveUP(RHICmdList, PT_TriangleList, 0, UE_ARRAY_COUNT(Vertices), 2, Indices, sizeof(Indices[0]), Vertices, sizeof(Vertices[0])); // Resolve render target. RHICmdList.CopyToResolveTarget( @@ -102,16 +103,16 @@ void USketchComponent::DrawIndexedPrimitiveUP( { const uint32 NumIndices = GetVertexCountForPrimitiveCount( NumPrimitives, PrimitiveType ); - FRHIResourceCreateInfo CreateInfo; - FVertexBufferRHIRef VertexBufferRHI = RHICreateVertexBuffer(VertexDataStride * NumVertices, BUF_Volatile, CreateInfo); - void* VoidPtr = RHILockVertexBuffer(VertexBufferRHI, 0, VertexDataStride * NumVertices, RLM_WriteOnly); + FRHIResourceCreateInfo CreateInfo(TEXT("FRHIResourceCreateInfo")); + FBufferRHIRef VertexBufferRHI = RHICreateVertexBuffer(VertexDataStride * NumVertices, BUF_Volatile, CreateInfo); + void* VoidPtr = RHILockBuffer(VertexBufferRHI, 0, VertexDataStride * NumVertices, RLM_WriteOnly); FPlatformMemory::Memcpy(VoidPtr, VertexData, VertexDataStride * NumVertices); - RHIUnlockVertexBuffer(VertexBufferRHI); + RHIUnlockBuffer(VertexBufferRHI); - FIndexBufferRHIRef IndexBufferRHI = RHICreateIndexBuffer(IndexDataStride, IndexDataStride * NumIndices, BUF_Volatile, CreateInfo); - void* VoidPtr2 = RHILockIndexBuffer(IndexBufferRHI, 0, IndexDataStride * NumIndices, RLM_WriteOnly); + FBufferRHIRef IndexBufferRHI = RHICreateIndexBuffer(IndexDataStride, IndexDataStride * NumIndices, BUF_Volatile, CreateInfo); + void* VoidPtr2 = RHILockBuffer(IndexBufferRHI, 0, IndexDataStride * NumIndices, RLM_WriteOnly); FPlatformMemory::Memcpy(VoidPtr2, IndexData, IndexDataStride * NumIndices); - RHIUnlockIndexBuffer(IndexBufferRHI); + RHIUnlockBuffer(IndexBufferRHI); RHICmdList.SetStreamSource(0, VertexBufferRHI, 0); RHICmdList.DrawIndexedPrimitive(IndexBufferRHI, MinVertexIndex, 0, NumVertices, 0, NumPrimitives, 1); diff --git a/UsfProject/Source/ShaderModule/SketchShader.cpp b/UsfProject/Source/ShaderModule/SketchShader.cpp index 0b57781..2763a2a 100644 --- a/UsfProject/Source/ShaderModule/SketchShader.cpp +++ b/UsfProject/Source/ShaderModule/SketchShader.cpp @@ -1,4 +1,5 @@ #include "SketchShader.h" +#include FSketchShaderVS::FSketchShaderVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) @@ -12,13 +13,6 @@ void FSketchShaderVS::ModifyCompilationEnvironment(const FGlobalShaderPermutatio OutEnvironment.CompilerFlags.Add(CFLAG_StandardOptimization); } -bool FSketchShaderVS::Serialize(FArchive& Ar) -{ - return FGlobalShader::Serialize(Ar); -} - - - FSketchShaderPS::FSketchShaderPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) { @@ -30,11 +24,6 @@ void FSketchShaderPS::ModifyCompilationEnvironment(const FGlobalShaderPermutatio OutEnvironment.CompilerFlags.Add(CFLAG_StandardOptimization); } -bool FSketchShaderPS::Serialize(FArchive& Ar) -{ - return FGlobalShader::Serialize(Ar); -} - //////////////////////////////////////////////////////////////////////////////////////////////// IMPLEMENT_SHADER_TYPE(, FSketchShaderVS, TEXT("/Project/SketchShader.usf"), TEXT("MainVS"), SF_Vertex); IMPLEMENT_SHADER_TYPE(, FSketchShaderPS, TEXT("/Project/SketchShader.usf"), TEXT("MainPS"), SF_Pixel); diff --git a/UsfProject/Source/ShaderModule/SketchShader.h b/UsfProject/Source/ShaderModule/SketchShader.h index c5cb2a6..07f1810 100644 --- a/UsfProject/Source/ShaderModule/SketchShader.h +++ b/UsfProject/Source/ShaderModule/SketchShader.h @@ -12,11 +12,9 @@ class FSketchShaderVS : public FGlobalShader FSketchShaderVS() {} explicit FSketchShaderVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer); - static bool ShouldCache(EShaderPlatform Platform) { return true; } - //static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES2); } + static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1); } static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& PermutationParams) { return true; } static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment); - virtual bool Serialize(FArchive& Ar) override; }; @@ -28,17 +26,15 @@ class FSketchShaderPS : public FGlobalShader FSketchShaderPS() {} explicit FSketchShaderPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer); - static bool ShouldCache(EShaderPlatform Platform) { return true; } - //static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES2); } + static bool ShouldCache(EShaderPlatform Platform) { return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1); } static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& PermutationParams) { return true; } static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment); - virtual bool Serialize(FArchive& Ar) override; }; struct FSketchVertex { - FVector4 Position; - FVector2D UV; + FVector4f Position; + FVector2f UV; }; class FSketchVertexDeclaration : public FRenderResource diff --git a/UsfProject/UsfProject.uproject b/UsfProject/UsfProject.uproject index 4f7e6bf..8eb4fd6 100644 --- a/UsfProject/UsfProject.uproject +++ b/UsfProject/UsfProject.uproject @@ -1,6 +1,6 @@ { "FileVersion": 3, - "EngineAssociation": "4.22", + "EngineAssociation": "5.0", "Category": "", "Description": "", "Modules": [