p3nGu1nZz commited on
Commit
a319f30
1 Parent(s): a2241b7

update to constants

Browse files
Files changed (3) hide show
  1. config.js +8 -1
  2. constants.js +9 -0
  3. index.html +5 -16
config.js CHANGED
@@ -7,5 +7,12 @@ export const config = {
7
  maxGlyphs: 100,
8
  vertsPerGlyph: 6,
9
  floatsPerVertex: 8,
10
- uniformBufferSize: 64
 
 
 
 
 
 
 
11
  };
 
7
  maxGlyphs: 100,
8
  vertsPerGlyph: 6,
9
  floatsPerVertex: 8,
10
+ uniformBufferSize: 64,
11
+ render: {
12
+ zNear: 0.001,
13
+ zFar: 50
14
+ },
15
+ time: {
16
+ phase: 0.001
17
+ }
18
  };
constants.js CHANGED
@@ -7,3 +7,12 @@ export const COLORS = [
7
  [1, 0, 0, 1],
8
  [0, 0.5, 1, 1]
9
  ];
 
 
 
 
 
 
 
 
 
 
7
  [1, 0, 0, 1],
8
  [0, 0.5, 1, 1]
9
  ];
10
+
11
+ export const RENDER_PASS_DESCRIPTOR = {
12
+ label: 'canvas render pass',
13
+ colorAttachments: [{
14
+ clearValue: [0.3, 0.3, 0.3, 1],
15
+ loadOp: 'clear',
16
+ storeOp: 'store',
17
+ }],
18
+ };
index.html CHANGED
@@ -13,7 +13,7 @@
13
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
14
  import { fetchShaderCode } from './utility.js';
15
  import { config } from './config.js';
16
- import { COLORS } from './constants.js';
17
 
18
  function generateGlyphTextureAtlas() {
19
  const canvas = document.createElement('canvas');
@@ -187,27 +187,16 @@
187
  ],
188
  });
189
 
190
- const renderPassDescriptor = {
191
- label: 'canvas render pass',
192
- colorAttachments: [{
193
- clearValue: [0.3, 0.3, 0.3, 1],
194
- loadOp: 'clear',
195
- storeOp: 'store',
196
- }],
197
- };
198
-
199
  function render(time) {
200
- time *= 0.001;
201
  const fov = 60 * Math.PI / 180;
202
  const aspect = canvas.clientWidth / canvas.clientHeight;
203
- const zNear = 0.001, zFar = 50;
204
- const projectionMatrix = mat4.perspective(fov, aspect, zNear, zFar);
205
  const viewMatrix = mat4.lookAt([0, 0, 5], [0, 0, 0], [0, 1, 0]);
206
  const viewProjectionMatrix = mat4.multiply(projectionMatrix, viewMatrix);
207
-
208
- renderPassDescriptor.colorAttachments[0].view = context.getCurrentTexture().createView();
209
  const encoder = device.createCommandEncoder();
210
- const pass = encoder.beginRenderPass(renderPassDescriptor);
211
  pass.setPipeline(pipeline);
212
  mat4.rotateY(viewProjectionMatrix, time, matrix);
213
  mat4.translate(matrix, [-width / 2, -height / 2, 0], matrix);
 
13
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
14
  import { fetchShaderCode } from './utility.js';
15
  import { config } from './config.js';
16
+ import { COLORS, RENDER_PASS_DESCRIPTOR } from './constants.js';
17
 
18
  function generateGlyphTextureAtlas() {
19
  const canvas = document.createElement('canvas');
 
187
  ],
188
  });
189
 
 
 
 
 
 
 
 
 
 
190
  function render(time) {
191
+ time *= config.time.phase;
192
  const fov = 60 * Math.PI / 180;
193
  const aspect = canvas.clientWidth / canvas.clientHeight;
194
+ const projectionMatrix = mat4.perspective(fov, aspect, config.render.zNear, config.render.zFar);
 
195
  const viewMatrix = mat4.lookAt([0, 0, 5], [0, 0, 0], [0, 1, 0]);
196
  const viewProjectionMatrix = mat4.multiply(projectionMatrix, viewMatrix);
197
+ RENDER_PASS_DESCRIPTOR.colorAttachments[0].view = context.getCurrentTexture().createView();
 
198
  const encoder = device.createCommandEncoder();
199
+ const pass = encoder.beginRenderPass(RENDER_PASS_DESCRIPTOR);
200
  pass.setPipeline(pipeline);
201
  mat4.rotateY(viewProjectionMatrix, time, matrix);
202
  mat4.translate(matrix, [-width / 2, -height / 2, 0], matrix);