-
Notifications
You must be signed in to change notification settings - Fork 26
/
shaders.h
85 lines (81 loc) · 2.24 KB
/
shaders.h
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
// Copyright 2017 OpenSWE1R Maintainers
// Licensed under GPLv2 or any later version
// Refer to the included LICENSE.txt file.
#ifndef __OPENSWE1R_SHADERS_H__
#define __OPENSWE1R_SHADERS_H__
static const char* VertexShader1Texture =
"#version 330\n"
"\n"
"uniform mat4 projectionMatrix;\n"
"\n"
"uniform vec3 clipScale;\n"
"uniform vec3 clipOffset;\n"
"\n"
"in vec4 positionIn;\n"
"in vec4 diffuseIn;\n"
"in vec4 specularIn;\n"
"in vec2 uv0In;\n"
"\n"
"out vec4 diffuse;\n"
"out vec4 specular;\n"
"out vec2 uv0;\n"
"\n"
"void main() {\n"
" gl_Position = vec4(positionIn.xyz * clipScale + clipOffset, 1.0);\n"
" gl_Position /= positionIn.w;\n"
" gl_Position.y = -gl_Position.y;\n"
" diffuse = diffuseIn.bgra;\n"
" specular = specularIn.bgra;\n"
" uv0 = uv0In;\n"
"}";
static const char* FragmentShader1Texture =
"#version 330\n"
"\n"
"bool tex0HasAlpha = true;\n"
"\n"
"uniform int tex0Blend;\n"
"uniform sampler2D tex0;\n"
"uniform bool alphaTest;\n"
"uniform int fogMode;\n"
"uniform float fogStart;\n"
"uniform float fogEnd;\n"
"uniform vec3 fogColor;\n"
"\n"
"in vec4 diffuse;\n"
"in vec4 specular;\n"
"in vec2 uv0;\n"
"\n"
"out vec4 color;\n"
#if 0
"\n"
"uniform sampler2D tex0;\n"
#endif
"\n"
"void main() {\n"
" vec4 tex = texture(tex0, uv0);\n"
" vec4 src = diffuse;\n"
" if (tex0Blend == 2) {\n" // D3DTBLEND_MODULATE
" color.rgb = src.rgb * tex.rgb;\n"
" if (tex0HasAlpha) {\n"
" color.a = tex.a;\n"
" } else {\n"
" color.a = src.a;\n"
" }\n"
" } else if (tex0Blend == 4) {\n" // D3DTBLEND_MODULATEALPHA
" color.rgb = src.rgb * tex.rgb;\n"
" color.a = src.a * tex.a;\n"
" } else {\n" // Unknown blend mode; Signals error by choosing a pink color
" color = vec4(1.0, 0.0, 1.0, 0.5);\n"
" }\n"
" if (alphaTest && !(int(round(color.a * 255.0)) != 0)) { discard; }\n"
" if (fogMode == 0) {\n" // D3DFOG_NONE
" color.rgb = color.rgb;\n"
" } else if (fogMode == 3) {\n" // D3DFOG_LINEAR
" float fogVisibility = (fogEnd - gl_FragCoord.z / gl_FragCoord.w) / (fogEnd - fogStart);\n"
" fogVisibility = clamp(fogVisibility, 0.0, 1.0);\n"
" color.rgb = mix(fogColor, color.rgb, fogVisibility);\n"
" } else {\n" // Unknown fog mode; Signal error by coloring primitive green
" color.rgb = vec3(0.0, 1.0, 0.0);\n"
" }\n"
"}\n";
#endif