Add alpha scissor
This commit is contained in:
parent
70d68bd6b8
commit
2731289263
@ -27,10 +27,18 @@ target_link_libraries(couch ${LUA_LIBRARIES})
|
||||
|
||||
include(UseSWIG)
|
||||
set_property(SOURCE scripting/couch.i PROPERTY CPLUSPLUS ON)
|
||||
if (NOT WIN32)
|
||||
swig_add_library(couchlua
|
||||
TYPE SHARED
|
||||
LANGUAGE lua
|
||||
SOURCES scripting/couch.i scripting/lua/helpers.i)
|
||||
else()
|
||||
swig_add_library(couchlua
|
||||
TYPE STATIC
|
||||
LANGUAGE lua
|
||||
SOURCES scripting/couch.i scripting/lua/helpers.i)
|
||||
endif()
|
||||
|
||||
target_link_libraries(couchlua ${LUA_LIBRARIES})
|
||||
target_link_libraries(couch couchlua)
|
||||
|
||||
|
@ -15,8 +15,6 @@ Color::Color(cfloat r, cfloat g, cfloat b) {
|
||||
Texture::Texture() {}
|
||||
|
||||
Texture Texture::FromFile(const char *filename) {
|
||||
// Lotta hocus pocus
|
||||
// https://learnopengl.com/Getting-started/Textures
|
||||
Texture tex;
|
||||
glGenTextures(1, &tex.id);
|
||||
glBindTexture(GL_TEXTURE_2D, tex.id);
|
||||
@ -43,4 +41,5 @@ Texture Texture::FromFile(const char *filename) {
|
||||
Material::Material() {
|
||||
usesColor = false;
|
||||
usesTex = false;
|
||||
alphaScissor = 0.0f;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ struct Material {
|
||||
bool usesColor;
|
||||
Texture tex;
|
||||
bool usesTex;
|
||||
cfloat alphaScissor;
|
||||
Material();
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,7 @@ void SubMesh::SetupSubMesh() {
|
||||
void SubMesh::Draw(Shader *shader) {
|
||||
shader->UpdateColor(material.usesColor, material.color);
|
||||
shader->UpdateTex(material.usesTex, material.tex);
|
||||
shader->UpdateAlphaScissor(material.alphaScissor);
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
@ -54,6 +55,10 @@ void Mesh::SetupMesh() {
|
||||
}
|
||||
}
|
||||
|
||||
Material Mesh::GetMaterial(int submesh) {
|
||||
return submeshes[submesh]->material;
|
||||
}
|
||||
|
||||
void Mesh::SetMaterial(int submesh, Material material) {
|
||||
submeshes[submesh]->material = material;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ class Mesh : public Spatial {
|
||||
public:
|
||||
Mesh();
|
||||
~Mesh();
|
||||
Material GetMaterial(int submesh);
|
||||
void SetMaterial(int submesh, Material material);
|
||||
static Mesh *FromFile(const char *filename);
|
||||
virtual bool IsDrawable() const {return true;}
|
||||
|
@ -3,3 +3,5 @@
|
||||
#include "flat.frag.h"
|
||||
|
||||
FlatShader::FlatShader() : Shader(flat_vert, flat_frag) {}
|
||||
|
||||
Name FlatShader::GetName() const {return "Flat Shader";}
|
||||
|
@ -6,6 +6,7 @@
|
||||
class FlatShader : public Shader {
|
||||
public:
|
||||
FlatShader();
|
||||
Name GetName() const;
|
||||
};
|
||||
|
||||
#endif /* FLATSHADER_H */
|
||||
|
@ -3,3 +3,5 @@
|
||||
#include "screen.frag.h"
|
||||
|
||||
ScreenShader::ScreenShader() : Shader(screen_vert, screen_frag) {}
|
||||
|
||||
Name ScreenShader::GetName() const {return "Screen Shader";}
|
||||
|
@ -3,4 +3,5 @@
|
||||
class ScreenShader : public Shader {
|
||||
public:
|
||||
ScreenShader();
|
||||
Name GetName() const;
|
||||
};
|
||||
|
@ -69,6 +69,9 @@ void Shader::UpdateTex(bool usesTex, Texture tex) {
|
||||
glUniform1i(glGetUniformLocation(id, "material.usesTex"), (int) usesTex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex.id);
|
||||
}
|
||||
void Shader::UpdateAlphaScissor(cfloat alphaScissor) {
|
||||
glUniform1f(glGetUniformLocation(id, "material.alphaScissor"), alphaScissor);
|
||||
}
|
||||
|
||||
Name Shader::GetName() const {
|
||||
return "Unnamed Shader";
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
void UpdateColor(bool usesColor, Color color);
|
||||
void UpdateTex(bool usesTex);
|
||||
void UpdateTex(bool usesTex, Texture tex);
|
||||
void UpdateAlphaScissor(cfloat alphaScissor);
|
||||
|
||||
virtual Name GetName() const;
|
||||
};
|
||||
|
@ -52,6 +52,15 @@ function init()
|
||||
trough.transform.scale = trough.transform.scale * 3.0
|
||||
|
||||
scaffold = couch.TexturedMesh("scaffold.glb", "grate_floor_lowres.png", "railing.png")
|
||||
|
||||
material = scaffold:GetMaterial(0)
|
||||
material.alphaScissor = 0.9
|
||||
scaffold:SetMaterial(0, material)
|
||||
|
||||
material = scaffold:GetMaterial(1)
|
||||
material.alphaScissor = 0.1
|
||||
scaffold:SetMaterial(1, material)
|
||||
|
||||
couch.Node.GetRoot().children:Append(scaffold)
|
||||
scaffold.transform:Translate(-10.0, 0.0, 0.0)
|
||||
end
|
||||
|
@ -2,24 +2,27 @@
|
||||
|
||||
in vec3 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
struct Material {
|
||||
vec3 color;
|
||||
bool usesColor;
|
||||
sampler2D tex;
|
||||
bool usesTex;
|
||||
float alphaScissor;
|
||||
};
|
||||
|
||||
uniform Material material;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(0.0);
|
||||
FragColor = vec4(0.0);
|
||||
if (material.usesColor) {
|
||||
gl_FragColor += vec4(material.color, 1.0);
|
||||
FragColor += vec4(material.color, 1.0);
|
||||
}
|
||||
if (material.usesTex) {
|
||||
gl_FragColor += texture(material.tex, UV.xy / UV.z);
|
||||
FragColor += texture(material.tex, UV.xy / UV.z);
|
||||
}
|
||||
if (gl_FragColor.w < 0.99) {
|
||||
if (FragColor.w < material.alphaScissor) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user