-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgouraud.vert
More file actions
32 lines (27 loc) · 1.05 KB
/
gouraud.vert
File metadata and controls
32 lines (27 loc) · 1.05 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
////////////////////////////////////////////////////////////////////
//
// $Id: gouraud.vert 2021/06/05 13:18:53 kanai Exp $
//
// Copyright (c) 2021 Takashi Kanai
// Released under the MIT license
//
////////////////////////////////////////////////////////////////////
#version 120
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();
}