-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.frag
More file actions
36 lines (29 loc) · 1.1 KB
/
texture.frag
File metadata and controls
36 lines (29 loc) · 1.1 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
////////////////////////////////////////////////////////////////////
//
// $Id: texture.frag 2021/06/05 13:11:54 kanai Exp $
//
// Copyright (c) 2021 Takashi Kanai
// Released under the MIT license
//
////////////////////////////////////////////////////////////////////
#version 120
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;
}