Skip to content

Commit

Permalink
Add instancing grass demo
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Feb 20, 2017
1 parent 39b0244 commit 1a4879c
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 0 deletions.
5 changes: 5 additions & 0 deletions res/org/lwjgl/demo/opengl/instancing/CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The following textures are made by Reiner Prokein and can be found on [http://www.reinerstilesets.de/new-textures-billboard-grass/]:
- grass_flower_blue.png
- grass_flower.png
- grass.png
- grass2.png
36 changes: 36 additions & 0 deletions res/org/lwjgl/demo/opengl/instancing/grass.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: http://lwjgl.org/license.php
*/
#version 110

uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;

varying vec2 texCoordVarying;
varying float yVarying;
varying vec3 normalVarying;
varying float texIndexVarying;

const vec3 LIGHT_DIR = normalize(vec3(0.1, 1, 0.1));

void main(void) {
vec3 n = normalize(normalVarying);
float dot = max(0.0, dot(LIGHT_DIR, n));
vec4 col;
int texIndexVaryingI = int(texIndexVarying);
if (texIndexVaryingI == 0)
col = texture2D(tex0, texCoordVarying);
else if (texIndexVaryingI == 1)
col = texture2D(tex1, texCoordVarying);
else if (texIndexVaryingI == 2)
col = texture2D(tex2, texCoordVarying);
else
col = texture2D(tex3, texCoordVarying);
col.rgb *= yVarying;
if (col.a < 0.8)
discard;
gl_FragColor = vec4(col.rgb * dot, col.a);
}
Binary file added res/org/lwjgl/demo/opengl/instancing/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions res/org/lwjgl/demo/opengl/instancing/grass.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: http://lwjgl.org/license.php
*/
#version 110
#extension GL_NV_non_square_matrices : enable

attribute vec3 position;
attribute vec2 texCoord;
attribute vec2 displacement;
attribute vec4 worldPosition;
attribute vec4 rotation;

uniform mat4 vpMatrix;

varying vec2 texCoordVarying;
varying float yVarying;
varying vec3 normalVarying;
varying float texIndexVarying;

void main(void) {
texCoordVarying = texCoord;
texIndexVarying = worldPosition.w * worldPosition.w * 4.0;
yVarying = position.y;
vec3 spos = position;
spos.y *= worldPosition.z;
vec2 pos = spos.xz;
mat2x2 rot = mat2x2(rotation.x, rotation.y, rotation.z, rotation.w);
pos = rot * pos;
pos += displacement * yVarying;
pos += worldPosition.xy;
normalVarying = vec3(0.0, 1.0, 0.0);
normalVarying.xz += displacement * yVarying;
gl_Position = vpMatrix * vec4(pos.x, spos.y, pos.y, 1.0);
}
Binary file added res/org/lwjgl/demo/opengl/instancing/grass2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions res/org/lwjgl/demo/opengl/instancing/ground.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: http://lwjgl.org/license.php
*/
#version 110

void main(void) {
gl_FragColor = vec4(0.2, 0.2, 0.13, 1.0);
}
19 changes: 19 additions & 0 deletions res/org/lwjgl/demo/opengl/instancing/ground.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: http://lwjgl.org/license.php
*/
#version 110

attribute vec2 position;

uniform mat4 vpMatrix;
uniform float groundSize;

varying vec2 texCoordVarying;

void main(void) {
texCoordVarying = position * groundSize;
vec2 pos = position * 2.0 - vec2(1.0, 1.0);
pos *= groundSize;
gl_Position = vpMatrix * vec4(pos.x, 0.0, pos.y, 1.0);
}
Loading

0 comments on commit 1a4879c

Please sign in to comment.