1+ OF_GLSL_SHADER_HEADER
12//
23// _____ ___
34// / / / / vboMeshDrawInstancedExample
2425// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2526// THE SOFTWARE.
2627
27- #version 150
28+
29+ // #version 150
30+
2831
2932uniform mat4 projectionMatrix;
3033uniform mat4 modelViewMatrix;
3134uniform mat4 modelViewProjectionMatrix;
32- uniform vec4 globalColor = vec4 (1.0 );
35+ uniform vec4 globalColor; // = vec4(1.0);
3336uniform sampler2D tex0; // we use this to sample depth data for our boxes.
34- uniform float timeValue= 0.0 ; // we get this from our ofApp, it's a time value moving from 0 to 1 every 30 seconds
37+ uniform float timeValue; // =0.0; // we get this from our ofApp, it's a time value moving from 0 to 1 every 30 seconds
3538
3639
3740in vec4 position;
@@ -134,13 +137,18 @@ void main()
134137 // we would like to spread our primitives out evenly along the x and an y coordinates
135138 // we calculate an x and an y coordinate value based on the current instance ID
136139
137- float instanceX = float (gl_InstanceID % (iCount) - iCount/ 2 ) / 128.0 ;
138- float instanceY = float (gl_InstanceID / (iCount) - iCount/ 2 ) / 128.0 ;
140+ float instanceX = float (gl_InstanceID % (iCount) - (iCount/ 2 )) / 128.0 ;
141+ float instanceY = float (gl_InstanceID / (iCount) - (iCount/ 2 )) / 128.0 ;
142+
143+ // float instanceX = float(gl_InstanceID)/128.0-0.5;
144+ // float instanceY = float(gl_InstanceID)/128.0-0.5;
145+
146+ texCoordVarying = vec2 (0.5 ,0.5 );
139147
140148 // next we get a mix-value, based on the current instance x coordinate and time, which
141149 // will help us to achieve some animation happiness.
142150
143- float timeDependentInstanceXValue = mod (instanceX * 0.25 + timeValue * 2 , 1.0 );
151+ float timeDependentInstanceXValue = mod (instanceX * 0.25 + timeValue * 2.0 , 1.0 );
144152
145153
146154 // get pixel depth by sampling from our depth texture.
@@ -153,6 +161,7 @@ void main()
153161
154162 // set the color for this primitive based on the current pixelDepth modified by the time dependent instance x value.
155163 colorVarying = vec4 (globalColor.rgb * pixelDepth, globalColor.a) * vec4 (1.0 ,1.0 - timeDependentInstanceXValue,(instanceX + 0.5 ) ,1.0 );
164+ // colorVarying = vec4(1.0);
156165
157166 vec4 vPos = position;
158167
@@ -164,9 +173,9 @@ void main()
164173 vPos.x = vPos.x * 4.0 + snoise(vec2 (instanceX,instanceY)) * 20.0 ;
165174 vPos.y = vPos.y * 4.0 + snoise(vec2 (1.0 - instanceX,instanceY)) * 300.0 ;
166175 // this will distribute our boxes in space,
167- vPos = vPos + vec4 (instanceX* 20 * 128 ,instanceY* 10 * 128 , 0 , 0 );
176+ vPos = vPos + vec4 (instanceX* 20.0 * 128.0 ,instanceY* 10.0 * 128.0 , 0.0 , 0. 0 );
168177 vPos.z = vPos.z + snoise(vec2 (instanceX,instanceY)) * 100.0 ;
169178
170179
171- gl_Position = projectionMatrix * modelViewMatrix * vPos ;
172- }
180+ gl_Position = projectionMatrix * modelViewMatrix * vPos;
181+ }
0 commit comments