From e24c755a17eb442e14efe9c91371cf69e9f9f7e6 Mon Sep 17 00:00:00 2001 From: Leon Buckel Date: Sun, 11 Dec 2022 00:52:23 +0100 Subject: [PATCH] Fix UV coords not changed if the first modifier is not a UTexModifier --- OpenGLDrv/Src/OpenGLMaterial.cpp | 103 ++++++++++-------------- OpenGLDrv/Src/OpenGLRenderDevice.cpp | 22 ++--- OpenGLDrv/Src/OpenGLRenderInterface.cpp | 2 +- OpenGLDrv/Src/OpenGLRenderInterface.h | 8 +- OpenGLDrv/Src/OpenGLResource.cpp | 14 ++-- 5 files changed, 66 insertions(+), 83 deletions(-) diff --git a/OpenGLDrv/Src/OpenGLMaterial.cpp b/OpenGLDrv/Src/OpenGLMaterial.cpp index dad3292d..36e5d3ba 100644 --- a/OpenGLDrv/Src/OpenGLMaterial.cpp +++ b/OpenGLDrv/Src/OpenGLMaterial.cpp @@ -2,78 +2,61 @@ #include "OpenGLRenderDevice.h" #include "OpenGLResource.h" -UMaterial* FOpenGLRenderInterface::RemoveModifiers(UMaterial* InMaterial, FModifierInfo& ModifierInfo){ - UModifier* Modifier = Cast(InMaterial); +UMaterial* FOpenGLRenderInterface::RemoveModifiers(UMaterial* Material, FModifierInfo& ModifierInfo){ + checkSlow(Material); - if(!Modifier) - return InMaterial; + while(Material->IsA()){ + if(Material->IsA()){ + ModifierInfo.bModifiesTextureCoordinates = true; - UModifier* FirstModifier = Cast(Modifier); - UMaterial* Material = NULL; + UTexModifier* TexModifier = static_cast(Material); + FMatrix* Matrix = TexModifier->GetMatrix(GEngineTime); - while(Modifier){ - Material = Modifier->Material; - Modifier = Cast(Material); - } - - // Collect modifiers - - if(Material){ - Modifier = FirstModifier; - - // Apply modifiers - while(Modifier != Material){ - if(Modifier->IsA()){ - UTexModifier* TexModifier = static_cast(Modifier); - - FMatrix* Matrix = TexModifier->GetMatrix(GEngineTime); - - if(Matrix && *Matrix != FMatrix::Identity){ - ModifierInfo.TexMatrix *= *Matrix; - ModifierInfo.bUseTexMatrix = 1; - } - - if(TexModifier->TexCoordSource != TCS_NoChange){ - ModifierInfo.bTexCoordProjected = TexModifier->TexCoordProjected; - ModifierInfo.TexCoordSrc = static_cast(TexModifier->TexCoordSource); - ModifierInfo.TexCoordCount = static_cast(TexModifier->TexCoordCount); - } + if(Matrix && *Matrix != FMatrix::Identity){ + ModifierInfo.TexMatrix *= *Matrix; + ModifierInfo.bUseTexMatrix = 1; + } - ModifierInfo.TexUClamp = static_cast(TexModifier->UClampMode); - ModifierInfo.TexVClamp = static_cast(TexModifier->VClampMode); - }else if(Modifier->IsA()){ - UFinalBlend* FinalBlend = static_cast(Modifier); + if(TexModifier->TexCoordSource != TCS_NoChange){ + ModifierInfo.bTexCoordProjected = TexModifier->TexCoordProjected; + ModifierInfo.TexCoordSrc = static_cast(TexModifier->TexCoordSource); + ModifierInfo.TexCoordCount = static_cast(TexModifier->TexCoordCount); + } - if(!ModifyFramebufferBlending){ - ModifyFramebufferBlending = true; - SetFramebufferBlending(static_cast(FinalBlend->FrameBufferBlending)); - CurrentState->bZTest = FinalBlend->ZTest != 0; - CurrentState->bZWrite = FinalBlend->ZWrite != 0; - } + ModifierInfo.TexUClamp = static_cast(TexModifier->UClampMode); + ModifierInfo.TexVClamp = static_cast(TexModifier->VClampMode); + }else if(Material->IsA()){ + UFinalBlend* FinalBlend = static_cast(Material); - if(FinalBlend->TwoSided) - CurrentState->CullMode = CM_None; + if(!ModifyFramebufferBlending){ + ModifyFramebufferBlending = true; + SetFramebufferBlending(static_cast(FinalBlend->FrameBufferBlending)); + CurrentState->bZTest = FinalBlend->ZTest != 0; + CurrentState->bZWrite = FinalBlend->ZWrite != 0; + } - if(FinalBlend->AlphaTest){ - CurrentState->AlphaRef = FinalBlend->AlphaRef / 255.0f; - ++CurrentState->UniformRevision; - } - }else if(Modifier->IsA()){ - UColorModifier* ColorModifier = static_cast(Modifier); + if(FinalBlend->TwoSided) + CurrentState->CullMode = CM_None; - CurrentState->ModifyColor = 1; - CurrentState->ColorFactor = ColorModifier->Color; + if(FinalBlend->AlphaTest){ + CurrentState->AlphaRef = FinalBlend->AlphaRef / 255.0f; ++CurrentState->UniformRevision; + } + }else if(Material->IsA()){ + UColorModifier* ColorModifier = static_cast(Material); - if(ColorModifier->RenderTwoSided) - CurrentState->CullMode = CM_None; + CurrentState->ModifyColor = 1; + CurrentState->ColorFactor = ColorModifier->Color; + ++CurrentState->UniformRevision; - if(!ModifyFramebufferBlending && ColorModifier->AlphaBlend) - SetFramebufferBlending(FB_AlphaBlend); - } + if(ColorModifier->RenderTwoSided) + CurrentState->CullMode = CM_None; - Modifier = static_cast(Modifier->Material); + if(!ModifyFramebufferBlending && ColorModifier->AlphaBlend) + SetFramebufferBlending(FB_AlphaBlend); } + + Material = static_cast(Material)->Material; } return Material; @@ -915,7 +898,7 @@ bool FOpenGLRenderInterface::HandleShaderMaterial(UShader* Shader, FShaderGenera } if(Shader->Opacity){ - if((HaveDiffuse && Shader->Opacity != Shader->Diffuse) || (HaveSelfIllumination && Shader->Opacity != Shader->SelfIllumination) || !HaveDiffuse && !HaveSelfIllumination){ + if((HaveDiffuse && Shader->Opacity != Shader->Diffuse) || (HaveSelfIllumination && Shader->Opacity != Shader->SelfIllumination) || (!HaveDiffuse && !HaveSelfIllumination)){ ShaderGenerator.AddColorOp(CA_R0, CA_R0, COP_Arg1, CC_RGB, ShaderGenerator.PushTempRegister()); if(!HandleSimpleMaterial(Shader->Opacity, ShaderGenerator, &ModifierInfo)) diff --git a/OpenGLDrv/Src/OpenGLRenderDevice.cpp b/OpenGLDrv/Src/OpenGLRenderDevice.cpp index 0c34d3b4..5a3ddcbd 100644 --- a/OpenGLDrv/Src/OpenGLRenderDevice.cpp +++ b/OpenGLDrv/Src/OpenGLRenderDevice.cpp @@ -555,17 +555,17 @@ UBOOL UOpenGLRenderDevice::SetRes(UViewport* Viewport, INT NewX, INT NewY, UBOOL // Initialize shaders ErrorShader.Compile("#ifdef VERTEX_SHADER\n" - "void main(void){\n" - "\tgl_Position = LocalToScreen * vec4(InPosition.xyz, 1.0);\n" - "}\n" - "#elif defined(FRAGMENT_SHADER)\n" - "void main(void){\n" - "\tFragColor = vec4(1.0, 0.0, 1.0, 1.0);\n" - "}\n" - "#else\n" - "#error Shader type not implemented\n" - "#endif\n", - "ERRORSHADER"); + "void main(void){\n" + "\tgl_Position = LocalToScreen * vec4(InPosition.xyz, 1.0);\n" + "}\n" + "#elif defined(FRAGMENT_SHADER)\n" + "void main(void){\n" + "\tFragColor = vec4(1.0, 0.0, 1.0, 1.0);\n" + "}\n" + "#else\n" + "#error Shader type not implemented\n" + "#endif\n", + "ERRORSHADER"); check(ErrorShader.IsValid()); /* diff --git a/OpenGLDrv/Src/OpenGLRenderInterface.cpp b/OpenGLDrv/Src/OpenGLRenderInterface.cpp index 818f6a2e..aa943293 100644 --- a/OpenGLDrv/Src/OpenGLRenderInterface.cpp +++ b/OpenGLDrv/Src/OpenGLRenderInterface.cpp @@ -1130,7 +1130,7 @@ void FOpenGLRenderInterface::SetMaterial(UMaterial* Material, FString* ErrorStri Shader = RenDev->GetShaderForMaterial(Material); if(Material->IsA()) - Result = (Modifier && Modifier->IsA()) ? SetSimpleMaterial(Material, ModifierInfo) : SetBitmapMaterial(static_cast(Material)); + Result = ModifierInfo.bModifiesTextureCoordinates ? SetSimpleMaterial(Material, ModifierInfo) : SetBitmapMaterial(static_cast(Material)); else if(Material->IsA()) Result = SetShaderMaterial(static_cast(Material), ModifierInfo); else if(Material->IsA()) diff --git a/OpenGLDrv/Src/OpenGLRenderInterface.h b/OpenGLDrv/Src/OpenGLRenderInterface.h index d4d4e79e..2fd2690b 100644 --- a/OpenGLDrv/Src/OpenGLRenderInterface.h +++ b/OpenGLDrv/Src/OpenGLRenderInterface.h @@ -278,6 +278,7 @@ class FOpenGLRenderInterface : public FRenderInterface{ private: struct FModifierInfo{ FMatrix TexMatrix; + bool bModifiesTextureCoordinates; bool bUseTexMatrix; bool bTexCoordProjected; ETexCoordSrc TexCoordSrc; @@ -286,13 +287,14 @@ class FOpenGLRenderInterface : public FRenderInterface{ ETexClampModeOverride TexVClamp; FModifierInfo() : TexMatrix(FMatrix::Identity), - bUseTexMatrix(0), - bTexCoordProjected(0), + bModifiesTextureCoordinates(false), + bUseTexMatrix(false), + bTexCoordProjected(false), TexCoordSrc(TCS_Stream0), TexCoordCount(TCN_2DCoords){} }; - UMaterial* RemoveModifiers(UMaterial* InMaterial, FModifierInfo& ModifierInfo); + UMaterial* RemoveModifiers(UMaterial* Material, FModifierInfo& ModifierInfo); void GetShaderConstants(FSConstantsInfo* Info, FPlane* Constants, INT NumConstants); void SetTexture(FBaseTexture* Texture, INT TextureIndex, FLOAT UVScale = 1.0f, FLOAT BumpSize = 1.0f, FLOAT BumpLumaScale = 1.0f, FLOAT BumpLumaOffset = 0.0f); void SetBitmapTexture(UBitmapMaterial* Bitmap, INT TextureIndex, FLOAT UVScale = 1.0f, FLOAT BumpSize = 1.0f, FLOAT BumpLumaScale = 1.0f, FLOAT BumpLumaOffset = 0.0f); diff --git a/OpenGLDrv/Src/OpenGLResource.cpp b/OpenGLDrv/Src/OpenGLResource.cpp index 4cea0452..e6ec3947 100644 --- a/OpenGLDrv/Src/OpenGLResource.cpp +++ b/OpenGLDrv/Src/OpenGLResource.cpp @@ -219,14 +219,12 @@ void FOpenGLTexture::Cache(FBaseTexture* BaseTexture, bool bOwnDepthBuffer){ } } - if(bOwnDepthBuffer || IsMipTarget){ - if(IsMipTarget){ - DepthStencilAttachment = GL_NONE; // The FrameFX mip targets don't need a depth or stencil buffer - }else{ - RenDev->glCreateRenderbuffers(1, &DepthStencilAttachment); - RenDev->glNamedRenderbufferStorage(DepthStencilAttachment, GL_DEPTH24_STENCIL8, Width, Height); - HasSharedDepthStencil = false; - } + if(IsMipTarget){ + DepthStencilAttachment = GL_NONE; // The FrameFX mip targets don't need a depth or stencil buffer + }else if(bOwnDepthBuffer){ + RenDev->glCreateRenderbuffers(1, &DepthStencilAttachment); + RenDev->glNamedRenderbufferStorage(DepthStencilAttachment, GL_DEPTH24_STENCIL8, Width, Height); + HasSharedDepthStencil = false; }else{ checkSlow(RenDev->BackbufferDepthStencil); DepthStencilAttachment = RenDev->BackbufferDepthStencil;