WebGPURenderPipelines.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. import { GPUPrimitiveTopology, GPUIndexFormat, GPUTextureFormat, GPUCompareFunction, GPUFrontFace, GPUCullMode, GPUVertexFormat, GPUBlendFactor, GPUBlendOperation, BlendColorFactor, OneMinusBlendColorFactor, GPUColorWriteFlags, GPUStencilOperation } from './constants.js';
  2. import {
  3. FrontSide, BackSide, DoubleSide,
  4. NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth,
  5. NeverStencilFunc, AlwaysStencilFunc, LessStencilFunc, LessEqualStencilFunc, EqualStencilFunc, GreaterEqualStencilFunc, GreaterStencilFunc, NotEqualStencilFunc,
  6. KeepStencilOp, ZeroStencilOp, ReplaceStencilOp, InvertStencilOp, IncrementStencilOp, DecrementStencilOp, IncrementWrapStencilOp, DecrementWrapStencilOp,
  7. NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending,
  8. AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation,
  9. ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor
  10. } from '../../../../build/three.module.js';
  11. class WebGPURenderPipelines {
  12. constructor( device, glslang, bindings, sampleCount ) {
  13. this.device = device;
  14. this.glslang = glslang;
  15. this.bindings = bindings;
  16. this.sampleCount = sampleCount;
  17. this.pipelines = new WeakMap();
  18. this.shaderAttributes = new WeakMap();
  19. this.shaderModules = {
  20. vertex: new WeakMap(),
  21. fragment: new WeakMap()
  22. };
  23. }
  24. get( object ) {
  25. let pipeline = this.pipelines.get( object );
  26. if ( pipeline === undefined ) {
  27. const device = this.device;
  28. const material = object.material;
  29. // shader source
  30. let shader;
  31. if ( material.isMeshBasicMaterial ) {
  32. shader = ShaderLib.mesh_basic;
  33. } else if ( material.isPointsMaterial ) {
  34. shader = ShaderLib.points_basic;
  35. } else if ( material.isLineBasicMaterial ) {
  36. shader = ShaderLib.line_basic;
  37. } else {
  38. console.error( 'THREE.WebGPURenderer: Unknwon shader type.' );
  39. }
  40. // shader modules
  41. const glslang = this.glslang;
  42. let moduleVertex = this.shaderModules.vertex.get( shader );
  43. if ( moduleVertex === undefined ) {
  44. const byteCodeVertex = glslang.compileGLSL( shader.vertexShader, 'vertex' );
  45. moduleVertex = {
  46. module: device.createShaderModule( { code: byteCodeVertex } ),
  47. entryPoint: 'main'
  48. };
  49. this.shaderModules.vertex.set( shader, moduleVertex );
  50. }
  51. let moduleFragment = this.shaderModules.fragment.get( shader );
  52. if ( moduleFragment === undefined ) {
  53. const byteCodeFragment = glslang.compileGLSL( shader.fragmentShader, 'fragment' );
  54. moduleFragment = {
  55. module: device.createShaderModule( { code: byteCodeFragment } ),
  56. entryPoint: 'main'
  57. };
  58. this.shaderModules.fragment.set( shader, moduleFragment );
  59. }
  60. // layout
  61. const bindLayout = this.bindings.get( object ).layout;
  62. const layout = device.createPipelineLayout( { bindGroupLayouts: [ bindLayout ] } );
  63. // vertex buffers
  64. const vertexBuffers = [];
  65. const shaderAttributes = [];
  66. // find "layout (location = num) in type name" in vertex shader
  67. const regex = /^\s*layout\s*\(\s*location\s*=\s*(?<location>[0-9]+)\s*\)\s*in\s+(?<type>\w+)\s+(?<name>\w+)\s*;/gmi;
  68. let shaderAttribute = null;
  69. while ( shaderAttribute = regex.exec( shader.vertexShader ) ) {
  70. const shaderLocation = parseInt( shaderAttribute.groups.location );
  71. const arrayStride = this._getArrayStride( shaderAttribute.groups.type );
  72. const vertexFormat = this._getVertexFormat( shaderAttribute.groups.type );
  73. shaderAttributes.push( { name: shaderAttribute.groups.name, slot: shaderLocation } );
  74. vertexBuffers.push( {
  75. arrayStride: arrayStride,
  76. attributes: [ { shaderLocation: shaderLocation, offset: 0, format: vertexFormat } ]
  77. } );
  78. }
  79. //
  80. const geometry = object.geometry;
  81. let indexFormat;
  82. if ( object.isLine ) {
  83. const count = ( geometry.index ) ? geometry.index.count : geometry.attributes.position.count;
  84. indexFormat = ( count > 65535 ) ? GPUIndexFormat.Uint32 : GPUIndexFormat.Uint16; // define data type for primitive restart value
  85. }
  86. //
  87. let alphaBlend = {};
  88. let colorBlend = {};
  89. if ( material.transparent === true && material.blending !== NoBlending ) {
  90. alphaBlend = this._getAlphaBlend( material );
  91. colorBlend = this._getColorBlend( material );
  92. }
  93. //
  94. let stencilFront = {};
  95. if ( material.stencilWrite === true ) {
  96. stencilFront = {
  97. compare: this._getStencilCompare( material ),
  98. failOp: this._getStencilOperation( material.stencilFail ),
  99. depthFailOp: this._getStencilOperation( material.stencilZFail ),
  100. passOp: this._getStencilOperation( material.stencilZPass )
  101. };
  102. }
  103. // pipeline
  104. const primitiveTopology = this._getPrimitiveTopology( object );
  105. const rasterizationState = this._getRasterizationStateDescriptor( material );
  106. const colorWriteMask = this._getColorWriteMask( material );
  107. const depthCompare = this._getDepthCompare( material );
  108. pipeline = device.createRenderPipeline( {
  109. layout: layout,
  110. vertexStage: moduleVertex,
  111. fragmentStage: moduleFragment,
  112. primitiveTopology: primitiveTopology,
  113. rasterizationState: rasterizationState,
  114. colorStates: [ {
  115. format: GPUTextureFormat.BRGA8Unorm,
  116. alphaBlend: alphaBlend,
  117. colorBlend: colorBlend,
  118. writeMask: colorWriteMask
  119. } ],
  120. depthStencilState: {
  121. format: GPUTextureFormat.Depth24PlusStencil8,
  122. depthWriteEnabled: material.depthWrite,
  123. depthCompare: depthCompare,
  124. stencilFront: stencilFront,
  125. stencilBack: {}, // three.js does not provide an API to configure the back function (gl.stencilFuncSeparate() was never used)
  126. stencilReadMask: material.stencilFuncMask,
  127. stencilWriteMask: material.stencilWriteMask
  128. },
  129. vertexState: {
  130. indexFormat: indexFormat,
  131. vertexBuffers: vertexBuffers
  132. },
  133. sampleCount: this.sampleCount
  134. } );
  135. this.pipelines.set( object, pipeline );
  136. this.shaderAttributes.set( pipeline, shaderAttributes );
  137. }
  138. return pipeline;
  139. }
  140. getShaderAttributes( pipeline ) {
  141. return this.shaderAttributes.get( pipeline );
  142. }
  143. dispose() {
  144. this.pipelines = new WeakMap();
  145. this.shaderAttributes = new WeakMap();
  146. this.shaderModules = {
  147. vertex: new WeakMap(),
  148. fragment: new WeakMap()
  149. };
  150. }
  151. _getArrayStride( type ) {
  152. // @TODO: This code is GLSL specific. We need to update when we switch to WGSL.
  153. if ( type === 'float' ) return 4;
  154. if ( type === 'vec2' ) return 8;
  155. if ( type === 'vec3' ) return 12;
  156. if ( type === 'vec4' ) return 16;
  157. if ( type === 'int' ) return 4;
  158. if ( type === 'ivec2' ) return 8;
  159. if ( type === 'ivec3' ) return 12;
  160. if ( type === 'ivec4' ) return 16;
  161. if ( type === 'uint' ) return 4;
  162. if ( type === 'uvec2' ) return 8;
  163. if ( type === 'uvec3' ) return 12;
  164. if ( type === 'uvec4' ) return 16;
  165. console.error( 'THREE.WebGPURenderer: Shader variable type not supported yet.', type );
  166. }
  167. _getAlphaBlend( material ) {
  168. const blending = material.blending;
  169. const premultipliedAlpha = material.premultipliedAlpha;
  170. let alphaBlend = undefined;
  171. switch ( blending ) {
  172. case NormalBlending:
  173. if ( premultipliedAlpha === false ) {
  174. alphaBlend = {
  175. srcFactor: GPUBlendFactor.One,
  176. dstFactor: GPUBlendFactor.OneMinusSrcAlpha,
  177. operation: GPUBlendOperation.Add
  178. };
  179. }
  180. break;
  181. case AdditiveBlending:
  182. // no alphaBlend settings
  183. break;
  184. case SubtractiveBlending:
  185. if ( premultipliedAlpha === true ) {
  186. alphaBlend = {
  187. srcFactor: GPUBlendFactor.OneMinusSrcColor,
  188. dstFactor: GPUBlendFactor.OneMinusSrcAlpha,
  189. operation: GPUBlendOperation.Add
  190. };
  191. }
  192. break;
  193. case MultiplyBlending:
  194. if ( premultipliedAlpha === true ) {
  195. alphaBlend = {
  196. srcFactor: GPUBlendFactor.Zero,
  197. dstFactor: GPUBlendFactor.SrcAlpha,
  198. operation: GPUBlendOperation.Add
  199. };
  200. }
  201. break;
  202. case CustomBlending:
  203. const blendSrcAlpha = material.blendSrcAlpha;
  204. const blendDstAlpha = material.blendDstAlpha;
  205. const blendEquationAlpha = material.blendEquationAlpha;
  206. if ( blendSrcAlpha !== null && blendDstAlpha !== null && blendEquationAlpha !== null ) {
  207. alphaBlend = {
  208. srcFactor: this._getBlendFactor( blendSrcAlpha ),
  209. dstFactor: this._getBlendFactor( blendDstAlpha ),
  210. operation: this._getBlendOperation( blendEquationAlpha )
  211. };
  212. }
  213. break;
  214. default:
  215. console.error( 'THREE.WebGPURenderer: Blending not supported.', blending );
  216. }
  217. return alphaBlend;
  218. }
  219. _getBlendFactor( blend ) {
  220. let blendFactor;
  221. switch ( blend ) {
  222. case ZeroFactor:
  223. blendFactor = GPUBlendFactor.Zero;
  224. break;
  225. case OneFactor:
  226. blendFactor = GPUBlendFactor.One;
  227. break;
  228. case SrcColorFactor:
  229. blendFactor = GPUBlendFactor.SrcColor;
  230. break;
  231. case OneMinusSrcColorFactor:
  232. blendFactor = GPUBlendFactor.OneMinusSrcColor;
  233. break;
  234. case SrcAlphaFactor:
  235. blendFactor = GPUBlendFactor.SrcAlpha;
  236. break;
  237. case OneMinusSrcAlphaFactor:
  238. blendFactor = GPUBlendFactor.OneMinusSrcAlpha;
  239. break;
  240. case DstColorFactor:
  241. blendFactor = GPUBlendFactor.DstColor;
  242. break;
  243. case OneMinusDstColorFactor:
  244. blendFactor = GPUBlendFactor.OneMinusDstColor;
  245. break;
  246. case DstAlphaFactor:
  247. blendFactor = GPUBlendFactor.DstAlpha;
  248. break;
  249. case OneMinusDstAlphaFactor:
  250. blendFactor = GPUBlendFactor.OneMinusDstAlpha;
  251. break;
  252. case SrcAlphaSaturateFactor:
  253. blendFactor = GPUBlendFactor.SrcAlphaSaturated;
  254. break;
  255. case BlendColorFactor:
  256. blendFactor = GPUBlendFactor.BlendColor;
  257. break;
  258. case OneMinusBlendColorFactor:
  259. blendFactor = GPUBlendFactor.OneMinusBlendColor;
  260. break;
  261. default:
  262. console.error( 'THREE.WebGPURenderer: Blend factor not supported.', blend );
  263. }
  264. return blendFactor;
  265. }
  266. _getBlendOperation( blendEquation ) {
  267. let blendOperation;
  268. switch ( blendEquation ) {
  269. case AddEquation:
  270. blendOperation = GPUBlendOperation.Add;
  271. break;
  272. case SubtractEquation:
  273. blendOperation = GPUBlendOperation.Subtract;
  274. break;
  275. case ReverseSubtractEquation:
  276. blendOperation = GPUBlendOperation.ReverseSubtract;
  277. break;
  278. case MinEquation:
  279. blendOperation = GPUBlendOperation.Min;
  280. break;
  281. case MaxEquation:
  282. blendOperation = GPUBlendOperation.Max;
  283. break;
  284. default:
  285. console.error( 'THREE.WebGPURenderer: Blend equation not supported.', blendEquation );
  286. }
  287. return blendOperation;
  288. }
  289. _getColorBlend( material ) {
  290. const blending = material.blending;
  291. const premultipliedAlpha = material.premultipliedAlpha;
  292. const colorBlend = {
  293. srcFactor: null,
  294. dstFactor: null,
  295. operation: null
  296. };
  297. switch ( blending ) {
  298. case NormalBlending:
  299. colorBlend.srcFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.One : GPUBlendFactor.SrcAlpha;
  300. colorBlend.dstFactor = GPUBlendFactor.OneMinusSrcAlpha;
  301. colorBlend.operation = GPUBlendOperation.Add;
  302. break;
  303. case AdditiveBlending:
  304. colorBlend.srcFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.One : GPUBlendFactor.SrcAlpha;
  305. colorBlend.operation = GPUBlendOperation.Add;
  306. break;
  307. case SubtractiveBlending:
  308. colorBlend.srcFactor = GPUBlendFactor.Zero;
  309. colorBlend.dstFactor = ( premultipliedAlpha === true ) ? GPUBlendFactor.Zero : GPUBlendFactor.OneMinusSrcColor;
  310. colorBlend.operation = GPUBlendOperation.Add;
  311. break;
  312. case MultiplyBlending:
  313. colorBlend.srcFactor = GPUBlendFactor.Zero;
  314. colorBlend.dstFactor = GPUBlendFactor.SrcColor;
  315. colorBlend.operation = GPUBlendOperation.Add;
  316. break;
  317. case CustomBlending:
  318. colorBlend.srcFactor = this._getBlendFactor( material.blendSrc );
  319. colorBlend.dstFactor = this._getBlendFactor( material.blendDst );
  320. colorBlend.operation = this._getBlendOperation( material.blendEquation );
  321. break;
  322. default:
  323. console.error( 'THREE.WebGPURenderer: Blending not supported.', blending );
  324. }
  325. return colorBlend;
  326. }
  327. _getColorWriteMask( material ) {
  328. return ( material.colorWrite === true ) ? GPUColorWriteFlags.All : GPUColorWriteFlags.None;
  329. }
  330. _getDepthCompare( material ) {
  331. let depthCompare;
  332. if ( material.depthTest === false ) {
  333. depthCompare = GPUCompareFunction.Always;
  334. } else {
  335. const depthFunc = material.depthFunc;
  336. switch ( depthFunc ) {
  337. case NeverDepth:
  338. depthCompare = GPUCompareFunction.Never;
  339. break;
  340. case AlwaysDepth:
  341. depthCompare = GPUCompareFunction.Always;
  342. break;
  343. case LessDepth:
  344. depthCompare = GPUCompareFunction.Less;
  345. break;
  346. case LessEqualDepth:
  347. depthCompare = GPUCompareFunction.LessEqual;
  348. break;
  349. case EqualDepth:
  350. depthCompare = GPUCompareFunction.Equal;
  351. break;
  352. case GreaterEqualDepth:
  353. depthCompare = GPUCompareFunction.GreaterEqual;
  354. break;
  355. case GreaterDepth:
  356. depthCompare = GPUCompareFunction.Greater;
  357. break;
  358. case NotEqualDepth:
  359. depthCompare = GPUCompareFunction.NotEqual;
  360. break;
  361. default:
  362. console.error( 'THREE.WebGPURenderer: Invalid depth function.', depthFunc );
  363. }
  364. }
  365. return depthCompare;
  366. }
  367. _getPrimitiveTopology( object ) {
  368. if ( object.isMesh ) return GPUPrimitiveTopology.TriangleList;
  369. else if ( object.isPoints ) return GPUPrimitiveTopology.PointList;
  370. else if ( object.isLine ) return GPUPrimitiveTopology.LineStrip;
  371. else if ( object.isLineSegments ) return GPUPrimitiveTopology.LineList;
  372. }
  373. _getRasterizationStateDescriptor( material ) {
  374. const descriptor = {};
  375. switch ( material.side ) {
  376. case FrontSide:
  377. descriptor.frontFace = GPUFrontFace.CCW;
  378. descriptor.cullMode = GPUCullMode.Back;
  379. break;
  380. case BackSide:
  381. descriptor.frontFace = GPUFrontFace.CW;
  382. descriptor.cullMode = GPUCullMode.Back;
  383. break;
  384. case DoubleSide:
  385. descriptor.frontFace = GPUFrontFace.CCW;
  386. descriptor.cullMode = GPUCullMode.None;
  387. break;
  388. default:
  389. console.error( 'THREE.WebGPURenderer: Unknown Material.side value.', material.side );
  390. break;
  391. }
  392. return descriptor;
  393. }
  394. _getStencilCompare( material ) {
  395. let stencilCompare;
  396. const stencilFunc = material.stencilFunc;
  397. switch ( stencilFunc ) {
  398. case NeverStencilFunc:
  399. stencilCompare = GPUCompareFunction.Never;
  400. break;
  401. case AlwaysStencilFunc:
  402. stencilCompare = GPUCompareFunction.Always;
  403. break;
  404. case LessStencilFunc:
  405. stencilCompare = GPUCompareFunction.Less;
  406. break;
  407. case LessEqualStencilFunc:
  408. stencilCompare = GPUCompareFunction.LessEqual;
  409. break;
  410. case EqualStencilFunc:
  411. stencilCompare = GPUCompareFunction.Equal;
  412. break;
  413. case GreaterEqualStencilFunc:
  414. stencilCompare = GPUCompareFunction.GreaterEqual;
  415. break;
  416. case GreaterStencilFunc:
  417. stencilCompare = GPUCompareFunction.Greater;
  418. break;
  419. case NotEqualStencilFunc:
  420. stencilCompare = GPUCompareFunction.NotEqual;
  421. break;
  422. default:
  423. console.error( 'THREE.WebGPURenderer: Invalid stencil function.', stencilFunc );
  424. }
  425. return stencilCompare;
  426. }
  427. _getStencilOperation( op ) {
  428. let stencilOperation;
  429. switch ( op ) {
  430. case KeepStencilOp:
  431. stencilOperation = GPUStencilOperation.Keep;
  432. break;
  433. case ZeroStencilOp:
  434. stencilOperation = GPUStencilOperation.Zero;
  435. break;
  436. case ReplaceStencilOp:
  437. stencilOperation = GPUStencilOperation.Replace;
  438. break;
  439. case InvertStencilOp:
  440. stencilOperation = GPUStencilOperation.Invert;
  441. break;
  442. case IncrementStencilOp:
  443. stencilOperation = GPUStencilOperation.IncrementClamp;
  444. break;
  445. case DecrementStencilOp:
  446. stencilOperation = GPUStencilOperation.DecrementClamp;
  447. break;
  448. case IncrementWrapStencilOp:
  449. stencilOperation = GPUStencilOperation.IncrementWrap;
  450. break;
  451. case DecrementWrapStencilOp:
  452. stencilOperation = GPUStencilOperation.DecrementWrap;
  453. break;
  454. default:
  455. console.error( 'THREE.WebGPURenderer: Invalid stencil operation.', stencilOperation );
  456. }
  457. return stencilOperation;
  458. }
  459. _getVertexFormat( type ) {
  460. // @TODO: This code is GLSL specific. We need to update when we switch to WGSL.
  461. if ( type === 'float' ) return GPUVertexFormat.Float;
  462. if ( type === 'vec2' ) return GPUVertexFormat.Float2;
  463. if ( type === 'vec3' ) return GPUVertexFormat.Float3;
  464. if ( type === 'vec4' ) return GPUVertexFormat.Float4;
  465. if ( type === 'int' ) return GPUVertexFormat.Int;
  466. if ( type === 'ivec2' ) return GPUVertexFormat.Int2;
  467. if ( type === 'ivec3' ) return GPUVertexFormat.Int3;
  468. if ( type === 'ivec4' ) return GPUVertexFormat.Int4;
  469. if ( type === 'uint' ) return GPUVertexFormat.UInt;
  470. if ( type === 'uvec2' ) return GPUVertexFormat.UInt2;
  471. if ( type === 'uvec3' ) return GPUVertexFormat.UInt3;
  472. if ( type === 'uvec4' ) return GPUVertexFormat.UInt4;
  473. console.error( 'THREE.WebGPURenderer: Shader variable type not supported yet.', type );
  474. }
  475. }
  476. const ShaderLib = {
  477. mesh_basic: {
  478. vertexShader: `#version 450
  479. layout(location = 0) in vec3 position;
  480. layout(location = 1) in vec2 uv;
  481. layout(location = 0) out vec2 vUv;
  482. layout(set = 0, binding = 0) uniform ModelUniforms {
  483. mat4 modelMatrix;
  484. mat4 modelViewMatrix;
  485. } modelUniforms;
  486. layout(set = 0, binding = 1) uniform CameraUniforms {
  487. mat4 projectionMatrix;
  488. mat4 viewMatrix;
  489. } cameraUniforms;
  490. void main(){
  491. vUv = uv;
  492. gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 );
  493. }`,
  494. fragmentShader: `#version 450
  495. layout(set = 0, binding = 2) uniform OpacityUniforms {
  496. float opacity;
  497. } opacityUniforms;
  498. layout(set = 0, binding = 3) uniform sampler mySampler;
  499. layout(set = 0, binding = 4) uniform texture2D myTexture;
  500. layout(location = 0) in vec2 vUv;
  501. layout(location = 0) out vec4 outColor;
  502. void main() {
  503. outColor = texture( sampler2D( myTexture, mySampler ), vUv );
  504. outColor.a *= opacityUniforms.opacity;
  505. }`
  506. },
  507. points_basic: {
  508. vertexShader: `#version 450
  509. layout(location = 0) in vec3 position;
  510. layout(set = 0, binding = 0) uniform ModelUniforms {
  511. mat4 modelMatrix;
  512. mat4 modelViewMatrix;
  513. } modelUniforms;
  514. layout(set = 0, binding = 1) uniform CameraUniforms {
  515. mat4 projectionMatrix;
  516. mat4 viewMatrix;
  517. } cameraUniforms;
  518. void main(){
  519. gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 );
  520. }`,
  521. fragmentShader: `#version 450
  522. layout(location = 0) out vec4 outColor;
  523. void main() {
  524. outColor = vec4( 1.0, 0.0, 0.0, 1.0 );
  525. }`
  526. },
  527. line_basic: {
  528. vertexShader: `#version 450
  529. layout(location = 0) in vec3 position;
  530. layout(set = 0, binding = 0) uniform ModelUniforms {
  531. mat4 modelMatrix;
  532. mat4 modelViewMatrix;
  533. } modelUniforms;
  534. layout(set = 0, binding = 1) uniform CameraUniforms {
  535. mat4 projectionMatrix;
  536. mat4 viewMatrix;
  537. } cameraUniforms;
  538. void main(){
  539. gl_Position = cameraUniforms.projectionMatrix * modelUniforms.modelViewMatrix * vec4( position, 1.0 );
  540. }`,
  541. fragmentShader: `#version 450
  542. layout(location = 0) out vec4 outColor;
  543. void main() {
  544. outColor = vec4( 1.0, 0.0, 0.0, 1.0 );
  545. }`
  546. }
  547. };
  548. export default WebGPURenderPipelines;