Skip to content

Commit

Permalink
Some fixes for trigger / special textures
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Jan 8, 2024
1 parent 88254f7 commit 7d9966f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 31 deletions.
Binary file modified resources/pictures/aaatrigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 7 additions & 30 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,36 +925,13 @@ int BspRenderer::refreshModel(int modelIdx, bool refreshClipnodes, bool noTriang
verts[e].b = 1.0f;
verts[e].a = 1.0f;

// texture coords
float tw = 1.0f / (float)texWidth;
float th = 1.0f / (float)texHeight;
float fU = dotProduct(texinfo.vS, vert) + texinfo.shiftS;
float fV = dotProduct(texinfo.vT, vert) + texinfo.shiftT;
if (!isSpecial)
{
verts[e].u = fU * tw;
verts[e].v = fV * th;
}
else
{
vec3 xv, yv;
BSPPLANE& plane = map->planes[face.iPlane];
int bestplane = TextureAxisFromPlane(plane, xv, yv);

vec3 vS = AxisFromTextureAngle(0.0, true, bestplane);
vec3 vT = AxisFromTextureAngle(0.0, false, bestplane);

vS = vS.normalize(1.0f / (1.0f / texinfo.vS.length()));
vT = vT.normalize(1.0f / (1.0f / texinfo.vS.length()));

tw = 1.0f / (float)64;
th = 1.0f / (float)64;
fU = dotProduct(vS, vert);
fV = dotProduct(vT, vert);

verts[e].u = fU * tw;
verts[e].v = fV * th;
}
// texture coords
float tw = 1.0f / (float)(isSpecial ? 64 : texWidth);
float th = 1.0f / (float)(isSpecial ? 64 : texHeight);
float fU = dotProduct(isSpecial ? texinfo.vS.normalize(1.0f): texinfo.vS, vert) + (texinfo.shiftS);
float fV = dotProduct(isSpecial ? texinfo.vT.normalize(1.0f) : texinfo.vT, vert) + (texinfo.shiftT);
verts[e].u = fU * tw;
verts[e].v = fV * th;
// lightmap texture coords
if (hasLighting && lmap)
{
Expand Down
4 changes: 3 additions & 1 deletion src/editor/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ int CreateBspModelCommand::getDefaultTextureIdx()
BSPMIPTEX& tex = *((BSPMIPTEX*)(map->textures + texOffset));
if (tex.szName[0] != '\0' && strcasecmp(tex.szName, "aaatrigger") == 0)
{
tex.nWidth = aaatriggerTex->width;
tex.nHeight = aaatriggerTex->height;
print_log(get_localized_string(LANG_0295));
return i;
}
Expand All @@ -488,7 +490,7 @@ int CreateBspModelCommand::addDefaultTexture()
Bsp* map = getBsp();
if (!map)
return -1;
int aaatriggerIdx = map->add_texture("aaatrigger", missingTex->data, missingTex->width, missingTex->height);
int aaatriggerIdx = map->add_texture("aaatrigger", aaatriggerTex->data, aaatriggerTex->width, aaatriggerTex->height);

return aaatriggerIdx;
}
Expand Down
5 changes: 5 additions & 0 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Texture* blueTex = NULL;
Texture* missingTex = NULL;
Texture* missingTex_rgba = NULL;
Texture* aaatriggerTex_rgba = NULL;
Texture* aaatriggerTex = NULL;
Texture* skyTex_rgba = NULL;
Texture* clipTex_rgba = NULL;

Expand Down Expand Up @@ -199,6 +200,10 @@ Renderer::Renderer()
aaatriggerTex_rgba = new Texture(w, h, img_dat, "aaatrigger", true);
aaatriggerTex_rgba->upload();

lodepng_decode24_file(&img_dat, &w, &h, "./pictures/aaatrigger.png");
aaatriggerTex = new Texture(w, h, img_dat, "aaatrigger");
aaatriggerTex->upload();

lodepng_decode32_file(&img_dat, &w, &h, "./pictures/sky.png");
skyTex_rgba = new Texture(w, h, img_dat, "sky", true);
skyTex_rgba->upload();
Expand Down
1 change: 1 addition & 0 deletions src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern Texture* blueTex;
extern Texture* missingTex;
extern Texture* missingTex_rgba;
extern Texture* aaatriggerTex_rgba;
extern Texture* aaatriggerTex;
extern Texture* skyTex_rgba;
extern Texture* clipTex_rgba;

Expand Down

0 comments on commit 7d9966f

Please sign in to comment.