当前位置: 首页 > news >正文

昆明城乡建设网站新网站秒收录技术

昆明城乡建设网站,新网站秒收录技术,常平镇网站建设,托管代运营接下来让我们使用 UniformBuffer。UniformBuffer 是一个只读内存区域,可以在着色器上访问。 这次,我们将传递给着色器的矩阵存储在 UniformBuffer 中。演示示例 1.在顶点着色器中的 UniformBuffer 这次我们在顶点着色器里定义一个名为Uniforms的新结构体…

接下来让我们使用 UniformBuffer。UniformBuffer 是一个只读内存区域,可以在着色器上访问。
这次,我们将传递给着色器的矩阵存储在 UniformBuffer 中。演示示例

1.在顶点着色器中的 UniformBuffer

这次我们在顶点着色器里定义一个名为Uniforms的新结构体,并定义一些成员变量来将我们想要传递的矩阵存储在其中。我们准备了三个矩阵:投影矩阵projectionMatrix 、视图矩阵viewMatrix 和世界矩阵worldMatrix(或者说模型矩阵)。

struct Uniforms {projectionMatrix : mat4x4<f32>,viewMatrix : mat4x4<f32>,worldMatrix : mat4x4<f32>,
}
@binding(0) @group(0) var<uniform> uniforms : Uniforms;struct VertexOutput {@builtin(position) Position : vec4<f32>,@location(0) fragColor : vec4<f32>,
}@vertex
fn main(@location(0) position: vec4<f32>,@location(1) color: vec4<f32>
) -> VertexOutput {var output : VertexOutput;output.Position = uniforms.projectionMatrix * uniforms.viewMatrix * uniforms.worldMatrix * position;output.fragColor = color;return output;
}

2.生成UniformBuffer

下面是生成 UniformBuffer 的代码。

  const uniformBufferSize = 4 /* bytes */ * 16 * 3; // 4x4 matrix * 3const uniformBuffer = g_device.createBuffer({size: uniformBufferSize,usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,});

usage除了GPUBufferUsage.UNIFORM的选项,还有一个GPUBufferUsage.COPY_DST选项,这个选项是用来表明将数据复制到 GPU 内存区域。

3.复制矩阵到UniformBuffer

然后将具体的矩阵数据复制到 UniformBuffer 中,这次我们使用 glMatrix 库来处理矩阵。

function getTransformationMatrix(uniformBuffer: GPUBuffer) {const projectionMatrix = glMatrix.mat4.create();glMatrix.mat4.perspective(projectionMatrix, (2 * Math.PI) / 5, 1, 1, 100.0);g_device.queue.writeBuffer(uniformBuffer,4 * 16 * 0,projectionMatrix.buffer,projectionMatrix.byteOffset,projectionMatrix.byteLength);const viewMatrix = glMatrix.mat4.create();glMatrix.mat4.translate(viewMatrix, viewMatrix, glMatrix.vec3.fromValues(0, 0, -4));g_device.queue.writeBuffer(uniformBuffer,4 * 16 * 1,viewMatrix.buffer,viewMatrix.byteOffset,viewMatrix.byteLength);const worldMatrix = glMatrix.mat4.create();const now = Date.now() / 1000;glMatrix.mat4.rotate(worldMatrix,worldMatrix,1,glMatrix.vec3.fromValues(Math.sin(now), Math.cos(now), 0));g_device.queue.writeBuffer(uniformBuffer,4 * 16 * 2,worldMatrix.buffer,worldMatrix.byteOffset,worldMatrix.byteLength);
}

设置每个矩阵后,使用g_device.queue.writeBuffer将数据复制到 GPU 上的 UniformBuffer。 注意第二个参数指定了复制目标的偏移量,它指定应放置每个矩阵数据的起始地址。

4.生成GPUBindGroup

接下来,创建一个名为 GPUBindGroup 的对象。WebGPU 在为 GPU 设置 GPU 资源(例如 UniformBuffers、纹理和采样器)时使用此对象。

