Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 0888217

Browse files
committed
Implemented Basic Subdivision
- normals are not yet interpolated - torus does not yet have normals
1 parent 088cd8b commit 0888217

17 files changed

Lines changed: 605 additions & 270 deletions

File tree

38.8 MB
Binary file not shown.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#version 150
2+
// GLSL version 1.50
3+
// Fragment shader for diffuse shading in combination with a texture map
4+
5+
// Uniform variables passed in from host program
6+
uniform sampler2D myTexture;
7+
8+
// Variables passed in from the vertex shader
9+
in float ndotl;
10+
in vec3 lightingSum;
11+
in vec2 frag_texcoord;
12+
in vec3 normal_out;
13+
14+
// Output variable, will be written to framebuffer automatically
15+
out vec4 frag_shaded;
16+
17+
void main()
18+
{
19+
/*int numShades = 10;
20+
vec3 shadeIntensity = ceil(lightingSum * numShades)/numShades;*/
21+
// The built-in GLSL function "texture" performs the texture lookup
22+
vec4 values = vec4(lightingSum, 0) * texture(myTexture, frag_texcoord);
23+
24+
if (values.x > 0.9)
25+
values.x = 1;
26+
else if (values.x > 0.5)
27+
values.x = 0.7;
28+
else if (values.x > 0.25)
29+
values.x = 0.3;
30+
else if (values.x < 0.25)
31+
values.x = 0.15;
32+
33+
if (values.y > 0.9)
34+
values.y = 1;
35+
else if (values.y > 0.5)
36+
values.y = 0.7;
37+
else if (values.y > 0.25)
38+
values.y = 0.3;
39+
else if (values.y < 0.25)
40+
values.y = 0.15;
41+
42+
if (values.z > 0.9)
43+
values.z = 1;
44+
else if (values.z > 0.5)
45+
values.z = 0.7;
46+
else if (values.z > 0.25)
47+
values.z = 0.3;
48+
else if (values.z < 0.25)
49+
values.z = 0.15;
50+
51+
52+
frag_shaded.x = values.x ;
53+
frag_shaded.y = values.y ;
54+
frag_shaded.z = values.z ;
55+
56+
//frag_shaded = values * shadeIntensity;
57+
//frag_shaded = vec4(normal_out, 1);
58+
}
59+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#version 150
2+
// GLSL version 1.50
3+
// Vertex shader for diffuse shading in combination with a texture map
4+
5+
#define MAX_LIGHTS 8
6+
7+
// Uniform variables, passed in from host program via suitable
8+
// variants of glUniform*
9+
uniform mat4 projection;
10+
uniform mat4 modelview;
11+
uniform vec4 lightDirection[MAX_LIGHTS];
12+
uniform vec4 lightPosition[MAX_LIGHTS];
13+
uniform vec3 lightColorDiffuse[MAX_LIGHTS];
14+
uniform vec3 materialColorDiffuse;
15+
uniform int nLights;
16+
17+
// Input vertex attributes; passed in from host program to shader
18+
// via vertex buffer objects
19+
in vec3 normal;
20+
in vec4 position;
21+
in vec2 texcoord;
22+
23+
// Output variables for fragment shader
24+
out vec3 lightingSum;
25+
out float ndotl;
26+
out vec2 frag_texcoord;
27+
out vec3 normal_out;
28+
29+
void main()
30+
{
31+
// Compute dot product of normal and light direction
32+
// and pass color to fragment shader
33+
// Note: here we assume "lightDirection" is specified in camera coordinates,
34+
// so we transform the normal to camera coordinates, and we don't transform
35+
// the light direction, i.e., it stays in camera coordinates
36+
37+
//ndotl = max(dot(modelview * vec4(normal,0), lightDirection[0]),0);
38+
39+
vec3 temp;
40+
normal_out = normal;
41+
42+
for (int i = 0; i < nLights; i++) {
43+
// Calculate the light distance and direction to the vertex.
44+
//float distance = length(lightPosition[i] - position);
45+
vec4 lightVector = normalize(lightPosition[i] - position);
46+
47+
ndotl = max(dot(modelview * vec4(normal,0), lightVector), 0.0);
48+
49+
temp += (lightColorDiffuse[i] * materialColorDiffuse * ndotl);
50+
}
51+
52+
lightingSum = temp;
53+
54+
// Pass texture coordiantes to fragment shader, OpenGL automatically
55+
// interpolates them to each pixel (in a perspectively correct manner)
56+
frag_texcoord = texcoord;
57+
58+
// Transform position, including projection matrix
59+
// Note: gl_Position is a default output variable containing
60+
// the transformed vertex position
61+
gl_Position = projection * modelview * position;
62+
}

S4/Computergrafik-Basecode-master/jrtr/shaders/diffuse.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main()
4242
for (int i = 0; i < nLights; i++) {
4343
// Calculate the light distance and direction to the vertex.
4444
//float distance = length(lightPosition[i] - position);
45-
vec4 lightVector = normalize(lightPosition[i] - position);
45+
vec4 lightVector = normalize(lightPosition[i] - modelview * position);
4646

4747
ndotl = max(dot(modelview * vec4(normal,0), lightVector), 0.0);
4848

S4/Computergrafik-Basecode-master/jrtr/shaders/discard.frag

Lines changed: 0 additions & 23 deletions
This file was deleted.

S4/Computergrafik-Basecode-master/jrtr/shaders/discard.vert

Lines changed: 0 additions & 30 deletions
This file was deleted.

S4/Computergrafik-Basecode-master/jrtr/shaders/phong.frag

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ void main()
3333
{
3434
vec3 lightSum, lightDiffuse, lightSpecular;
3535
vec4 position = modelview * frag_position;
36-
vec3 normal = frag_normal;
36+
vec3 normal = normalize(frag_normal);
3737

3838
for (int i = 0; i < nLights; i++) {
39-
vec4 lightVector = normalize(lightPosition[i] - position);
39+
vec4 lightVector = (lightPosition[i] - position);
4040

4141
float ndotl = max(dot(modelview * vec4(normal,0), lightVector), 0.0);
4242

4343
vec4 R = reflect(-lightVector, modelview * vec4(normal,0));
4444
vec4 e = normalize(vec4(centerOfProjection,0) - position);
45-
float Rep = pow(max(dot(R, e), 0.0), materialShininess);
45+
float Rep = pow(max(dot(normalize(R), e), 0.0), materialShininess);
4646

4747
lightDiffuse += (lightColorDiffuse[i] * materialColorDiffuse * ndotl);
4848
lightSpecular += (lightColorSpecular[i] * materialColorSpecular * Rep);

S4/Computergrafik-Basecode-master/jrtr/shaders/phong_texture.frag

Lines changed: 0 additions & 70 deletions
This file was deleted.

S4/Computergrafik-Basecode-master/jrtr/shaders/phong_texture.vert

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)