Import materials from files

This commit is contained in:
Dane Johnson
2021-01-22 18:44:43 -06:00
parent 1ee5ed3e88
commit 1d97f6d855
22 changed files with 4427 additions and 44 deletions

View File

@@ -3,17 +3,21 @@
noperspective in vec2 UV;
in vec3 NORMAL;
flat in vec3 AMBIENT;
flat in vec3 DIFFUSE;
flat in vec3 SPECULAR;
in vec3 AMBIENT;
in vec3 DIFFUSE;
in vec3 SPECULAR;
out vec4 FragColor;
struct Material {
vec3 color;
bool usesColor;
sampler2D tex;
bool usesTex;
vec3 ambient;
vec3 diffuse;
vec3 specular;
int shininess;
float alphaScissor;
bool unshaded;
bool cullBack;
@@ -22,14 +26,10 @@ struct Material {
uniform Material material;
void main() {
FragColor = vec4(0.0);
if (material.usesColor) {
FragColor += vec4(material.color, 1.0);
}
FragColor = vec4(AMBIENT + DIFFUSE + SPECULAR, 1.0);
if (material.usesTex) {
FragColor += texture(material.tex, UV);
FragColor *= texture(material.tex, UV);
}
if (FragColor.w < material.alphaScissor) {
@@ -39,8 +39,4 @@ void main() {
if (material.cullBack && !gl_FrontFacing) {
discard;
}
if (!material.unshaded) {
FragColor *= vec4(AMBIENT + DIFFUSE + SPECULAR, 1.0);
}
}

View File

@@ -11,9 +11,9 @@ uniform mat4 PROJECTION;
noperspective out vec2 UV; // PSX use affine texture mapping
out vec3 NORMAL;
flat out vec3 AMBIENT;
flat out vec3 DIFFUSE;
flat out vec3 SPECULAR;
out vec3 AMBIENT;
out vec3 DIFFUSE;
out vec3 SPECULAR;
struct DirectionalLight {
vec3 direction;
@@ -23,7 +23,22 @@ struct DirectionalLight {
float specular;
};
struct Material {
sampler2D tex;
bool usesTex;
vec3 ambient;
vec3 diffuse;
vec3 specular;
int shininess;
float alphaScissor;
bool unshaded;
bool cullBack;
};
uniform DirectionalLight directionalLight;
uniform Material material;
void main() {
vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
@@ -34,17 +49,17 @@ void main() {
NORMAL = (VIEW * MODEL * vec4(normal, 0.0)).xyz;
// Flat shading, we compute light per vertex
AMBIENT = directionalLight.ambient * directionalLight.color;
AMBIENT = directionalLight.ambient * directionalLight.color * material.ambient;
vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz;
float diff = dot(normalize(direction), normalize(NORMAL));
diff = max(diff, 0.0);
DIFFUSE = directionalLight.diffuse * diff * directionalLight.color;
DIFFUSE = directionalLight.diffuse * diff * directionalLight.color * material.diffuse;
vec3 viewDir = (VIEW * MODEL * vec4(pos, 1.0)).xyz;
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz);
vec3 reflectionDir = reflect(normalize(direction), normalize(NORMAL));
float spec = dot(viewDir, reflectionDir);
spec = max(spec, 0.0);
spec = pow(spec, 2);
SPECULAR = directionalLight.specular * spec * directionalLight.color;
spec = pow(spec, material.shininess);
SPECULAR = directionalLight.color * (spec * material.specular);
}