Skip to content

Commit

Permalink
[ADD] new scene.
Browse files Browse the repository at this point in the history
  • Loading branch information
SighingSnow committed Jul 17, 2022
1 parent e631e53 commit bd560d9
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 113 deletions.
6 changes: 3 additions & 3 deletions src/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ enum Camera_Movement {

// Default camera values
const float YAW = -90.0f;
const float PITCH = 0.0f;
const float SPEED = 7.0f;
const float SENSITIVITY = 0.0005f;
const float PITCH = -14.0f;
const float SPEED = 0.5f;
const float SENSITIVITY = 0.005f;
const float ZOOM = 45.0f;


Expand Down
30 changes: 2 additions & 28 deletions src/Shaders/Cube.fs
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
#version 330 core
out vec4 FragColor;

in vec3 Normal;
in vec3 FragPos;

uniform vec3 lightPos;
uniform vec3 viewPos;
uniform vec3 lightColor;
uniform vec3 objectColor;

void main()
{
// ambient
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * lightColor;

// diffuse
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diff * lightColor;

// specular
float specularStrength = 0.5;
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = specularStrength * spec * lightColor;

vec3 result = (ambient + diffuse + specular) * objectColor;
FragColor = vec4(result, 1.0);
}
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
}
9 changes: 1 addition & 8 deletions src/Shaders/Cube.vs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;

out vec3 FragPos;
out vec3 Normal;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;

gl_Position = projection * view * vec4(FragPos, 1.0);
gl_Position = projection * view * model * vec4(aPos, 1.0);
}
45 changes: 45 additions & 0 deletions src/Shaders/mcube.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#version 330 core
out vec4 FragColor;

struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};

struct Light {
vec3 position;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

in vec3 FragPos;
in vec3 Normal;

uniform vec3 viewPos;
uniform Material material;
uniform Light light;

void main()
{
// ambient
vec3 ambient = light.ambient * material.ambient;

// diffuse
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(light.position - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = light.diffuse * (diff * material.diffuse);

// specular
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * (spec * material.specular);

vec3 result = ambient + diffuse + specular;
FragColor = vec4(result, 1.0);
}
18 changes: 18 additions & 0 deletions src/Shaders/mcube.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;

out vec3 FragPos;
out vec3 Normal;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;

gl_Position = projection * view * vec4(FragPos, 1.0);
}
8 changes: 6 additions & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ const int inlinesize[2] = {SCR_WIDTH*3,0}; // For sws_scale convert function
static const char* rtmp_fout_name = "rtsp://localhost/livestream/live";

// OpenGL parameters
static const char* vs = "../src/Shaders/Cube.vs";
static char* fs = "../src/Shaders/Cube.fs";
const std::string cube_vs = "../src/Shaders/cube.vs";
const std::string cube_fs = "../src/Shaders/cube.fs";
const std::string mcube_vs = "../src/Shaders/mcube.vs";
const std::string mcube_fs = "../src/Shaders/mcube.fs";
const std::string text_vs = "../src/Shaders/text.vs";
const std::string text_fs = "../src/Shaders/text.fs";

const float vertices[] = {
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
Expand Down
Loading

0 comments on commit bd560d9

Please sign in to comment.