Added gamma correction, Blinn-Phong shading, and normal map support
This commit is contained in:
1 parent
e7cd6d8132
commit
6daa9d8d25
13 files changed
+101
-25
No files matched your search
@@ -16,6 +16,8 @@ struct Material {
|
||||
bool hasSpecTex;
|
||||
sampler2D specularTexture;
|
||||
float specPower;
|
||||
bool hasNormTex;
|
||||
sampler2D normalTexture;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
@@ -96,6 +98,15 @@ void main() {
|
||||
if (material.hasSpecTex)
|
||||
matSpec = texture(material.specularTexture, texCoord).rgb;
|
||||
|
||||
vec3 norm;
|
||||
if (material.hasNormTex) {
|
||||
norm = texture(material.normalTexture, texCoord).rgb;
|
||||
norm = normalize(norm * 2.0 - 1.0);
|
||||
}
|
||||
else {
|
||||
norm = normalize(normals);
|
||||
}
|
||||
|
||||
float ambientStrength = 0.2f;
|
||||
vec3 ambient = ambientStrength * matDiff;
|
||||
if (!isContinued)
|
||||
@@ -104,7 +115,6 @@ void main() {
|
||||
|
||||
if (light[i].type == 1) {
|
||||
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 * matDiff * (light[i].strength / 2.0f);
|
||||
|
||||
@@ -119,13 +129,12 @@ void main() {
|
||||
}
|
||||
if (light[i].type == 2) {
|
||||
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 * matDiff * light[i].strength;
|
||||
|
||||
vec3 viewDir = normalize(camera.pos - fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.specPower);
|
||||
vec3 halfway = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(norm, halfway), 0.0), material.specPower);
|
||||
vec3 specular = light[i].color * spec * matSpec * (light[i].strength / 2.5f);
|
||||
|
||||
float length = length(light[i].pos - fragPos);
|
||||
@@ -136,5 +145,8 @@ void main() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//TODO: Move this to a post-processing pass
|
||||
float gamma = 2.2;
|
||||
color.rgb = pow(color.rgb, vec3(1.0 / gamma));
|
||||
outColor = vec4(color, 1.0);
|
||||
}
|
||||
@@ -5,10 +5,13 @@ in vec2 texCoord;
|
||||
uniform sampler2D tex;
|
||||
uniform float opacity;
|
||||
|
||||
out vec4 color;
|
||||
out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture(tex, texCoord);
|
||||
|
||||
color = vec4(texColor.rgb, texColor.a * opacity);
|
||||
}
|
||||
vec4 color = texColor;
|
||||
//TODO: Move this to a post-processing pass too
|
||||
float gamma = 2.2;
|
||||
color.rgb = pow(color.rgb, vec3(1.0 / gamma));
|
||||
outColor = vec4(color.rgb, texColor.a * opacity);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl mat
|
||||
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,17 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib normal.mtl
|
||||
o Plane_Plane.001
|
||||
v -1.000000 -1.000000 -0.000000
|
||||
v 1.000000 -1.000000 -0.000000
|
||||
v -1.000000 1.000000 0.000000
|
||||
v 1.000000 1.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vn 0.0000 -0.0000 1.0000
|
||||
usemtl mat
|
||||
s off
|
||||
f 2/1/1 3/2/1 1/3/1
|
||||
f 2/1/1 4/4/1 3/2/1
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 559 KiB |
@@ -69,7 +69,10 @@ void getNeededImages(std::string mtl, std::set<std::string>& set) {
|
||||
unsigned int pos = mtl.find("map_");
|
||||
if (pos == std::string::npos)
|
||||
break;
|
||||
mtl = mtl.substr(pos + 7);
|
||||
if (pos == mtl.find("map_Kd") || pos == mtl.find("map_Ks"))
|
||||
mtl = mtl.substr(pos + 7);
|
||||
else
|
||||
mtl = mtl.substr(pos + 9);
|
||||
std::stringstream ss(mtl);
|
||||
std::string temp;
|
||||
ss >> temp;
|
||||
@@ -140,7 +143,7 @@ int main(int argc, char* argv[]) {
|
||||
getNeededImages(mtlContents, neededImages);
|
||||
if (!neededImages.empty()) {
|
||||
currFileContents.insert(0, "\n");
|
||||
for(std::string curr : neededImages) {
|
||||
for (std::string curr : neededImages) {
|
||||
currFileContents.insert(0, curr);
|
||||
currFileContents.insert(0, " ");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user