-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from tomasz-herman/develop
Develop
- Loading branch information
Showing
52 changed files
with
1,959 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020-2021 Tomasz Herman, Karol Krupa, Paweł Flis | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,84 @@ | ||
#version 330 core | ||
#define MAX_LIGHTS 5 | ||
#define MATERIALS 3 | ||
|
||
struct Light | ||
{ | ||
vec3 position; | ||
|
||
vec3 diffuse; | ||
}; | ||
|
||
struct Material | ||
{ | ||
float part; | ||
int useColor; | ||
vec3 color; | ||
sampler2D texture; | ||
}; | ||
|
||
in vec2 texCoord; | ||
out vec4 FragColor; | ||
|
||
in vec2 texCoord; | ||
in vec3 Normal; | ||
in vec3 FragPos; | ||
|
||
uniform int lightsCount; | ||
uniform Material materials[MATERIALS]; | ||
uniform Light light[MAX_LIGHTS]; | ||
uniform vec3 ambientLight; | ||
uniform vec3 cameraPosition; | ||
uniform float disturbance; | ||
|
||
vec3 Phong(); | ||
vec4 GetMaterialColor(Material material); | ||
float Attenuation(float dist); | ||
vec4 Clamp(vec4 vec); | ||
vec3 Clamp(vec3 vec); | ||
|
||
void main() | ||
{ | ||
FragColor = vec4(0.0f, texCoord, 0.0f); | ||
FragColor = vec4(Phong(), 1.0); | ||
} | ||
|
||
vec3 Phong() { | ||
vec4 ambient = Clamp(GetMaterialColor(materials[0])); | ||
vec4 diffuse = GetMaterialColor(materials[1]); | ||
vec4 specular = GetMaterialColor(materials[2]); | ||
|
||
vec3 normal = normalize(Normal); | ||
vec3 viewDirection = normalize(cameraPosition - vec3(FragPos)); | ||
|
||
vec3 a = vec3(ambient), d = vec3(diffuse) * ambientLight, s = vec3(0); | ||
|
||
// Point lights | ||
for (int i = 0; i < lightsCount; i++) { | ||
float lightDistance = length(vec3(light[i].position) - FragPos); | ||
vec3 lightDir = normalize(light[i].position - FragPos); | ||
float diff = max(dot(normal, lightDir), 0.0); | ||
d += Clamp(light[i].diffuse) * diff * vec3(diffuse); | ||
vec3 reflectDir = reflect(-lightDir, normal); | ||
float reflectAngle = max(dot(reflectDir, viewDirection), 0); | ||
s += vec3(specular * pow(reflectAngle, 1 + (1-disturbance)*99)); | ||
} | ||
|
||
return a * materials[0].part + d * materials[1].part + s * materials[2].part; | ||
} | ||
|
||
vec4 GetMaterialColor(Material material) | ||
{ | ||
return material.useColor == 1 ? vec4(material.color, 1.0) : texture(material.texture, texCoord); | ||
} | ||
|
||
float Attenuation(float dist) | ||
{ | ||
return 1 + 0.007 * dist + 0.0002 * dist * dist; | ||
} | ||
|
||
vec3 Clamp(vec3 vec) { | ||
return vec3(clamp(vec.x, 0, 1), clamp(vec.y, 0, 1), clamp(vec.z, 0, 1)); | ||
} | ||
|
||
vec4 Clamp(vec4 vec) { | ||
return vec4(clamp(vec.x, 0, 1), clamp(vec.y, 0, 1), clamp(vec.z, 0, 1), clamp(vec.w, 0, 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
#version 330 core | ||
layout (location = 0) in vec3 aPosition; | ||
layout (location = 1) in vec3 aNormal; | ||
layout (location = 2) in vec2 aTexCoord; | ||
|
||
out vec2 texCoord; | ||
out vec3 Normal; | ||
out vec3 FragPos; | ||
|
||
uniform mat4 model; | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
uniform mat4 mvp; | ||
|
||
out vec2 texCoord; | ||
void main() | ||
void main(void) | ||
{ | ||
texCoord = aTexCoord; | ||
mat4 vp = view * projection; | ||
gl_Position = vec4(aPosition, 1.0) * model * vp ; | ||
Normal = aNormal * mat3(model); | ||
FragPos = vec3(vec4(aPosition, 1.0)*model); | ||
|
||
gl_Position = vec4(aPosition, 1.0)*mvp; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.