Skip to content

Commit ea66160

Browse files
authored
[Fix] improve compatibility of example with older mobile devices (playcanvas#2348)
1 parent 3e9ccc9 commit ea66160

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

examples/graphics/hardware-instancing.html

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,38 +87,40 @@
8787
// add the box entity to the hierarchy
8888
app.root.addChild(box);
8989

90-
// number of instances to render
91-
var instanceCount = 1000;
92-
93-
// store matrices for individual instances into array
94-
var matrices = new Float32Array(instanceCount * 16);
95-
var matrixIndex = 0;
96-
97-
var radius = 5;
98-
var pos = new pc.Vec3();
99-
var rot = new pc.Quat();
100-
var scl = new pc.Vec3();
101-
var matrix = new pc.Mat4();
102-
103-
for (var i = 0; i < instanceCount; i++) {
104-
// generate random positions / scales and rotations
105-
pos.set(Math.random() * radius - radius * 0.5, Math.random() * radius - radius * 0.5, Math.random() * radius - radius * 0.5);
106-
scl.set(0.1 + Math.random() * 0.1, 0.1 + Math.random() * 0.3, 0.1 + Math.random() * 0.1);
107-
rot.setFromEulerAngles(i * 30, i * 50, i * 70);
108-
matrix.setTRS(pos, rot, scl);
109-
110-
// copy matrix elements into array of floats
111-
for (var m = 0; m < 16; m++)
112-
matrices[matrixIndex++] = matrix.data[m];
90+
if (this.app.graphicsDevice.supportsInstancing) {
91+
// number of instances to render
92+
var instanceCount = 1000;
93+
94+
// store matrices for individual instances into array
95+
var matrices = new Float32Array(instanceCount * 16);
96+
var matrixIndex = 0;
97+
98+
var radius = 5;
99+
var pos = new pc.Vec3();
100+
var rot = new pc.Quat();
101+
var scl = new pc.Vec3();
102+
var matrix = new pc.Mat4();
103+
104+
for (var i = 0; i < instanceCount; i++) {
105+
// generate random positions / scales and rotations
106+
pos.set(Math.random() * radius - radius * 0.5, Math.random() * radius - radius * 0.5, Math.random() * radius - radius * 0.5);
107+
scl.set(0.1 + Math.random() * 0.1, 0.1 + Math.random() * 0.3, 0.1 + Math.random() * 0.1);
108+
rot.setFromEulerAngles(i * 30, i * 50, i * 70);
109+
matrix.setTRS(pos, rot, scl);
110+
111+
// copy matrix elements into array of floats
112+
for (var m = 0; m < 16; m++)
113+
matrices[matrixIndex++] = matrix.data[m];
114+
}
115+
116+
// create static vertex buffer containing the matrices
117+
var vertexBuffer = new pc.VertexBuffer(this.app.graphicsDevice, pc.VertexFormat.defaultInstancingFormat, instanceCount, pc.BUFFER_STATIC, matrices);
118+
119+
// initialise instancing using the vertex buffer on meshInstance of the created box
120+
var boxMeshInst = box.model.meshInstances[0];
121+
boxMeshInst.setInstancing(vertexBuffer);
113122
}
114123

115-
// create static vertex buffer containing the matrices
116-
var vertexBuffer = new pc.VertexBuffer(this.app.graphicsDevice, pc.VertexFormat.defaultInstancingFormat, instanceCount, pc.BUFFER_STATIC, matrices);
117-
118-
// initialise instancing using the vertex buffer on meshInstance of the created box
119-
var boxMeshInst = box.model.meshInstances[0];
120-
boxMeshInst.setInstancing(vertexBuffer);
121-
122124
// Set an update function on the app's update event
123125
var angle = 0;
124126
app.on("update", function (dt) {

examples/graphics/lights-baked.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
nearClip: 0.05
9999
});
100100
app.root.addChild(camera);
101-
camera.setLocalPosition(0, 0, 5);
101+
camera.setLocalPosition(0, 0, 8);
102102

103103
app.scene.lightmapMode = pc.BAKE_COLOR;
104104
app.scene.lightmapMaxResolution = 2048;

examples/graphics/shader-burn.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</script>
3838

3939
<script id="fshader" type="x-shader/x-fragment">
40-
precision highp float;
40+
precision mediump float;
4141

4242
varying vec2 vUv0;
4343

examples/graphics/shader-toon.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</script>
6464

6565
<script id="fshader" type="x-shader/x-fragment">
66-
precision highp float;
66+
precision mediump float;
6767
uniform sampler2D uTexture;
6868
varying float vertOutTexCoord;
6969
varying vec2 texCoord;

examples/graphics/shader-wobble.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</script>
4141

4242
<script id="fshader" type="x-shader/x-fragment">
43-
precision highp float;
43+
precision mediump float;
4444

4545
uniform sampler2D uDiffuseMap;
4646

0 commit comments

Comments
 (0)