Models now draw in a single draw call

This commit is contained in:
grayson committed 2021-10-01 01:21:27 -05:00
1 parent 037ad47468
commit ba19742bfe
19 files changed
+257 -168

No files matched your search

@@ -4,19 +4,16 @@ in vec3 fragPos;
in vec2 texCoord;
in vec3 normal;
in mat3 tbn;
flat in int matNum;
struct Material {
bool hasDiffuseTex;
sampler2D diffuseTexture;
vec3 diffuseColor;
bool hasSpecTex;
sampler2D specularTexture;
float specPower;
bool hasNormTex;
sampler2D normalTexture;
};
uniform Material material;
uniform bool hasDiffuseTex[32];
uniform sampler2D diffuseTexture[32];
uniform vec3 diffuseColor[32];
uniform bool hasSpecTex[32];
uniform sampler2D specularTexture[32];
uniform float specPower[32];
uniform bool hasNormTex[32];
uniform sampler2D normalTexture[32];
layout(location = 0) out vec3 pos;
layout(location = 1) out vec3 normals;
@@ -25,25 +22,9 @@ layout(location = 3) out vec3 specular;
void main() {
pos = fragPos;
if (material.hasNormTex) {
normals = texture(material.normalTexture, texCoord).xyz;
normals = normals * 2.0 - 1.0;
normals = normalize(tbn * normals);
}
else
normals = normal;
if (material.hasDiffuseTex)
diffuse = texture(material.diffuseTexture, texCoord).rgb;
else
diffuse = material.diffuseColor;
specular.r = material.specPower;
if (material.hasSpecTex)
specular.g = texture(material.specularTexture, texCoord).r;
else
specular.g = 1.0;
normals = hasNormTex[matNum] ? normalize(tbn * (texture(normalTexture[matNum], texCoord).xyz * 2.0 - 1.0)) : normal;
diffuse = hasDiffuseTex[matNum] ? texture(diffuseTexture[matNum], texCoord).rgb : diffuseColor[matNum];
specular.r = specPower[matNum];
specular.g = hasSpecTex[matNum] ? texture(specularTexture[matNum], texCoord).r : 1.0;
specular.b = 1.0;
}
@@ -4,6 +4,7 @@ layout(location = 0) in vec3 pos;
layout(location = 1) in vec2 texCoords;
layout(location = 2) in vec3 normals;
layout(location = 3) in vec3 tangent;
layout(location = 4) in int matN;
uniform mat4 model;
uniform mat4 view;
@@ -12,8 +13,8 @@ uniform mat4 proj;
out vec3 fragPos;
out vec2 texCoord;
out vec3 normal;
out vec3 tang;
out mat3 tbn;
flat out int matNum;
void main() {
vec4 world = model * vec4(pos, 1.0);
@@ -25,6 +26,7 @@ void main() {
normal = n;
vec3 b = cross(n, t);
tbn = mat3(t, b, n);
matNum = matN;
gl_Position = proj * view * world;
}
@@ -0,0 +1,26 @@
# Blender MTL File: 'None'
# Material Count: 2
newmtl mat1
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd diff.png
map_Ks spec.png
newmtl mat2
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Bump brickwall_normal.jpg
map_Kd brickwall.jpg
@@ -0,0 +1,47 @@
# Blender v2.93.3 OBJ File: ''
# www.blender.org
mtllib 2mats.mtl
o Cube_Cube.001
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
vt -2.000000 0.000000
vt -1.000000 1.000000
vt -2.000000 1.000000
vt -1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 2.000000 1.000000
vt 1.000000 1.000000
vt 1.000000 2.000000
vt 0.000000 2.000000
vt 0.000000 -1.000000
vt 0.000000 0.000000
vt 2.000000 0.000000
vt 1.000000 -1.000000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
usemtl mat1
s off
f 2/1/1 3/2/1 1/3/1
f 4/4/2 7/5/2 3/2/2
f 6/6/3 1/7/3 5/8/3
f 7/5/4 1/9/4 3/10/4
f 4/11/5 6/6/5 8/12/5
f 2/1/1 4/4/1 3/2/1
f 4/4/2 8/12/2 7/5/2
f 6/6/3 2/13/3 1/7/3
f 7/5/4 5/8/4 1/9/4
f 4/11/5 2/14/5 6/6/5
usemtl mat2
f 8/12/6 5/8/6 7/5/6
f 8/12/6 6/6/6 5/8/6