|
1 | 1 | // @config DESCRIPTION This example demonstrates how to customize the shader handling the instancing of a StandardMaterial. |
| 2 | +import files from 'examples/files'; |
2 | 3 | import { deviceType, rootPath } from 'examples/utils'; |
3 | 4 | import * as pc from 'playcanvas'; |
4 | 5 |
|
@@ -96,34 +97,8 @@ assetListLoader.load(() => { |
96 | 97 |
|
97 | 98 | // and a custom instancing shader chunk, which will be used in case the mesh instance has instancing enabled |
98 | 99 | material.shaderChunksVersion = '2.8'; |
99 | | - material.getShaderChunks(pc.SHADERLANGUAGE_GLSL).set('transformInstancingVS', ` |
100 | | -
|
101 | | - // instancing attributes |
102 | | - attribute vec3 aInstPosition; |
103 | | - attribute float aInstScale; |
104 | | -
|
105 | | - // uniforms |
106 | | - uniform float uTime; |
107 | | - uniform vec3 uCenter; |
108 | | -
|
109 | | - // all instancing chunk needs to do is to implement getModelMatrix function, which returns a world matrix for the instance |
110 | | - mat4 getModelMatrix() { |
111 | | -
|
112 | | - // we have world position in aInstPosition, but modify it based on distance from uCenter for some displacement effect |
113 | | - vec3 direction = aInstPosition - uCenter; |
114 | | - float distanceFromCenter = length(direction); |
115 | | - float displacementIntensity = exp(-distanceFromCenter * 0.2) ; //* (1.9 + abs(sin(uTime * 1.5))); |
116 | | - vec3 worldPos = aInstPosition - direction * displacementIntensity; |
117 | | -
|
118 | | - // create matrix based on the modified poition, and scale |
119 | | - return mat4( |
120 | | - vec4(aInstScale, 0.0, 0.0, 0.0), |
121 | | - vec4(0.0, aInstScale, 0.0, 0.0), |
122 | | - vec4(0.0, 0.0, aInstScale, 0.0), |
123 | | - vec4(worldPos, 1.0) |
124 | | - ); |
125 | | - } |
126 | | - `); |
| 100 | + material.getShaderChunks(pc.SHADERLANGUAGE_GLSL).set('transformInstancingVS', files['transform-instancing.glsl.vert']); |
| 101 | + material.getShaderChunks(pc.SHADERLANGUAGE_WGSL).set('transformInstancingVS', files['transform-instancing.wgsl.vert']); |
127 | 102 |
|
128 | 103 | material.update(); |
129 | 104 |
|
|
0 commit comments