-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: shaders can be read from file
- Loading branch information
1 parent
609a13e
commit 84aa351
Showing
8 changed files
with
126 additions
and
95 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
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,25 @@ | ||
|
||
#ifndef TOOLS_H | ||
#define TOOLS_H | ||
|
||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
||
std::string read_file(const std::string& file_name) | ||
{ | ||
std::ifstream ifs(file_name.c_str(), std::ios::in | std::ios::binary | | ||
std::ios::ate); | ||
|
||
std::ifstream::pos_type file_size = ifs.tellg(); | ||
ifs.seekg(0, std::ios::beg); | ||
|
||
std::vector<char> bytes(file_size); | ||
ifs.read(&bytes[0], file_size); | ||
|
||
return std::string(&bytes[0], file_size); | ||
} | ||
|
||
|
||
#endif |
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,20 @@ | ||
|
||
#version 330 | ||
|
||
//in vec4 vCol; | ||
flat in vec3 vNormal; | ||
|
||
out vec4 color; | ||
|
||
void main() | ||
{ | ||
const vec3 lightDir = normalize(vec3(1,.5,.5)); | ||
|
||
//float c = clamp(dot(lightDir,triNormal), 0, 1); | ||
vec3 n = normalize(vNormal); | ||
float c = abs( dot(lightDir, n) ); | ||
color = vec4(.2, .2,0,1) + 0.8*vec4(c,c,0,1); | ||
|
||
//color = vec4(1,1,0,1); | ||
//color = vCol; | ||
} |
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,24 @@ | ||
|
||
#version 330 | ||
|
||
in vec3 vpos[]; | ||
out vec4 vCol; | ||
|
||
layout (triangles) in; | ||
layout (triangle_strip, max_vertices = 3) out; | ||
|
||
void main() | ||
{ | ||
const vec3 lightDir = normalize(vec3(1,.5,.5)); | ||
|
||
// compute the normal for the current triangle | ||
vec3 triNormal = normalize(cross(vpos[1]-vpos[0], vpos[2]-vpos[0])); | ||
//float c = clamp(dot(lightDir,triNormal), 0, 1); | ||
float c = abs(dot(lightDir,triNormal)); | ||
vCol = vec4(.2, .2,0,1) + vec4(c,c,0,1); | ||
|
||
gl_Position = gl_in[0].gl_Position; EmitVertex(); | ||
gl_Position = gl_in[1].gl_Position; EmitVertex(); | ||
gl_Position = gl_in[2].gl_Position; EmitVertex(); | ||
EndPrimitive(); | ||
} |
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,19 @@ | ||
|
||
#version 330 | ||
|
||
layout (location = 0) in vec3 pos; | ||
layout (location = 1) in vec3 normal; | ||
|
||
//out vec4 vCol; | ||
//out vec3 vpos; | ||
flat out vec3 vNormal; | ||
|
||
uniform mat4 MVP; | ||
|
||
void main() | ||
{ | ||
//vpos = pos; | ||
vNormal = normal; | ||
gl_Position = MVP * vec4(pos.xyz, 1); | ||
//gl_Position = vec4(pos.xyz, 1); | ||
} |