Skip to content

Commit

Permalink
Render update for transparent objects
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 5, 2023
1 parent 495d5b7 commit 9e7c7e8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 84 deletions.
85 changes: 35 additions & 50 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,17 @@ void BspRenderer::loadTextures()

if (path.empty())
{
logf(get_localized_string(LANG_0268),wadNames[i]);
logf(get_localized_string(LANG_0268), wadNames[i]);
continue;
}

logf(get_localized_string(LANG_0269),path);
logf(get_localized_string(LANG_0269), path);
Wad* wad = new Wad(path);
if (wad->readInfo())
wads.push_back(wad);
else
{
logf(get_localized_string(LANG_0270),path);
logf(get_localized_string(LANG_0270), path);
delete wad;
}
}
Expand Down Expand Up @@ -429,11 +429,11 @@ void BspRenderer::loadTextures()
}

if (wadTexCount)
logf(get_localized_string(LANG_0271),wadTexCount);
logf(get_localized_string(LANG_0271), wadTexCount);
if (embedCount)
logf(get_localized_string(LANG_0272),embedCount);
logf(get_localized_string(LANG_0272), embedCount);
if (missingCount)
logf(get_localized_string(LANG_0273),missingCount);
logf(get_localized_string(LANG_0273), missingCount);
}

void BspRenderer::reload()
Expand Down Expand Up @@ -593,7 +593,7 @@ void BspRenderer::loadLightmaps()

if (!atlases[atlasId]->insert(info.w, info.h, info.x[s], info.y[s]))
{
logf(get_localized_string(LANG_0275),info.w,info.h,LIGHTMAP_ATLAS_SIZE,LIGHTMAP_ATLAS_SIZE);
logf(get_localized_string(LANG_0275), info.w, info.h, LIGHTMAP_ATLAS_SIZE, LIGHTMAP_ATLAS_SIZE);
continue;
}
}
Expand Down Expand Up @@ -639,7 +639,7 @@ void BspRenderer::loadLightmaps()
numLightmapAtlases = atlasTextures.size();

//lodepng_encode24_file("atlas.png", atlasTextures[0]->data, LIGHTMAP_ATLAS_SIZE, LIGHTMAP_ATLAS_SIZE);
logf(get_localized_string(LANG_0276),lightmapCount,atlases.size());
logf(get_localized_string(LANG_0276), lightmapCount, atlases.size());

lightmapsGenerated = true;
}
Expand Down Expand Up @@ -672,7 +672,7 @@ void BspRenderer::updateLightmapInfos()
lightmaps = newLightmaps;
numRenderLightmapInfos = map->faceCount;

logf(get_localized_string(LANG_0278),addedFaces);
logf(get_localized_string(LANG_0278), addedFaces);
}

void BspRenderer::preRenderFaces()
Expand Down Expand Up @@ -1444,11 +1444,11 @@ void BspRenderer::generateClipnodeBufferForHull(int modelIdx, int hullIdx)

cVert* output = new cVert[allVerts.size()];
if (allVerts.size())
std::copy(allVerts.begin(),allVerts.end(), output);
std::copy(allVerts.begin(), allVerts.end(), output);

cVert* wireOutput = new cVert[wireframeVerts.size()];
if (wireframeVerts.size())
std::copy(wireframeVerts.begin(), wireframeVerts.end(), wireOutput);
std::copy(wireframeVerts.begin(), wireframeVerts.end(), wireOutput);

renderClip.clipnodeBuffer[hullIdx] = new VertexBuffer(colorShader, COLOR_4B | POS_3F, output, (GLsizei)allVerts.size(), GL_TRIANGLES);
renderClip.clipnodeBuffer[hullIdx]->ownData = true;
Expand Down Expand Up @@ -2012,7 +2012,7 @@ void BspRenderer::delayLoadData()
}

clipnodesLoaded = true;
logf(get_localized_string(LANG_0286),clipnodeLeafCount);
logf(get_localized_string(LANG_0286), clipnodeLeafCount);
updateClipnodeOpacity((g_render_flags & RENDER_TRANSPARENT) ? 128 : 255);
}
}
Expand Down Expand Up @@ -2122,7 +2122,7 @@ unsigned int BspRenderer::getFaceTextureId(int faceIdx)
}


