aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/sokol/05_instancing_glsl/rt_glsl_instancing.glsl
blob: 0e780b3f682d2bc46ba3b0461689105f200a0389 (plain)
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
//------------------------------------------------------------------------------
//  Shader code for texcube-sapp sample.
//
//  NOTE: This source file also uses the '#pragma sokol' form of the
//  custom tags.
//------------------------------------------------------------------------------
//#pragma sokol @ctype mat4 hmm_mat4

#pragma sokol @vs vs_i
uniform vs_params_i {
    mat4 mvp;
};

in vec4 pos;
in vec4 color0;
in vec2 texcoord0;

in vec4 inst_pos;

out vec4 color;
out vec4 color_inst;
out vec2 uv;

const vec4 palette[10] = vec4[10](
	vec4(1,0,0,1),
	vec4(0,1,0,1),
	vec4(0,0,1,1),
	vec4(1,1,0,1),
	vec4(0,1,1,1),
	vec4(1,1,1,1),
	vec4(0,0,0,1),
	vec4(0.2,0.2,0.2,1),
	vec4(0.3,0.3,0.3,1),
	vec4(0.9,0.9,0.9,1)
);

void main() {
		vec4 delta_pos = vec4(inst_pos.xyz,0);
		float w = inst_pos.w;
		color_inst = palette[int(w)];
    gl_Position = mvp * (pos + delta_pos);
    color = color0;
    uv = texcoord0/4;
}
#pragma sokol @end

#pragma sokol @fs fs_i
uniform sampler2D tex;

in vec4 color;
in vec4 color_inst;
in vec2 uv;
out vec4 frag_color;

void main() {
	vec4 c = color;
	vec4 txt = texture(tex, uv);
	c = txt * c * color_inst;	
	frag_color = c ;
}

#pragma sokol @end

#pragma sokol @program instancing vs_i fs_i