diff --git a/browedit/components/LubRenderer.cpp b/browedit/components/LubRenderer.cpp index c009dd1..82e81a9 100644 --- a/browedit/components/LubRenderer.cpp +++ b/browedit/components/LubRenderer.cpp @@ -69,9 +69,8 @@ void LubRenderer::render() modelMatrix = glm::rotate(modelMatrix, -glm::radians(lubEffect->rotate_angle.x), glm::vec3(1, 0, 0)); } - shader->setUniform(LubShader::Uniforms::modelMatrix, modelMatrix); shader->setUniform(LubShader::Uniforms::billboard_off, (bool)lubEffect->billboard_off); - shader->setUniform(LubShader::Uniforms::color, lubEffect->color); + shader->setUniform(LubShader::Uniforms::color, glm::vec4(lubEffect->color.r, lubEffect->color.g, lubEffect->color.b, 1.0f)); glBindBuffer(GL_ARRAY_BUFFER, 0); if (texture) @@ -87,9 +86,9 @@ void LubRenderer::render() p.position += (p.dir * lubEffect->speed + p.speed) * elapsedTime; p.life -= elapsedTime; p.speed += lubEffect->speed * lubEffect->gravity * glm::vec3(1, -1, 1) * elapsedTime; - + if (p.start_life > 1) { - if (p.life < p.start_life / 2) + if (p.life < glm::min(1.0f, p.start_life / 2.0f)) p.alpha -= elapsedTime; else p.alpha += elapsedTime; @@ -97,7 +96,7 @@ void LubRenderer::render() p.alpha = glm::clamp(p.alpha, 0.0f, 1.0f); } } - if(particles.size() > 0) + if (particles.size() > 0) particles.erase(std::remove_if(particles.begin(), particles.end(), [](const Particle& p) { return p.life < 0; }), particles.end()); emitTime -= elapsedTime; if (emitTime < 0 && particles.size() < lubEffect->maxcount) @@ -108,6 +107,7 @@ void LubRenderer::render() -lubEffect->radius.y + (rand() / (float)RAND_MAX) * (-lubEffect->radius.y + 2 * abs(lubEffect->radius.y) + lubEffect->radius.y), -lubEffect->radius.z + (rand() / (float)RAND_MAX) * (-lubEffect->radius.z + 2 * abs(lubEffect->radius.z) + lubEffect->radius.z) ); + p.speed = glm::vec3(0); p.dir = glm::vec3( lubEffect->dir1.x + (rand() / (float)RAND_MAX) * (lubEffect->dir2.x - lubEffect->dir1.x), -lubEffect->dir1.y + (rand() / (float)RAND_MAX) * (-lubEffect->dir2.y + lubEffect->dir1.y), @@ -122,36 +122,45 @@ void LubRenderer::render() emitTime = 1.0f / (lubEffect->rate.x + (rand() / (float)RAND_MAX) * (lubEffect->rate.y - lubEffect->rate.x)); } - + if (lubEffect->zenable) + glEnable(GL_DEPTH_TEST); + else + glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); int src = d3dToOpenGlBlend(lubEffect->srcmode); int dst = d3dToOpenGlBlend(lubEffect->destmode); - glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE); + glBlendFunc(src, dst); glDepthMask(0); std::vector verts; for (const auto& p : particles) { float alpha = p.alpha; - //float alpha = 1.0; - verts.push_back(VertexP3T2A1(p.position + glm::vec3(-p.size, -p.size, 0), glm::vec2(0, 0), alpha)); - verts.push_back(VertexP3T2A1(p.position + glm::vec3(-p.size, p.size, 0), glm::vec2(0, 1), alpha)); - verts.push_back(VertexP3T2A1(p.position + glm::vec3(p.size, p.size, 0), glm::vec2(1, 1), alpha)); - verts.push_back(VertexP3T2A1(p.position + glm::vec3(p.size, -p.size, 0), glm::vec2(1, 0), alpha)); + verts.push_back(VertexP3T2A1(glm::vec3(-p.size, -p.size, 0), glm::vec2(0, 0), alpha)); + verts.push_back(VertexP3T2A1(glm::vec3(-p.size, p.size, 0), glm::vec2(0, 1), alpha)); + verts.push_back(VertexP3T2A1(glm::vec3(p.size, p.size, 0), glm::vec2(1, 1), alpha)); + verts.push_back(VertexP3T2A1(glm::vec3(p.size, -p.size, 0), glm::vec2(1, 0), alpha)); } - if (verts.size() > 0) { - glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(VertexP3T2A1), verts[0].data); glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(VertexP3T2A1), verts[0].data + 3); glVertexAttribPointer(2, 1, GL_FLOAT, false, sizeof(VertexP3T2A1), verts[0].data + 5); - glDrawArrays(GL_QUADS, 0, (int)verts.size()); } + + for (int i = 0; i < particles.size(); i++) + { + Particle p = particles[i]; + glm::mat4 modelMatrixSub = modelMatrix; + modelMatrixSub[3] += glm::vec4(p.position.x, p.position.y, -p.position.z, 0.0f); + shader->setUniform(LubShader::Uniforms::modelMatrix, modelMatrixSub); + glDrawArrays(GL_QUADS, 4 * i, 4); + } + glDepthMask(1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + glEnable(GL_DEPTH_TEST); } diff --git a/browedit/components/Rsm.cpp b/browedit/components/Rsm.cpp index 392a393..6e8e3ba 100644 --- a/browedit/components/Rsm.cpp +++ b/browedit/components/Rsm.cpp @@ -584,18 +584,13 @@ void Rsm::Mesh::calcMatrix1(int time) if (scaleFrames.size() > 0) { int tick = time % glm::max(1, model->animLen); int prevIndex = -1; - int nextIndex = -1; + int nextIndex = 0; - while (true) { - nextIndex++; - - if (nextIndex == scaleFrames.size() || tick < scaleFrames[nextIndex].time) - break; - - prevIndex++; + for (; nextIndex < scaleFrames.size() && tick >= scaleFrames[nextIndex].time; nextIndex++) { } - float prevTick = (float)(prevIndex < 0 ? 0 : scaleFrames[prevIndex].time); //TODO: this part is repeated for rot,scale,pos... dedupe code + prevIndex = nextIndex - 1; + float prevTick = (float)(prevIndex < 0 ? 0 : scaleFrames[prevIndex].time); float nextTick = (float)(nextIndex == scaleFrames.size() ? model->animLen : scaleFrames[nextIndex].time); glm::vec3 prev = prevIndex < 0 ? glm::vec3(1) : scaleFrames[prevIndex].scale; glm::vec3 next = nextIndex == scaleFrames.size() ? scaleFrames[nextIndex - 1].scale : scaleFrames[nextIndex].scale; @@ -608,22 +603,17 @@ void Rsm::Mesh::calcMatrix1(int time) { int tick = time % glm::max(1, model->animLen); int prevIndex = -1; - int nextIndex = -1; - - while (true) { - nextIndex++; - - if (nextIndex == rotFrames.size() || tick < rotFrames[nextIndex].time) - break; - - prevIndex++; + int nextIndex = 0; + + for (; nextIndex < rotFrames.size() && tick >= rotFrames[nextIndex].time; nextIndex++) { } - + + prevIndex = nextIndex - 1; float prevTick = (float)(prevIndex < 0 ? 0 : rotFrames[prevIndex].time); float nextTick = (float)(nextIndex == rotFrames.size() ? model->animLen : rotFrames[nextIndex].time); - glm::quat prev = prevIndex < 0 ? glm::quat() : rotFrames[prevIndex].quaternion; + glm::quat prev = prevIndex < 0 ? glm::quat(1, 0, 0, 0) : rotFrames[prevIndex].quaternion; glm::quat next = nextIndex == rotFrames.size() ? rotFrames[nextIndex - 1].quaternion : rotFrames[nextIndex].quaternion; - + float mult = (tick - prevTick) / (nextTick - prevTick); glm::quat quat = glm::slerp(prev, next, mult); matrix1 = glm::toMat4(quat) * matrix1; @@ -644,17 +634,12 @@ void Rsm::Mesh::calcMatrix1(int time) if (posFrames.size() > 0) { int tick = time % glm::max(1, model->animLen); int prevIndex = -1; - int nextIndex = -1; - - while (true) { - nextIndex++; - - if (nextIndex == posFrames.size() || tick < posFrames[nextIndex].time) - break; + int nextIndex = 0; - prevIndex++; + for (; nextIndex < posFrames.size() && tick >= posFrames[nextIndex].time; nextIndex++) { } + prevIndex = nextIndex - 1; float prevTick = (float)(prevIndex < 0 ? 0 : posFrames[prevIndex].time); float nextTick = (float)(nextIndex == posFrames.size() ? model->animLen : posFrames[nextIndex].time); glm::vec3 prev = prevIndex < 0 ? pos_ : posFrames[prevIndex].position; diff --git a/browedit/components/RsmRenderer.cpp b/browedit/components/RsmRenderer.cpp index c291f45..1573366 100644 --- a/browedit/components/RsmRenderer.cpp +++ b/browedit/components/RsmRenderer.cpp @@ -224,7 +224,7 @@ void RsmRenderer::renderMesh(Rsm::Mesh* mesh, const glm::mat4& matrix, bool sele textures.push_back(util::ResourceManager::load("data\\texture\\" + textureFilename)); } - if (mesh && (!mesh->rotFrames.empty() || mesh->matrixDirty || !mesh->scaleFrames.empty() || !mesh->posFrames.empty())) + if (mesh && (!mesh->rotFrames.empty() || mesh->matrixDirty || mesh->model->version >= 0x202)) { mesh->matrixDirty = false; diff --git a/browedit/components/Rsw.Effect.cpp b/browedit/components/Rsw.Effect.cpp index 83ff9d1..ed50fa1 100644 --- a/browedit/components/Rsw.Effect.cpp +++ b/browedit/components/Rsw.Effect.cpp @@ -118,6 +118,7 @@ void LubEffect::load(const json& data) srcmode = data["srcmode"][0]; destmode = data["destmode"][0]; maxcount = data["maxcount"][0]; + zenable = data["zenable"][0]; if (data.find("billboard_off") != data.end()) billboard_off = data["billboard_off"][0]; diff --git a/browedit/components/Rsw.cpp b/browedit/components/Rsw.cpp index b43c15a..73c3f61 100644 --- a/browedit/components/Rsw.cpp +++ b/browedit/components/Rsw.cpp @@ -51,6 +51,7 @@ void Rsw::load(const std::string& fileName, Map* map, BrowEdit* browEdit, bool l quadtree = nullptr; json lubInfo = json::array(); + std::map lubInfoMap; std::string mapName = fileName; mapName = mapName.substr(0, mapName.size() - 4); @@ -139,20 +140,12 @@ void Rsw::load(const std::string& fileName, Map* map, BrowEdit* browEdit, bool l std::replace(data.begin(), data.end(), ']', '\"'); data = util::replace(data, "\"\"", ""); std::replace(data.begin(), data.end(), '=', ':'); - data[0] = '['; auto lines = util::split(data, "\n"); bool done = false; for (auto i = 0; i < lines.size(); i++) { if (lines[i].find("--") != std::string::npos) lines[i] = util::rtrim(lines[i].substr(0, lines[i].find("--")));//remove comments - if (lines[i].size() > 2 && lines[i][0] == '\t' && lines[i][1] == '\"') - { - if (lines[i].find("{") != std::string::npos) - lines[i] = lines[i].substr(lines[i].find(":") + 2); - else - lines[i] = ""; - } if (lines[i].size() > 3 && lines[i][0] == '\t' && lines[i][1] == '\t' && lines[i][2] != '\t') { lines[i] = "\t\t\"" + lines[i].substr(2, lines[i].find(" ") - 2) + "\"" + lines[i].substr(lines[i].find(" ") + 1); @@ -174,11 +167,14 @@ void Rsw::load(const std::string& fileName, Map* map, BrowEdit* browEdit, bool l jsondata = util::replace(jsondata, "\n\n", "\n"); jsondata = util::trim(jsondata); - jsondata[jsondata.length() - 1] = ']'; try { lubInfo = json::parse(jsondata); + + for (auto& it : lubInfo.items()) { + lubInfoMap[atoi(it.key().c_str())] = it.value(); + } } catch (const std::exception& e) { @@ -384,8 +380,8 @@ void Rsw::load(const std::string& fileName, Map* map, BrowEdit* browEdit, bool l if (rswEffect && rswEffect->id == 974) { auto lubEffect = new LubEffect(); - if (lubIndex <= lubInfo.size()) - lubEffect->load(lubInfo[lubIndex]); + if (lubInfoMap.find(lubIndex) != lubInfoMap.end()) + lubEffect->load(lubInfoMap[lubIndex]); object->addComponent(lubEffect); object->addComponent(new LubRenderer()); lubIndex++; @@ -596,7 +592,7 @@ void Rsw::save(const std::string& fileName, BrowEdit* browEdit) { std::cout << "Lub effects found, saving to " << browEdit->config.ropath << "data\\luafiles514\\lua files\\effecttool\\" << mapName << ".lub" << std::endl; std::ofstream lubFile((browEdit->config.ropath + "data\\luafiles514\\lua files\\effecttool\\" + mapName + ".lub").c_str(), std::ios_base::out | std::ios_base::binary); - lubFile << "_" << luaMapName << "_emitterInfo_version = "<srcmode) << "," << std::endl; SAVEPROP0("destmode", lubEffects[i]->destmode) << "," << std::endl; SAVEPROP0("maxcount", lubEffects[i]->maxcount) << "," << std::endl; - SAVEPROP0("zenable", lubEffects[i]->zenable) << "," <zenable) << "," << std::endl; + SAVEPROP0("billboard_off", lubEffects[i]->billboard_off) << "," << std::endl; SAVEPROP3("rotate_angle", lubEffects[i]->rotate_angle) << std::endl; diff --git a/data/shaders/gnd.fs b/data/shaders/gnd.fs index e94dff9..cf81083 100644 --- a/data/shaders/gnd.fs +++ b/data/shaders/gnd.fs @@ -36,7 +36,8 @@ void main() if(texture.a < 0.1) discard; - texture.rgb *= max((max(0.0, dot(normal, vec3(1,-1,1)*lightDirection)) * lightDiffuse + lightIntensity * lightAmbient), lightToggle); + float NL = clamp(dot(normalize(normal), vec3(1,-1,1)*lightDirection),0.0,1.0); + texture.rgb *= max((NL * min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient), lightToggle); texture.rgb *= max(color, colorToggle).rgb; texture.rgb *= max(texture2D(s_lighting, texCoord2).a, shadowMapToggle); texture.rgb += clamp(texture2D(s_lighting, texCoord2).rgb, 0.0, 1.0) * lightColorToggle; diff --git a/data/shaders/lub.fs b/data/shaders/lub.fs index 7b12968..888168b 100644 --- a/data/shaders/lub.fs +++ b/data/shaders/lub.fs @@ -13,7 +13,5 @@ void main() vec4 outColor = texture2D(s_texture, texCoord); outColor *= color; outColor.a *= alpha; - //if(outColor.a < 0.1) - // discard; fragColor = outColor; } \ No newline at end of file diff --git a/data/shaders/rsm.fs b/data/shaders/rsm.fs index 91e6349..c297c2f 100644 --- a/data/shaders/rsm.fs +++ b/data/shaders/rsm.fs @@ -31,11 +31,12 @@ void main() discard; if (lightToggle) { - // lightIntensity is ignored by the client for whatever reason if (shadeType == 0) color.rgb *= min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient; - else if (shadeType == 1 || shadeType == 2) - color.rgb *= clamp(dot(normalize(normal), lightDirection),0.0,1.0) * lightDiffuse + lightAmbient; + else if (shadeType == 1 || shadeType == 2) { + float NL = clamp(dot(normalize(normal), lightDirection),0.0,1.0); + color.rgb *= NL * min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient; + } else if (shadeType == 4) // only for editor color.rgb *= lightDiffuse; }