void BspRenderer::render(std::vector<int> highlightEnts, bool highlightAlwaysOnTop, int clipnodeHull)
void BspRenderer::render(std::vector<int> highlightEnts, bool modelVertsDraw, int clipnodeHull)
{
ShaderProgram* activeShader; vec3 renderOffset;
mapOffset = map->ents.size() ? map->ents[0]->getOrigin() : vec3();
Expand All @@ -2135,34 +2135,14 @@ void BspRenderer::render(std::vector<int> highlightEnts, bool highlightAlwaysOnT
activeShader->modelMat->translate(renderOffset.x, renderOffset.y, renderOffset.z);
activeShader->updateMatrixes();

// draw highlighted ent first so other ent edges don't overlap the highlighted edges
if (highlightEnts.size() && !highlightAlwaysOnTop)
{
activeShader->bind();

for (int highlightEnt : highlightEnts)
{
if (highlightEnt > 0 && renderEnts[highlightEnt].modelIdx >= 0 && renderEnts[highlightEnt].modelIdx < map->modelCount)
{
if (renderEnts[highlightEnt].hide)
continue;
activeShader->pushMatrix(MAT_MODEL);
*activeShader->modelMat = renderEnts[highlightEnt].modelMatAngles;
activeShader->modelMat->translate(renderOffset.x, renderOffset.y, renderOffset.z);
activeShader->updateMatrixes();

drawModel(&renderEnts[highlightEnt], false, true, true);
drawModel(&renderEnts[highlightEnt], true, true, true);

activeShader->popMatrix(MAT_MODEL);
}
}
}

for (int pass = 0; pass < 2; pass++)
{
bool drawTransparentFaces = pass == 1;

if (drawTransparentFaces)
{
//glDepthMask(GL_FALSE);
//glDepthFunc(GL_LESS);
}
if (!renderEnts[0].hide)
drawModel(0, drawTransparentFaces, false, false);

Expand All @@ -2182,7 +2162,11 @@ void BspRenderer::render(std::vector<int> highlightEnts, bool highlightAlwaysOnT
activeShader->popMatrix(MAT_MODEL);
}
}

if (drawTransparentFaces)
{
//glDepthMask(GL_TRUE);
//glDepthFunc(GL_LESS);
}
if ((g_render_flags & RENDER_POINT_ENTS) && pass == 0)
{
drawPointEntities(highlightEnts);
Expand Down Expand Up @@ -2237,7 +2221,9 @@ void BspRenderer::render(std::vector<int> highlightEnts, bool highlightAlwaysOnT
}
}

if (highlightEnts.size() && highlightAlwaysOnTop)
glDepthMask(GL_FALSE);
glDepthFunc(GL_ALWAYS);
if (highlightEnts.size())
{
activeShader->bind();

Expand All @@ -2251,17 +2237,18 @@ void BspRenderer::render(std::vector<int> highlightEnts, bool highlightAlwaysOnT
*activeShader->modelMat = renderEnts[highlightEnt].modelMatAngles;
activeShader->modelMat->translate(renderOffset.x, renderOffset.y, renderOffset.z);
activeShader->updateMatrixes();

glDisable(GL_DEPTH_TEST);
if (modelVertsDraw)
glDisable(GL_CULL_FACE);
drawModel(&renderEnts[highlightEnt], false, true, true);
drawModel(&renderEnts[highlightEnt], true, true, true);
glEnable(GL_DEPTH_TEST);

if (modelVertsDraw)
glEnable(GL_CULL_FACE);
activeShader->popMatrix(MAT_MODEL);
}
}
}

glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
delayLoadData();
}

Expand Down Expand Up @@ -2422,9 +2409,7 @@ void BspRenderer::drawModel(RenderEnt* ent, bool transparent, bool highlight, bo
*activeShader->modelMat = ent->modelMatOrigin;
activeShader->modelMat->translate(renderOffset.x, renderOffset.y, renderOffset.z);
activeShader->updateMatrixes();
glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_SRC_COLOR);
rgroup.buffer->drawFull();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
activeShader->popMatrix(MAT_MODEL);
}
}
Expand Down Expand Up @@ -2928,7 +2913,7 @@ void BspRenderer::pushModelUndoState(const std::string& actionDesc, unsigned int
differences[i] = true;
if (g_verbose)
{
logf(get_localized_string(LANG_0291),g_lump_names[i],newLumps.lumps[i].size(),undoLumpState.lumps[i].size());
logf(get_localized_string(LANG_0291), g_lump_names[i], newLumps.lumps[i].size(), undoLumpState.lumps[i].size());
}
targetLumps = targetLumps | (1 << i);
}
Expand Down Expand Up @@ -2984,7 +2969,7 @@ void BspRenderer::undo()
Command* undoCommand = undoHistory[undoHistory.size() - 1];
if (!undoCommand->allowedDuringLoad && g_app->isLoading)
{
logf(get_localized_string(LANG_0293),undoCommand->desc);
logf(get_localized_string(LANG_0293), undoCommand->desc);
return;
}

Expand All @@ -3004,7 +2989,7 @@ void BspRenderer::redo()
Command* redoCommand = redoHistory[redoHistory.size() - 1];
if (!redoCommand->allowedDuringLoad && g_app->isLoading)
{
logf(get_localized_string(LANG_0294),redoCommand->desc);
logf(get_localized_string(LANG_0294), redoCommand->desc);
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void Gui::init()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
//glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
return (void*)(uint64_t)tex;
};
Expand Down
51 changes: 33 additions & 18 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ void Renderer::renderLoop()
logf(get_localized_string(LANG_0904),value);
}

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

