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;
|
float x, y;
|
||||||
x = (aVert.x + pos.x - screen.x * .5) / (screen.x * .5);
|
x = (aVert.x + pos.x - screen.x * .5) / (screen.x * .5);
|
||||||
y = (screen.y * .5 - (aVert.y + pos.y)) / (screen.y * .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;
|
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 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 void addTexUniform(std::string name, Texture *value, bool animatable){uniforms.push_back(new TextureUniform(name, value, animatable));}
|
||||||
inline Shader* getShader(){return shader;}
|
inline Shader* getShader(){return shader;}
|
||||||
|
inline bool isTransparent(){return transparent;}
|
||||||
|
inline void setTransparent(bool t){this->transparent = t;}
|
||||||
private:
|
private:
|
||||||
std::vector<Uniform*> uniforms;
|
std::vector<Uniform*> uniforms;
|
||||||
Shader *shader = nullptr;
|
Shader *shader = nullptr;
|
||||||
|
bool transparent = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace vb01{
|
|||||||
inline Skeleton* getSkeleton(int i){return skeletons[i];}
|
inline Skeleton* getSkeleton(int i){return skeletons[i];}
|
||||||
inline int getNumSkeletons(){return skeletons.size();}
|
inline int getNumSkeletons(){return skeletons.size();}
|
||||||
inline Text* getText(int i){return texts[i];}
|
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<Mesh*>& getMeshes(){return meshes;}
|
||||||
inline std::vector<Skeleton*>& getSkeletons(){return skeletons;}
|
inline std::vector<Skeleton*>& getSkeletons(){return skeletons;}
|
||||||
inline Mesh* getMesh(int i){return meshes[i];}
|
inline Mesh* getMesh(int i){return meshes[i];}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace vb01{
|
|||||||
|
|
||||||
AnimationController::getSingleton()->update();
|
AnimationController::getSingleton()->update();
|
||||||
|
|
||||||
updateNodeTree(rootNode);
|
updateNodeTree(rootNode, false);
|
||||||
|
|
||||||
LineRenderer::getSingleton()->drawLines();
|
LineRenderer::getSingleton()->drawLines();
|
||||||
|
|
||||||
@@ -167,31 +167,26 @@ namespace vb01{
|
|||||||
updateGuiPlane();
|
updateGuiPlane();
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
updateNodeTree(guiNode);
|
updateNodeTree(guiNode, true);
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO replace sorting algorithm
|
//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;
|
vector<Node*> descendants, opaqueNodes, transparentNodes;
|
||||||
node->getDescendants(descendants);
|
node->getDescendants(descendants);
|
||||||
|
|
||||||
for(Node *desc : descendants){
|
for(Node *desc : descendants){
|
||||||
if(!desc->getMeshes().empty())
|
if(!desc->getMeshes().empty())
|
||||||
for(Mesh *mesh : desc->getMeshes()){
|
for(Mesh *mesh : desc->getMeshes()){
|
||||||
Material *mat = mesh->getMaterial();
|
(mesh->getMaterial()->isTransparent() ? transparentNodes : opaqueNodes).push_back(desc);
|
||||||
vector<Material::Uniform*> uniforms = mat->getUniformsByType(Material::Uniform::TEXTURE);
|
break;
|
||||||
|
|
||||||
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 if(!desc->getTexts().empty())
|
||||||
|
transparentNodes.push_back(desc);
|
||||||
else
|
else
|
||||||
opaqueNodes.push_back(desc);
|
opaqueNodes.push_back(desc);
|
||||||
}
|
}
|
||||||
@@ -202,16 +197,24 @@ namespace vb01{
|
|||||||
int numNodes = transparentNodes.size();
|
int numNodes = transparentNodes.size();
|
||||||
|
|
||||||
for(int i = 0; i < numNodes; i++){
|
for(int i = 0; i < numNodes; i++){
|
||||||
|
float d1 = transparentNodes[i]->getPosition().z;
|
||||||
|
|
||||||
|
if(!gui){
|
||||||
Vector3 v1 = transparentNodes[i]->getPosition() - camera->getPosition();
|
Vector3 v1 = transparentNodes[i]->getPosition() - camera->getPosition();
|
||||||
float a1 = v1.norm().getAngleBetween(camera->getDirection());
|
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++){
|
for(int j = i; j < numNodes; j++){
|
||||||
|
float d2 = transparentNodes[j]->getPosition().z;
|
||||||
|
|
||||||
|
if(!gui){
|
||||||
Vector3 v2 = transparentNodes[j]->getPosition() - camera->getPosition();
|
Vector3 v2 = transparentNodes[j]->getPosition() - camera->getPosition();
|
||||||
float a2 = v2.norm().getAngleBetween(camera->getDirection());
|
float a2 = v2.norm().getAngleBetween(camera->getDirection());
|
||||||
float d2 = v2.getLength() * cos(a2);
|
d2 = v2.getLength() * cos(a2);
|
||||||
|
}
|
||||||
|
|
||||||
if(d1 < d2)
|
if(d1 > d2)
|
||||||
swap(transparentNodes[i], transparentNodes[j]);
|
swap(transparentNodes[i], transparentNodes[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace vb01{
|
|||||||
void initGuiPlane(Texture*, Texture*);
|
void initGuiPlane(Texture*, Texture*);
|
||||||
void updateBloomFramebuffer();
|
void updateBloomFramebuffer();
|
||||||
void updateGuiPlane();
|
void updateGuiPlane();
|
||||||
void updateNodeTree(vb01::Node*);
|
void updateNodeTree(vb01::Node*, bool);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ void main(){
|
|||||||
float x, y;
|
float x, y;
|
||||||
x = (aVert.x - screen.x * .5) / (screen.x * .5);
|
x = (aVert.x - screen.x * .5) / (screen.x * .5);
|
||||||
y = (screen.y * .5 - (aVert.y)) / (screen.y * .5);
|
y = (screen.y * .5 - (aVert.y)) / (screen.y * .5);
|
||||||
gl_Position = vec4(x, y, pos.z, 1);
|
gl_Position = vec4(x, y, -pos.z, 1);
|
||||||
texCoords = aVert.zw;
|
texCoords = aVert.zw;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user