소스 검색

WebGPURenderer: Introduce ShaderLib.

Mugen87 4 년 전
부모
커밋
a01651a4de
2개의 변경된 파일100개의 추가작업 그리고 97개의 파일을 삭제
  1. 95 0
      examples/jsm/renderers/webgpu/ShaderLib.js
  2. 5 97
      examples/jsm/renderers/webgpu/WebGPURenderPipelines.js

+ 95 - 0
examples/jsm/renderers/webgpu/ShaderLib.js

@@ -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;

+ 5 - 97
examples/jsm/renderers/webgpu/WebGPURenderPipelines.js

@@ -9,6 +9,8 @@ import {
 	ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor
 } from '../../../../build/three.module.js';
 
+import ShaderLib from './ShaderLib.js';
+
 class WebGPURenderPipelines {
 
 	constructor( renderer, properties, device, glslang, sampleCount ) {
@@ -57,15 +59,15 @@ class WebGPURenderPipelines {
 
 			if ( material.isMeshBasicMaterial ) {
 
-				shader = ShaderLib.mesh_basic;
+				shader = ShaderLib.meshBasic;
 
 			} else if ( material.isPointsMaterial ) {
 
-				shader = ShaderLib.points_basic;
+				shader = ShaderLib.pointsBasic;
 
 			} else if ( material.isLineBasicMaterial ) {
 
-				shader = ShaderLib.line_basic;
+				shader = ShaderLib.lineBasic;
 
 			} else {
 
@@ -790,98 +792,4 @@ class WebGPURenderPipelines {
 
 }
 
-const ShaderLib = {
-	mesh_basic: {
-		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;
-		}`
-	},
-	points_basic: {
-		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 );
-		}`
-	},
-	line_basic: {
-		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 WebGPURenderPipelines;