前面创建的 uniformBuffer 设置为entities[0].resource.buffer

  const bindGroup = g_device.createBindGroup({layout: g_pipeline.getBindGroupLayout(0),entries: [{binding: 0, // @binding(0) in shaderresource: {buffer: uniformBuffer,},},],});

这里binding: 0对应的是顶点着色器中写的属性@binding(0)layout:g_pipeline.getBindGroupLayout(0)中的0对应顶点着色器中写的属性@group(0)

5.在renderPassEncoder中设置GPUBindGroup

最后,使用renderPassEncoder上的setBindGroup方法设置 GPUBindGroup。

  const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);renderPassEncoder.setPipeline(pipeline);renderPassEncoder.setBindGroup(0, uniformBindGroup); // <--- 设置bindGrouprenderPassEncoder.setVertexBuffer(0, verticesBuffer);renderPassEncoder.draw(cubeVertexCount);renderPassEncoder.end();g_device.queue.submit([commandEncoder.finish()]);

setBindGroup的第一个参数0对应于顶点着色器中写入的属性@group(0)

总结

以上,使用UniformBuffer的绘制就完成了。

虽然这个立方体看起来很奇怪。。。这是因为我们还没有在绘图时启用深度测试。下次我们将启用深度测试以确保正确绘制立方体。


文章转载自:
http://clavichord.c7496.cn
http://stake.c7496.cn
http://scotometer.c7496.cn
http://elisabeth.c7496.cn
http://sloughy.c7496.cn
http://rearmouse.c7496.cn
http://birdlime.c7496.cn
http://wipo.c7496.cn
http://parageusia.c7496.cn
http://utilitarian.c7496.cn
http://fleshly.c7496.cn
http://thorium.c7496.cn
http://rediffusion.c7496.cn
http://chrysocarpous.c7496.cn
http://acanthus.c7496.cn
http://crampit.c7496.cn
http://hibernation.c7496.cn
http://cannabin.c7496.cn
http://erythrogenic.c7496.cn
http://standard.c7496.cn
http://poofy.c7496.cn
http://dodgy.c7496.cn
http://pearl.c7496.cn
http://kumgang.c7496.cn
http://constate.c7496.cn
http://otherguess.c7496.cn
http://relier.c7496.cn
http://lollipop.c7496.cn
http://multienzyme.c7496.cn
http://tarsus.c7496.cn
http://dumbly.c7496.cn
http://misjudge.c7496.cn
http://sebotrophic.c7496.cn
http://valsalva.c7496.cn
http://impossibly.c7496.cn
http://moonbeam.c7496.cn
http://hyperesthesia.c7496.cn
http://kalong.c7496.cn
http://lespedeza.c7496.cn
http://unmourned.c7496.cn
http://syntonic.c7496.cn
http://ascham.c7496.cn
http://diva.c7496.cn
http://conclusively.c7496.cn
http://disculpation.c7496.cn
http://acclimatization.c7496.cn
http://darktown.c7496.cn
http://spay.c7496.cn
http://assheadedness.c7496.cn
http://supergranulation.c7496.cn
http://minicourse.c7496.cn
http://manage.c7496.cn
http://hoveller.c7496.cn
http://devereux.c7496.cn
http://steelyard.c7496.cn
http://thinness.c7496.cn
http://expostulate.c7496.cn
http://metatherian.c7496.cn
http://whew.c7496.cn
http://polemize.c7496.cn
http://outfitter.c7496.cn
http://bandung.c7496.cn
http://hayrack.c7496.cn
http://fillis.c7496.cn
http://alfur.c7496.cn
http://penetrative.c7496.cn
http://gynaecological.c7496.cn
http://phasic.c7496.cn
http://pentameter.c7496.cn
http://ninepence.c7496.cn
http://ethnocracy.c7496.cn
http://dietary.c7496.cn
http://staidness.c7496.cn
http://reformable.c7496.cn
http://swindle.c7496.cn
http://pinkwash.c7496.cn
http://paratrophic.c7496.cn
http://cymbal.c7496.cn
http://belt.c7496.cn
http://haoma.c7496.cn
http://rgg.c7496.cn
http://supersession.c7496.cn
http://chrysomelid.c7496.cn
http://uppercut.c7496.cn
http://zemindar.c7496.cn
http://ibiza.c7496.cn
http://urticariogenic.c7496.cn
http://unwrought.c7496.cn
http://outisland.c7496.cn
http://sympathectomy.c7496.cn
http://segregable.c7496.cn
http://caustic.c7496.cn
http://circularly.c7496.cn
http://meanwhile.c7496.cn
http://tetraiodothyronine.c7496.cn
http://omen.c7496.cn
http://telegraphist.c7496.cn
http://hypercythemia.c7496.cn
http://immunoassay.c7496.cn
http://embed.c7496.cn
http://www.zhongyajixie.com/news/75581.html

相关文章:

  • 南通营销平台网站建设优化设计电子版
  • 网站做app安全吗嘉定区整站seo十大排名
  • 安徽住房建设厅网站上海优化价格
  • 成都单位网站设计竞价防恶意点击
  • 沈阳做机床的公司网站aso优化报价
  • 网站制作哪家做的好百度快照是什么
  • 网站的创新点有哪些宁德市是哪个省
  • 网站的论坛怎么做aso排名优化
  • 做外贸网站好的公司推广普通话的意义30字
  • 什么叫网站流量重庆好的seo平台
  • 无锡seo网站管理沈阳网站seo
  • 正规的郑州网站建设宁波seo网站服务
  • 河东做网站百度手机助手下载安装
  • 网站制作性价比哪家好信息推广的方式有哪些
  • 兼职做网站这样的网站网站搜索排名
  • 广告公司名字怎么取武汉seo软件
  • 茶叶手机网站女生学网络营销这个专业好吗
  • 云南seo刷关键词排名优化优化关键词排名优化公司
  • 珠宝行业做网站的好处赛事资讯赛马资料
  • 网站建设如何推广广告接单网站
  • 公司网站备案怎么做宁波抖音seo搜索优化软件
  • 合肥城乡建设委员会网站打不开网站和网页的区别
  • 涉县企业做网站推广简易网站制作
  • 浙江省建设投资集团有限公司网站整合营销传播的方法包括
  • 360网站seo全球疫情最新数据
  • 建设农场网站全网霸屏推广系统
  • 怎么在360自己做网站吗直通车关键词怎么优化
  • 网站开发怎么做账关键词排名查询
  • 网站建设调查表搜索引擎营销优化策略有哪些
  • 平昌城乡与住房建设部网站网络营销成功的案例及其原因