mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
fixed z fighting for GUI elements
This commit is contained in:
@@ -12,6 +12,6 @@ void main(){
|
||||
float x, y;
|
||||
x = (aVert.x + pos.x - screen.x * .5) / (screen.x * .5);
|
||||
y = (screen.y * .5 - (aVert.y + pos.y)) / (screen.y * .5);
|
||||
gl_Position = vec4(x, y, pos.z + aVert.z, 1);
|
||||
gl_Position = vec4(x, y, -(pos.z + aVert.z), 1);
|
||||
texCoords = aTexCoords;
|
||||
}
|
||||
|
||||
@@ -160,9 +160,12 @@ namespace vb01{
|
||||
inline void addVec4Uniform(std::string name, Vector4 value){uniforms.push_back(new Vector4Uniform(name, value));}
|
||||
inline void addTexUniform(std::string name, Texture *value, bool animatable){uniforms.push_back(new TextureUniform(name, value, animatable));}
|
||||
inline Shader* getShader(){return shader;}
|
||||
inline bool isTransparent(){return transparent;}
|
||||
inline void setTransparent(bool t){this->transparent = t;}
|
||||
private:
|
||||
std::vector<Uniform*> uniforms;
|
||||
Shader *shader = nullptr;
|
||||
bool transparent = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace vb01{
|
||||
inline Skeleton* getSkeleton(int i){return skeletons[i];}
|
||||
inline int getNumSkeletons(){return skeletons.size();}
|
||||
inline Text* getText(int i){return texts[i];}
|
||||
inline std::vector<Text*>& getTexts(){return texts;}
|
||||
inline std::vector<Mesh*>& getMeshes(){return meshes;}
|
||||
inline std::vector<Skeleton*>& getSkeletons(){return skeletons;}
|
||||
inline Mesh* getMesh(int i){return meshes[i];}
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace vb01{
|
||||
|
||||
AnimationController::getSingleton()->update();
|
||||
|
||||
updateNodeTree(rootNode);
|
||||
updateNodeTree(rootNode, false);
|
||||
|
||||
LineRenderer::getSingleton()->drawLines();
|
||||
|
||||
@@ -167,33 +167,28 @@ namespace vb01{
|
||||
updateGuiPlane();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
updateNodeTree(guiNode);
|
||||
updateNodeTree(guiNode, true);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
//TODO replace sorting algorithm
|
||||
void Root::updateNodeTree(Node *node){
|
||||
//TODO specify differentiation of nodes with translucent meshes AND texts
|
||||
void Root::updateNodeTree(Node *node, bool gui){
|
||||
vector<Node*> descendants, opaqueNodes, transparentNodes;
|
||||
node->getDescendants(descendants);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
if(!desc->getMeshes().empty())
|
||||
for(Mesh *mesh : desc->getMeshes()){
|
||||
(mesh->getMaterial()->isTransparent() ? transparentNodes : opaqueNodes).push_back(desc);
|
||||
break;
|
||||
}
|
||||
else if(!desc->getTexts().empty())
|
||||
transparentNodes.push_back(desc);
|
||||
else
|
||||
opaqueNodes.push_back(desc);
|
||||
}
|
||||
|
||||
for(Node *node : opaqueNodes)
|
||||
@@ -202,22 +197,30 @@ namespace vb01{
|
||||
int numNodes = transparentNodes.size();
|
||||
|
||||
for(int i = 0; i < numNodes; i++){
|
||||
float d1 = transparentNodes[i]->getPosition().z;
|
||||
|
||||
if(!gui){
|
||||
Vector3 v1 = transparentNodes[i]->getPosition() - camera->getPosition();
|
||||
float a1 = v1.norm().getAngleBetween(camera->getDirection());
|
||||
float d1 = v1.getLength() * cos(a1);
|
||||
d1 = v1.getLength() * cos(a1);
|
||||
}
|
||||
|
||||
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);
|
||||
for(int j = i; j < numNodes; j++){
|
||||
float d2 = transparentNodes[j]->getPosition().z;
|
||||
|
||||
if(d1 < d2)
|
||||
swap(transparentNodes[i], transparentNodes[j]);
|
||||
if(!gui){
|
||||
Vector3 v2 = transparentNodes[j]->getPosition() - camera->getPosition();
|
||||
float a2 = v2.norm().getAngleBetween(camera->getDirection());
|
||||
d2 = v2.getLength() * cos(a2);
|
||||
}
|
||||
|
||||
if(d1 > d2)
|
||||
swap(transparentNodes[i], transparentNodes[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(Node *node : transparentNodes)
|
||||
node->update();
|
||||
node->update();
|
||||
}
|
||||
|
||||
void Root::updateBloomFramebuffer(){
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace vb01{
|
||||
void initGuiPlane(Texture*, Texture*);
|
||||
void updateBloomFramebuffer();
|
||||
void updateGuiPlane();
|
||||
void updateNodeTree(vb01::Node*);
|
||||
void updateNodeTree(vb01::Node*, bool);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user