{
line_verts = new cVert[2];
lineBuf = new VertexBuffer(colorShader, COLOR_4B | POS_3F, line_verts, 2, GL_LINES);
Expand Down Expand Up @@ -303,9 +297,24 @@ void Renderer::renderLoop()

glfwPollEvents();

/*tempmodel->AdvanceFrame(curTime - oldTime);
tempmodel->UpdateModelMeshList();*/
if (SelectedMap && SelectedMap->is_mdl_model)
glClearColor(0.25, 0.25, 0.25, 1.0);
else
glClearColor(0.0, 0.0, 0.0, 1.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.05f);

glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

{//Update keyboard / mouse state
oldLeftMouse = curLeftMouse;
Expand Down Expand Up @@ -408,10 +417,6 @@ void Renderer::renderLoop()
matmodel.rotateZ((float)oldTime);
matmodel.rotateX((float)curTime);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if (SelectedMap && SelectedMap->is_mdl_model)
glClearColor(0.25, 0.25, 0.25, 1.0);
setupView();

drawEntConnections();
Expand Down Expand Up @@ -558,13 +563,13 @@ void Renderer::renderLoop()
}
}

glDepthMask(GL_FALSE);
glDepthFunc(GL_ALWAYS);
if (entConnectionPoints && (g_render_flags & RENDER_ENT_CONNECTIONS))
{
matmodel.loadIdentity();
colorShader->updateMatrixes();
glDisable(GL_DEPTH_TEST);
entConnectionPoints->drawFull();
glEnable(GL_DEPTH_TEST);
}

if (entIdx <= 0)
Expand All @@ -574,11 +579,14 @@ void Renderer::renderLoop()
SelectedMap->selectModelEnt();
}
}

if (modelIdx > 0 && pickMode == PICK_OBJECT)
{
if (transformTarget == TRANSFORM_VERTEX && isTransformableSolid)
{
glDisable(GL_CULL_FACE);
drawModelVerts();
glEnable(GL_CULL_FACE);
}
if (transformTarget == TRANSFORM_ORIGIN)
{
Expand All @@ -594,6 +602,9 @@ void Renderer::renderLoop()
}
}

glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

vec3 forward, right, up;
makeVectors(cameraAngles, forward, right, up);
if (!hideGui)
Expand Down Expand Up @@ -933,30 +944,34 @@ void Renderer::drawTransformAxes()
{
if (SelectedMap->ents[pickInfo.selectedEnts[0]]->getBspModelIdx() > 0)
{
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glDepthFunc(GL_ALWAYS);
updateDragAxes();
vec3 ori = scaleAxes.origin;
matmodel.translate(ori.x, ori.z, -ori.y);
colorShader->updateMatrixes();
glDisable(GL_CULL_FACE);
scaleAxes.buffer->drawFull();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
}
}
if (SelectedMap && pickInfo.selectedEnts.size() > 0 && transformMode == TRANSFORM_MODE_MOVE)
{
if (transformTarget != TRANSFORM_VERTEX || (anyVertSelected || anyEdgeSelected))
{
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glDepthFunc(GL_ALWAYS);
updateDragAxes();
vec3 ori = moveAxes.origin;
matmodel.translate(ori.x, ori.z, -ori.y);
colorShader->updateMatrixes();
glDisable(GL_CULL_FACE);
moveAxes.buffer->drawFull();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
}
}
dragDelta = vec3();
Expand Down
12 changes: 0 additions & 12 deletions src/gl/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,10 @@ void Texture::upload(int _format, bool lightmap)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}

//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
// TODO: load mipmaps from BSP/WAD
/*if (_format == GL_RGB)
{
lodepng_encode24_file((GetWorkDir() + std::string(texName) + "_24bit.png").c_str(), data, width, height);
}
else
{
lodepng_encode32_file((GetWorkDir() + std::string(texName) + "_32bit.png").c_str(), data, width, height);
}*/
glTexImage2D(GL_TEXTURE_2D, 0, _format, width, height, 0, _format, GL_UNSIGNED_BYTE, data);

if (g_settings.verboseLogs)
logf(get_localized_string(LANG_0971),texName,width,height);
//glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB, width, height);
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, data);

uploaded = true;
}
Expand Down
8 changes: 6 additions & 2 deletions src/gl/shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ namespace Shaders
" return;\n"
" }\n"
" }\n"
" if (fcolor.g == 6.0)\n"
*/" if (fcolor.g == 6.0)\n"
" {\n"
" color.rgb = color.rgb * fcolor.a;\n"
" fcolor.g = 1.0;\n"
" }\n"*/
" }\n"
" else if (fcolor.g > 1.0)\n"
" {\n"
" fcolor.g = 1.0;\n"
" }\n"
" vec3 lightmap = texture2D(sLightmapTex0, fLightmapTex0.xy).rgb * fLightmapTex0.z;\n"
" lightmap += texture2D(sLightmapTex1, fLightmapTex1.xy).rgb * fLightmapTex1.z;\n"
" lightmap += texture2D(sLightmapTex2, fLightmapTex2.xy).rgb * fLightmapTex2.z;\n"
Expand Down
Loading

0 comments on commit 9e7c7e8

Please sign in to comment.