-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshaders.h
More file actions
116 lines (105 loc) · 3.78 KB
/
shaders.h
File metadata and controls
116 lines (105 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
////////////////////////////////////////////////////////////////////
//
// $Id: shaders.h 2021/06/05 13:13:31 kanai Exp $
//
// Copyright (c) 2021 Takashi Kanai
// Released under the MIT license
//
////////////////////////////////////////////////////////////////////
#ifndef _SHADERS_H
#define _SHADERS_H 1
// same as texture.vert
static const GLchar *vertex_shader_Texture_source =
"#version 120\n"
"varying vec4 position;"
"varying vec3 normal;"
"void main(void)"
"{"
"position = gl_ModelViewMatrix * gl_Vertex;"
"normal = normalize(gl_NormalMatrix * gl_Normal);"
"gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
"gl_Position = ftransform();"
"}\0";
// same as texture.frag
static const GLchar *fragment_shader_Texture_source =
"#version 120\n"
"uniform sampler2D texture;"
"varying vec4 position;"
"varying vec3 normal;"
"void main (void)"
"{"
"vec4 color = texture2DProj(texture, gl_TexCoord[0]);"
"vec3 fnormal = normalize(normal);"
"vec3 light = normalize((gl_LightSource[0].position * position.w - gl_LightSource[0].position.w * position).xyz);"
"vec3 view = -normalize(position.xyz);"
"vec3 halfway = normalize(light + view);"
"float diffuse = max(dot(fnormal, light), 0.0);"
"float specular = pow(max(dot(fnormal, halfway), 0.0), gl_FrontMaterial.shininess);"
"gl_FragColor = gl_LightSource[0].ambient * color + gl_LightSource[0].diffuse * diffuse * color + gl_FrontLightProduct[0].specular * specular;"
"}\0";
// same as phong.vert
static const GLchar *vertex_shader_Phong_source =
"#version 120\n"
"varying vec4 position;"
"varying vec3 normal;"
"void main(void)"
"{"
"position = gl_ModelViewMatrix * gl_Vertex;"
"normal = normalize(gl_NormalMatrix * gl_Normal);"
"gl_Position = ftransform();"
"}\0";
// same as phong.frag
static const GLchar *fragment_shader_Phong_source =
"#version 120\n"
"varying vec4 position;"
"varying vec3 normal;"
"void main (void)"
"{"
"vec3 fnormal = normalize(normal);"
"vec3 light = normalize((gl_LightSource[0].position * position.w - gl_LightSource[0].position.w * position).xyz);"
"vec3 view = -normalize(position.xyz);"
"vec3 halfway = normalize(light + view);"
"float diffuse = max(dot(fnormal, light), 0.0);"
"float specular = pow(max(dot(fnormal, halfway), 0.0), gl_FrontMaterial.shininess);"
"gl_FragColor = gl_FrontLightProduct[0].ambient + gl_FrontLightProduct[0].diffuse * diffuse + gl_FrontLightProduct[0].specular * specular;"
"}\0";
static const GLchar *vertex_shader_Gourand_source =
"#version 120\n"
"void main(void)"
"{"
"vec4 position = gl_ModelViewMatrix * gl_Vertex;"
"vec3 normal = normalize(gl_NormalMatrix * gl_Normal);"
"vec3 light = normalize((gl_LightSource[0].position * position.w - gl_LightSource[0].position.w * position).xyz);"
"vec3 view = -normalize(position.xyz);"
"vec3 halfway = normalize(light + view);"
"float diffuse = max(dot(light, normal), 0.0);"
"float specular = pow(max(dot(normal, halfway), 0.0), gl_FrontMaterial.shininess);"
"gl_FrontColor = gl_FrontLightProduct[0].ambient + gl_FrontLightProduct[0].diffuse * diffuse + gl_FrontLightProduct[0].specular * specular;"
"gl_Position = ftransform();"
"}\0";
static const GLchar *fragment_shader_Gourand_source =
"#version 120\n"
"void main (void)"
"{"
"gl_FragColor = gl_Color;"
"}\0";
static const GLchar *vertex_wireframe_source =
"#version 120\n"
"varying vec4 position;"
"void main(void)"
"{"
"position = gl_ModelViewMatrix * gl_Vertex;"
"gl_Position = ftransform();"
"gl_FrontColor = gl_Color;"
"}\0";
static const GLchar *fragment_wireframe_source =
"#version 120\n"
"void main (void)"
"{"
"gl_FragColor = gl_Color;"
"}\0";
#define PHONG_SHADING 0
#define GOURAND_SHADING 1
#define WIREFRAME 2
#define PHONG_TEXTURE 3
#endif // _SHADERS_H