Skip to content

Commit

Permalink
Added an optional argument frameVar to shader:BindTexture/BindCubeMap…
Browse files Browse the repository at this point in the history
…/BindBumpMap
  • Loading branch information
devonium committed Jun 13, 2023
1 parent ea38290 commit 4a1ce81
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
30 changes: 25 additions & 5 deletions source/shaderlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ namespace ShaderLib
return 0;
}

void BindTexture(ShaderUData* u, int sampler, int paramindex, TextureBind::TextureType type, bool isStandardTexture = false)
void BindTexture(ShaderUData* u, int sampler, int paramindex, TextureBind::TextureType type, bool isStandardTexture = false, int frameVar = -1)
{
if (sampler > u->Shader->ActiveSamplers) { u->Shader->ActiveSamplers = sampler; }

for (int i = u->Shader->Binds.Count(); --i >= 0; )
{
TextureBind* bind = u->Shader->Binds.Element(i);
Expand All @@ -698,6 +698,8 @@ namespace ShaderLib
bind->Type = type;
bind->Sampler = sampler;
bind->IsStandardTexture = isStandardTexture;
bind->FrameVar = frameVar;

u->Shader->Binds.AddToTail(bind);
}

Expand All @@ -706,7 +708,13 @@ namespace ShaderLib
ShaderUData* u = GetUShader(LUA);
int sampler = LUA->CheckNumber(2);
int paramindex = LUA->CheckNumber(3);
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Texture);
int frameVar = -1;
if (LUA->IsType(4, GarrysMod::Lua::Type::NUMBER))
{
frameVar = LUA->GetNumber(4);
if (frameVar < 0 || frameVar > (u->Shader->GetNumParams() - 1)) { luau_error(LUA, "invalid frame var param"); }
}
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Texture, false, frameVar);
return 0;
}

Expand All @@ -724,7 +732,13 @@ namespace ShaderLib
ShaderUData* u = GetUShader(LUA);
int sampler = LUA->CheckNumber(2);
int paramindex = LUA->CheckNumber(3);
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Cubemap);
int frameVar = -1;
if (LUA->IsType(4, GarrysMod::Lua::Type::NUMBER))
{
frameVar = LUA->GetNumber(4);
if (frameVar < 0 || frameVar >(u->Shader->GetNumParams() - 1)) { luau_error(LUA, "invalid frame var param"); }
}
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Cubemap, false, frameVar);
return 0;
}

Expand All @@ -733,7 +747,13 @@ namespace ShaderLib
ShaderUData* u = GetUShader(LUA);
int sampler = LUA->CheckNumber(2);
int paramindex = LUA->CheckNumber(3);
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Bumpmap);
int frameVar = -1;
if (LUA->IsType(4, GarrysMod::Lua::Type::NUMBER))
{
frameVar = LUA->GetNumber(4);
if (frameVar < 0 || frameVar >(u->Shader->GetNumParams() - 1)) { luau_error(LUA, "invalid frame var param"); }
}
BindTexture(u, sampler, paramindex, TextureBind::TextureType::Bumpmap, false, frameVar);
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion source/shaderlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ namespace ShaderLib
TextureType Type = Texture;
bool IsStandardTexture = false;
bool IsValid = false;
int FrameVar = -1;
};

struct ShaderConstantF
Expand Down Expand Up @@ -597,7 +598,7 @@ namespace ShaderLib
}
else
{
BindTexture((Sampler_t)bind->Sampler, bind->ParamIndex, 0);
BindTexture((Sampler_t)bind->Sampler, bind->ParamIndex, bind->FrameVar);
}
}

Expand Down

0 comments on commit 4a1ce81

Please sign in to comment.