WebGPURenderPipelines.js 19 KB

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