Skip to content

Commit 1a4879c

Browse files
committed
Add instancing grass demo
1 parent 39b0244 commit 1a4879c

File tree

10 files changed

+485
-0
lines changed

10 files changed

+485
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The following textures are made by Reiner Prokein and can be found on [http://www.reinerstilesets.de/new-textures-billboard-grass/]:
2+
- grass_flower_blue.png
3+
- grass_flower.png
4+
- grass.png
5+
- grass2.png
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright LWJGL. All rights reserved.
3+
* License terms: http://lwjgl.org/license.php
4+
*/
5+
#version 110
6+
7+
uniform sampler2D tex0;
8+
uniform sampler2D tex1;
9+
uniform sampler2D tex2;
10+
uniform sampler2D tex3;
11+
12+
varying vec2 texCoordVarying;
13+
varying float yVarying;
14+
varying vec3 normalVarying;
15+
varying float texIndexVarying;
16+
17+
const vec3 LIGHT_DIR = normalize(vec3(0.1, 1, 0.1));
18+
19+
void main(void) {
20+
vec3 n = normalize(normalVarying);
21+
float dot = max(0.0, dot(LIGHT_DIR, n));
22+
vec4 col;
23+
int texIndexVaryingI = int(texIndexVarying);
24+
if (texIndexVaryingI == 0)
25+
col = texture2D(tex0, texCoordVarying);
26+
else if (texIndexVaryingI == 1)
27+
col = texture2D(tex1, texCoordVarying);
28+
else if (texIndexVaryingI == 2)
29+
col = texture2D(tex2, texCoordVarying);
30+
else
31+
col = texture2D(tex3, texCoordVarying);
32+
col.rgb *= yVarying;
33+
if (col.a < 0.8)
34+
discard;
35+
gl_FragColor = vec4(col.rgb * dot, col.a);
36+
}
653 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright LWJGL. All rights reserved.
3+
* License terms: http://lwjgl.org/license.php
4+
*/
5+
#version 110
6+
#extension GL_NV_non_square_matrices : enable
7+
8+
attribute vec3 position;
9+
attribute vec2 texCoord;
10+
attribute vec2 displacement;
11+
attribute vec4 worldPosition;
12+
attribute vec4 rotation;
13+
14+
uniform mat4 vpMatrix;
15+
16+
varying vec2 texCoordVarying;
17+
varying float yVarying;
18+
varying vec3 normalVarying;
19+
varying float texIndexVarying;
20+
21+
void main(void) {
22+
texCoordVarying = texCoord;
23+
texIndexVarying = worldPosition.w * worldPosition.w * 4.0;
24+
yVarying = position.y;
25+
vec3 spos = position;
26+
spos.y *= worldPosition.z;
27+
vec2 pos = spos.xz;
28+
mat2x2 rot = mat2x2(rotation.x, rotation.y, rotation.z, rotation.w);
29+
pos = rot * pos;
30+
pos += displacement * yVarying;
31+
pos += worldPosition.xy;
32+
normalVarying = vec3(0.0, 1.0, 0.0);
33+
normalVarying.xz += displacement * yVarying;
34+
gl_Position = vpMatrix * vec4(pos.x, spos.y, pos.y, 1.0);
35+
}
645 KB
Loading
796 KB
Loading
809 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright LWJGL. All rights reserved.
3+
* License terms: http://lwjgl.org/license.php
4+
*/
5+
#version 110
6+
7+
void main(void) {
8+
gl_FragColor = vec4(0.2, 0.2, 0.13, 1.0);
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright LWJGL. All rights reserved.
3+
* License terms: http://lwjgl.org/license.php
4+
*/
5+
#version 110
6+
7+
attribute vec2 position;
8+
9+
uniform mat4 vpMatrix;
10+
uniform float groundSize;
11+
12+
varying vec2 texCoordVarying;
13+
14+
void main(void) {
15+
texCoordVarying = position * groundSize;
16+
vec2 pos = position * 2.0 - vec2(1.0, 1.0);
17+
pos *= groundSize;
18+
gl_Position = vpMatrix * vec4(pos.x, 0.0, pos.y, 1.0);
19+
}

0 commit comments

Comments
 (0)