Skip to content

Commit

Permalink
Enable WebGPU when available
Browse files Browse the repository at this point in the history
- fixed shader compilation errors: the compiler expects explicit locations for in/out and works fine with varying
  • Loading branch information
BarthPaleologue committed Nov 25, 2023
1 parent cb9b446 commit aedc64a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/shaders/butterflyFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ uniform vec3 lightDirection;

uniform sampler2D butterflyTexture;

in vec3 vPosition;
in vec2 vUV;
varying vec3 vPosition;
varying vec2 vUV;

in mat4 normalMatrix;
in vec3 vNormal;
varying mat4 normalMatrix;
varying vec3 vNormal;

in vec3 vOriginalWorldPosition;
varying vec3 vOriginalWorldPosition;

// src: https://gist.github.com/mairod/a75e7b44f68110e1576d77419d608786
vec3 hueShift( vec3 color, float hueAdjust ){
Expand Down
16 changes: 8 additions & 8 deletions src/shaders/butterflyVertex.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
precision highp float;

in vec3 position;
in vec3 normal;
in vec2 uv;
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;

uniform mat4 viewProjection;

Expand All @@ -12,13 +12,13 @@ uniform vec3 playerPosition;

uniform float time;

out vec3 vPosition;
out vec2 vUV;
varying vec3 vPosition;
varying vec2 vUV;

out mat4 normalMatrix;
out vec3 vNormal;
varying mat4 normalMatrix;
varying vec3 vNormal;

out vec3 vOriginalWorldPosition;
varying vec3 vOriginalWorldPosition;

// rotation using https://www.wikiwand.com/en/Rodrigues%27_rotation_formula
vec3 rotateAround(vec3 vector, vec3 axis, float theta) {
Expand Down
6 changes: 3 additions & 3 deletions src/shaders/grassFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ uniform float time;

uniform vec3 lightDirection;

in vec3 vPosition;
varying vec3 vPosition;

in mat4 normalMatrix;
in vec3 vNormal;
varying mat4 normalMatrix;
varying vec3 vNormal;

void main() {
vec3 baseColor = vec3(0.05, 0.2, 0.01);
Expand Down
10 changes: 5 additions & 5 deletions src/shaders/grassVertex.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
precision highp float;

in vec3 position;
in vec3 normal;
attribute vec3 position;
attribute vec3 normal;

uniform mat4 view;
uniform mat4 projection;
Expand All @@ -13,10 +13,10 @@ uniform float time;

uniform sampler2D perlinNoise;

out vec3 vPosition;
varying vec3 vPosition;

out mat4 normalMatrix;
out vec3 vNormal;
varying mat4 normalMatrix;
varying vec3 vNormal;

// rotation using https://www.wikiwand.com/en/Rodrigues%27_rotation_formula
vec3 rotateAround(vec3 vector, vec3 axis, float theta) {
Expand Down
3 changes: 2 additions & 1 deletion src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ import { TerrainChunk } from "./terrain/terrainChunk";
import { createButterfly } from "./butterfly/butterfly";
import { createButterflyMaterial } from "./butterfly/butterflyMaterial";
import { createTree } from "./utils/tree";
import { EngineFactory } from "@babylonjs/core";

const canvas = document.getElementById("renderer") as HTMLCanvasElement;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

const engine = new Engine(canvas, true);
const engine = await EngineFactory.CreateAsync(canvas, {});
engine.displayLoadingUI();

const havokInstance = await HavokPhysics();
Expand Down

0 comments on commit aedc64a

Please sign in to comment.