Skip to content

Commit

Permalink
Fix UV coords not changed if the first modifier is not a UTexModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-bckl committed Dec 10, 2022
1 parent 5a676f9 commit e24c755
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 83 deletions.
103 changes: 43 additions & 60 deletions OpenGLDrv/Src/OpenGLMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,61 @@
#include "OpenGLRenderDevice.h"
#include "OpenGLResource.h"

UMaterial* FOpenGLRenderInterface::RemoveModifiers(UMaterial* InMaterial, FModifierInfo& ModifierInfo){
UModifier* Modifier = Cast<UModifier>(InMaterial);
UMaterial* FOpenGLRenderInterface::RemoveModifiers(UMaterial* Material, FModifierInfo& ModifierInfo){
checkSlow(Material);

if(!Modifier)
return InMaterial;
while(Material->IsA<UModifier>()){
if(Material->IsA<UTexModifier>()){
ModifierInfo.bModifiesTextureCoordinates = true;

UModifier* FirstModifier = Cast<UModifier>(Modifier);
UMaterial* Material = NULL;
UTexModifier* TexModifier = static_cast<UTexModifier*>(Material);
FMatrix* Matrix = TexModifier->GetMatrix(GEngineTime);

while(Modifier){
Material = Modifier->Material;
Modifier = Cast<UModifier>(Material);
}

// Collect modifiers

if(Material){
Modifier = FirstModifier;

// Apply modifiers
while(Modifier != Material){
if(Modifier->IsA<UTexModifier>()){
UTexModifier* TexModifier = static_cast<UTexModifier*>(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<ETexCoordSrc>(TexModifier->TexCoordSource);
ModifierInfo.TexCoordCount = static_cast<ETexCoordCount>(TexModifier->TexCoordCount);
}
if(Matrix && *Matrix != FMatrix::Identity){
ModifierInfo.TexMatrix *= *Matrix;
ModifierInfo.bUseTexMatrix = 1;
}

ModifierInfo.TexUClamp = static_cast<ETexClampModeOverride>(TexModifier->UClampMode);
ModifierInfo.TexVClamp = static_cast<ETexClampModeOverride>(TexModifier->VClampMode);
}else if(Modifier->IsA<UFinalBlend>()){
UFinalBlend* FinalBlend = static_cast<UFinalBlend*>(Modifier);
if(TexModifier->TexCoordSource != TCS_NoChange){
ModifierInfo.bTexCoordProjected = TexModifier->TexCoordProjected;
ModifierInfo.TexCoordSrc = static_cast<ETexCoordSrc>(TexModifier->TexCoordSource);
ModifierInfo.TexCoordCount = static_cast<ETexCoordCount>(TexModifier->TexCoordCount);
}

if(!ModifyFramebufferBlending){
ModifyFramebufferBlending = true;
SetFramebufferBlending(static_cast<EFrameBufferBlending>(FinalBlend->FrameBufferBlending));
CurrentState->bZTest = FinalBlend->ZTest != 0;
CurrentState->bZWrite = FinalBlend->ZWrite != 0;
}
ModifierInfo.TexUClamp = static_cast<ETexClampModeOverride>(TexModifier->UClampMode);
ModifierInfo.TexVClamp = static_cast<ETexClampModeOverride>(TexModifier->VClampMode);
}else if(Material->IsA<UFinalBlend>()){
UFinalBlend* FinalBlend = static_cast<UFinalBlend*>(Material);

if(FinalBlend->TwoSided)
CurrentState->CullMode = CM_None;
if(!ModifyFramebufferBlending){
ModifyFramebufferBlending = true;
SetFramebufferBlending(static_cast<EFrameBufferBlending>(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>()){
UColorModifier* ColorModifier = static_cast<UColorModifier*>(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>()){
UColorModifier* ColorModifier = static_cast<UColorModifier*>(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<UModifier*>(Modifier->Material);
if(!ModifyFramebufferBlending && ColorModifier->AlphaBlend)
SetFramebufferBlending(FB_AlphaBlend);
}

Material = static_cast<UModifier*>(Material)->Material;
}

return Material;
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 11 additions & 11 deletions OpenGLDrv/Src/OpenGLRenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

/*
Expand Down
2 changes: 1 addition & 1 deletion OpenGLDrv/Src/OpenGLRenderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ void FOpenGLRenderInterface::SetMaterial(UMaterial* Material, FString* ErrorStri
Shader = RenDev->GetShaderForMaterial(Material);

if(Material->IsA<UBitmapMaterial>())
Result = (Modifier && Modifier->IsA<UTexModifier>()) ? SetSimpleMaterial(Material, ModifierInfo) : SetBitmapMaterial(static_cast<UBitmapMaterial*>(Material));
Result = ModifierInfo.bModifiesTextureCoordinates ? SetSimpleMaterial(Material, ModifierInfo) : SetBitmapMaterial(static_cast<UBitmapMaterial*>(Material));
else if(Material->IsA<UShader>())
Result = SetShaderMaterial(static_cast<UShader*>(Material), ModifierInfo);
else if(Material->IsA<UCombiner>())
Expand Down
8 changes: 5 additions & 3 deletions OpenGLDrv/Src/OpenGLRenderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class FOpenGLRenderInterface : public FRenderInterface{
private:
struct FModifierInfo{
FMatrix TexMatrix;
bool bModifiesTextureCoordinates;
bool bUseTexMatrix;
bool bTexCoordProjected;
ETexCoordSrc TexCoordSrc;
Expand All @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions OpenGLDrv/Src/OpenGLResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e24c755

Please sign in to comment.