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;
}