-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebGPURenderer: Introduce ShaderLib.
- Loading branch information
Showing
2 changed files
with
100 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
const ShaderLib = { | ||
meshBasic: { | ||
vertexShader: `#version 450 | ||
layout(location = 0) in vec3 position; | ||
layout(location = 1) in vec2 uv; | ||
layout(location = 0) out vec2 vUv; | ||
layout(set = 0, binding = 0) uniform ModelUniforms { | ||
mat4 modelMatrix; | ||
mat4 modelViewMatrix; | ||
mat3 normalMatrix; | ||
} modelUniforms; | ||
layout(set = 0, binding = 1) uniform CameraUniforms { | ||
mat4 projectionMatrix; | ||
mat4 viewMatrix; | ||
} cameraUniforms; | ||
void main(){ | ||
vUv = uv; | ||
gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 ); | ||
}`, | ||
fragmentShader: `#version 450 | ||
layout(set = 0, binding = 2) uniform OpacityUniforms { | ||
float opacity; | ||
} opacityUniforms; | ||
layout(set = 0, binding = 3) uniform sampler mySampler; | ||
layout(set = 0, binding = 4) uniform texture2D myTexture; | ||
layout(location = 0) in vec2 vUv; | ||
layout(location = 0) out vec4 outColor; | ||
void main() { | ||
outColor = texture( sampler2D( myTexture, mySampler ), vUv ); | ||
outColor.a *= opacityUniforms.opacity; | ||
}` | ||
}, | ||
pointsBasic: { | ||
vertexShader: `#version 450 | ||
layout(location = 0) in vec3 position; | ||
layout(set = 0, binding = 0) uniform ModelUniforms { | ||
mat4 modelMatrix; | ||
mat4 modelViewMatrix; | ||
} modelUniforms; | ||
layout(set = 0, binding = 1) uniform CameraUniforms { | ||
mat4 projectionMatrix; | ||
mat4 viewMatrix; | ||
} cameraUniforms; | ||
void main(){ | ||
gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 ); | ||
}`, | ||
fragmentShader: `#version 450 | ||
layout(location = 0) out vec4 outColor; | ||
void main() { | ||
outColor = vec4( 1.0, 0.0, 0.0, 1.0 ); | ||
}` | ||
}, | ||
lineBasic: { | ||
vertexShader: `#version 450 | ||
layout(location = 0) in vec3 position; | ||
layout(set = 0, binding = 0) uniform ModelUniforms { | ||
mat4 modelMatrix; | ||
mat4 modelViewMatrix; | ||
} modelUniforms; | ||
layout(set = 0, binding = 1) uniform CameraUniforms { | ||
mat4 projectionMatrix; | ||
mat4 viewMatrix; | ||
} cameraUniforms; | ||
void main(){ | ||
gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 ); | ||
}`, | ||
fragmentShader: `#version 450 | ||
layout(location = 0) out vec4 outColor; | ||
void main() { | ||
outColor = vec4( 1.0, 0.0, 0.0, 1.0 ); | ||
}` | ||
} | ||
}; | ||
|
||
export default ShaderLib; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters