mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
opaque objects are rendered before transparent objects
This commit is contained in:
@@ -97,4 +97,14 @@ namespace vb01{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
vector<Material::Uniform*> Material::getUniformsByType(Material::Uniform::Type type){
|
||||
vector<Material::Uniform*> uniforms;
|
||||
|
||||
for(Uniform *uni : this->uniforms)
|
||||
if(uni->type == type)
|
||||
uniforms.push_back(uni);
|
||||
|
||||
return uniforms;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@ namespace vb01{
|
||||
void setVec4Uniform(std::string, Vector4);
|
||||
void setTexUniform(std::string, Texture*, bool);
|
||||
Uniform* getUniform(std::string);
|
||||
std::vector<Uniform*> getUniformsByType(Uniform::Type);
|
||||
inline Uniform* getUniform(int i){return uniforms[i];}
|
||||
inline void addIntUniform(std::string name, int value){uniforms.push_back(new IntUniform(name, value));}
|
||||
inline void addBoolUniform(std::string name, bool value){uniforms.push_back(new BoolUniform(name, value));}
|
||||
|
||||
@@ -173,30 +173,51 @@ namespace vb01{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
//TODO replace sorting algorithm and sort only transparent objects
|
||||
//TODO replace sorting algorithm
|
||||
void Root::updateNodeTree(Node *node){
|
||||
vector<Node*> descendants;
|
||||
vector<Node*> descendants, opaqueNodes, transparentNodes;
|
||||
node->getDescendants(descendants);
|
||||
|
||||
int numDesc = descendants.size();
|
||||
for(Node *desc : descendants){
|
||||
if(!desc->getMeshes().empty())
|
||||
for(Mesh *mesh : desc->getMeshes()){
|
||||
Material *mat = mesh->getMaterial();
|
||||
vector<Material::Uniform*> uniforms = mat->getUniformsByType(Material::Uniform::TEXTURE);
|
||||
|
||||
for(int i = 0; i < numDesc; i++){
|
||||
Vector3 v1 = descendants[i]->getPosition() - camera->getPosition();
|
||||
if(!uniforms.empty())
|
||||
for(Material::Uniform *uni : uniforms){
|
||||
bool transparent = ((Material::TextureUniform*)uni)->value->isTransparent();
|
||||
(transparent ? transparentNodes : opaqueNodes).push_back(desc);
|
||||
}
|
||||
else
|
||||
opaqueNodes.push_back(desc);
|
||||
}
|
||||
else
|
||||
opaqueNodes.push_back(desc);
|
||||
}
|
||||
|
||||
for(Node *node : opaqueNodes)
|
||||
node->update();
|
||||
|
||||
int numNodes = transparentNodes.size();
|
||||
|
||||
for(int i = 0; i < numNodes; i++){
|
||||
Vector3 v1 = transparentNodes[i]->getPosition() - camera->getPosition();
|
||||
float a1 = v1.norm().getAngleBetween(camera->getDirection());
|
||||
float d1 = v1.getLength() * cos(a1);
|
||||
|
||||
for(int j = i; j < numDesc; j++){
|
||||
Vector3 v2 = descendants[j]->getPosition() - camera->getPosition();
|
||||
for(int j = i; j < numNodes; j++){
|
||||
Vector3 v2 = transparentNodes[j]->getPosition() - camera->getPosition();
|
||||
float a2 = v2.norm().getAngleBetween(camera->getDirection());
|
||||
float d2 = v2.getLength() * cos(a2);
|
||||
|
||||
if(d1 < d2)
|
||||
swap(descendants[i], descendants[j]);
|
||||
swap(transparentNodes[i], transparentNodes[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(Node *desc : descendants)
|
||||
desc->update();
|
||||
for(Node *node : transparentNodes)
|
||||
node->update();
|
||||
}
|
||||
|
||||
void Root::updateBloomFramebuffer(){
|
||||
|
||||
@@ -64,7 +64,6 @@ namespace vb01{
|
||||
mixRatio = .1;
|
||||
|
||||
for(int i = 0; i < numFrames; i++){
|
||||
bool png = false;
|
||||
int length = paths[i].length();
|
||||
|
||||
if(paths[i].substr(length - 4, string::npos) == ".png")
|
||||
|
||||
@@ -26,8 +26,9 @@ namespace vb01{
|
||||
inline int getMipmapLevel(){return mipmapLevel;}
|
||||
inline float getMixRatio(){return mixRatio;}
|
||||
inline bool isCubemap(){return cubemap;}
|
||||
inline bool isTransparent(){return png;}
|
||||
private:
|
||||
bool cubemap = false;
|
||||
bool cubemap = false, png = false;
|
||||
u32 *texture = nullptr;
|
||||
s64 lastUpdateTime = 0;
|
||||
int width, height, updateRate = 0, numFrames = 0, frameA = 0, frameB = 0, mipmapLevel = 1;
|
||||
|
||||
Reference in New Issue
Block a user