Added the materials system; Any model can have any number of materials with different textures and properties
This commit is contained in:
1 parent
70318b28fd
commit
39e0c8e808
37 files changed
+1616
-1327
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,5 +1,6 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib cone.mtl
|
||||
o Cone
|
||||
v 0.000000 -1.000000 -1.000000
|
||||
v 0.195090 -1.000000 -0.980785
|
||||
@@ -133,6 +134,7 @@ vn -0.4969 0.4472 -0.7437
|
||||
vn -0.3423 0.4472 -0.8263
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn -0.1745 0.4472 -0.8772
|
||||
usemtl None
|
||||
s 1
|
||||
f 1/1/1 33/2/2 2/3/3
|
||||
f 2/3/3 33/2/2 3/4/4
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,6 +1,7 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
o Cube_Cube.002
|
||||
mtllib cube.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
|
||||
@@ -29,6 +30,7 @@ vn 1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 1.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
usemtl None
|
||||
s off
|
||||
f 2/1/1 3/2/1 1/3/1
|
||||
f 4/4/2 7/5/2 3/2/2
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,6 +1,7 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
o Cylinder
|
||||
mtllib cylinder.mtl
|
||||
o Cylinder_Cylinder.001
|
||||
v 0.000000 -1.000000 -1.000000
|
||||
v 0.000000 1.000000 -1.000000
|
||||
v 0.195090 -1.000000 -0.980785
|
||||
@@ -229,6 +230,7 @@ vn -0.3827 0.0000 -0.9239
|
||||
vn 0.0000 1.0000 -0.0000
|
||||
vn -0.1951 0.0000 -0.9808
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
usemtl None
|
||||
s 1
|
||||
f 2/1/1 3/2/2 1/3/1
|
||||
f 4/4/2 5/5/3 3/2/2
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,5 +1,6 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib plane.mtl
|
||||
o Plane
|
||||
v -1.000000 0.000000 1.000000
|
||||
v 1.000000 0.000000 1.000000
|
||||
@@ -10,6 +11,7 @@ vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
usemtl None
|
||||
s off
|
||||
f 2/1/1 3/2/1 1/3/1
|
||||
f 2/1/1 4/4/1 3/2/1
|
||||
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,10 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 100
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,5 +1,6 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib torus.mtl
|
||||
o Torus
|
||||
v 1.250000 0.000000 0.000000
|
||||
v 1.216506 0.125000 0.000000
|
||||
@@ -1742,6 +1743,7 @@ vn 0.5036 -0.8614 0.0663
|
||||
vn 0.8612 -0.4954 0.1134
|
||||
vn -0.8559 0.5047 -0.1127
|
||||
vn -0.4876 -0.8707 -0.0642
|
||||
usemtl None
|
||||
s 1
|
||||
f 13/1/1 2/2/2 1/3/3
|
||||
f 2/2/2 15/4/4 3/5/5
|
||||
|
||||
@@ -9,8 +9,12 @@ struct Camera {
|
||||
};
|
||||
|
||||
struct Material {
|
||||
float shininess;
|
||||
//Do I want a specular color here?
|
||||
bool hasDiffuseTex;
|
||||
sampler2D diffuseTexture;
|
||||
vec3 diffuseColor;
|
||||
bool hasSpecTex;
|
||||
sampler2D specularTexture;
|
||||
float specPower;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
@@ -21,7 +25,6 @@ struct Light {
|
||||
float strength;
|
||||
};
|
||||
|
||||
uniform sampler2D modelTexture;
|
||||
uniform Camera camera;
|
||||
uniform Material material;
|
||||
uniform Light light[100];
|
||||
@@ -30,13 +33,21 @@ uniform int numberOfLights;
|
||||
out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture(modelTexture, texCoord);
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
vec3 matDiff;
|
||||
if (material.hasDiffuseTex)
|
||||
matDiff = texture(material.diffuseTexture, texCoord).rgb;
|
||||
else
|
||||
matDiff = material.diffuseColor;
|
||||
|
||||
vec3 matSpec = vec3(1.0);
|
||||
if(material.hasSpecTex)
|
||||
matSpec = texture(material.specularTexture, texCoord).rgb;
|
||||
|
||||
for (int i = 0; i < numberOfLights; i++) {
|
||||
float ambientStrength = 0.2f;
|
||||
vec3 ambient = ambientStrength * texColor.rgb;
|
||||
vec3 ambient = ambientStrength * matDiff;
|
||||
if (i == numberOfLights - 1 && numberOfLights == 1) {
|
||||
color += ambient;
|
||||
break;
|
||||
@@ -46,12 +57,12 @@ void main() {
|
||||
vec3 lightDir = normalize(-light[i].pos);
|
||||
vec3 norm = normalize(normals);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light[i].color * (diff * texColor.rgb) * light[i].strength;
|
||||
vec3 diffuse = light[i].color * (diff * matDiff) * (light[i].strength / 2.0f);
|
||||
|
||||
vec3 viewDir = normalize(camera.pos - fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f);
|
||||
vec3 specular = light[i].color * spec * light[i].strength;
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.specPower);
|
||||
vec3 specular = light[i].color * spec * matSpec * (light[i].strength / 2.0f);
|
||||
|
||||
color += (ambient + diffuse + specular);
|
||||
continue;
|
||||
@@ -60,12 +71,12 @@ void main() {
|
||||
vec3 lightDir = normalize(light[i].pos - fragPos);
|
||||
vec3 norm = normalize(normals);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light[i].color * (diff * texColor.rgb) * light[i].strength;
|
||||
vec3 diffuse = light[i].color * (diff * matDiff) * (light[i].strength / 2.0f);
|
||||
|
||||
vec3 viewDir = normalize(camera.pos - fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess * 32.0f);
|
||||
vec3 specular = light[i].color * spec * (light[i].strength) / 8.0f;
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.specPower);
|
||||
vec3 specular = light[i].color * spec * matSpec * (light[i].strength / 2.0f);
|
||||
|
||||
float length = length(light[i].pos - fragPos);
|
||||
float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength;
|
||||
@@ -74,5 +85,5 @@ void main() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
outColor = vec4(color, texColor.a);
|
||||
outColor = vec4(color, 1.0);
|
||||
}
|
||||
Reference in new issue
Block a user