- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个 Metal 支持的绘图应用程序,其中通过沿着路径重复冲压纹理方 block 来在 MTKView 上绘制笔触。我在绘制笔触时在顶点级别改变图章的颜色/透明度,这样我就可以模拟墨水效果,例如颜色/透明度随着时间的推移而褪色等。当我使用时,这似乎工作正常经典的“过度”类型混合(不会随着时间的推移积累值),但是当我使用“附加”混合时,顶点透明度被完全忽略(即我只获得纹理透明度)。以下是相关代码片段:
首先,我的顶点程序:
vertex VertexOut basic_vertex(const device VertexIn* vertex_array [[ buffer(0) ]], unsigned int vid [[ vertex_id ]]) {
VertexIn VertexIn = vertex_array[vid];
VertexOut VertexOut;
VertexOut.position = float4(VertexIn.position,1);
VertexOut.color = VertexIn.color;
VertexOut.texCoord = VertexIn.texCoord;
return VertexOut;
}
接下来,我的片段程序将图章的纹理(带 Alpha)乘以顶点颜色(也带 Alpha),这是在笔触上逐渐着色或褪色每个图章所需要的
fragment float4 basic_fragment(VertexOut interpolated [[stage_in]], texture2d<float> tex2D [[ texture(0) ]], sampler sampler2D [[ sampler(0) ]])
{
float4 color = interpolated.color * tex2D.sample(sampler2D, interpolated.texCoord); // texture multiplied by vertex color
return color;
}
接下来,以下是混合定义:
// 5a. Define render pipeline settings
let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
renderPipelineDescriptor.vertexFunction = vertexProgram
renderPipelineDescriptor.sampleCount = self.sampleCount
renderPipelineDescriptor.colorAttachments[0].pixelFormat = self.colorPixelFormat
renderPipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
renderPipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
// settings for additive blending
if drawColorBlendMode == colorBlendMode.compositeAdd {
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .one
}
// settings for classic 'over' blending
if drawColorBlendMode == colorBlendMode.compositeOver {
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
}
renderPipelineDescriptor.fragmentFunction = fragmentProgram
最后,我的渲染编码:
brushTexture = MetalTexture(resourceName: "stamp_stipple1_0256", ext: "png", mipmaped: true)
brushTexture.loadTexture(device: device!, commandQ: commandQueue, flip: true)
renderCommandEncoder?.setRenderPipelineState(renderPipeline!)
renderCommandEncoder?.setVertexBuffer(vertexBuffer, offset: 0, index: 0)
renderCommandEncoder?.setFragmentTexture(brushTexture.texture, index: 0)
renderCommandEncoder?.setFragmentSamplerState(samplerState, index: 0)
我有什么遗漏的吗?如前所述,这在“over”模式下按预期工作,但在“additive”模式下则不然。同样,所需的效果是将不同的颜色/透明度设置传递给每个图章(一对纹理三角形)。
最佳答案
通过反复试验,我得到了以下设置来获得我想要的结果:
// Settings for compositeOver
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
此外,因为我正在处理许多重叠的图章,所以我必须将颜色/alpha 值除以重叠数,以避免过度饱和。我认为这最重要的是我没有按照我预期的方式看到颜色/alpha 积累的原因。
stampColor = UIColor(red: (rgba.red * rgba.alpha / numOverlappingStamps), green: (rgba.green * rgba.alpha / numOverlappingStamps), blue: (rgba.blue * rgba.alpha / numOverlappingStamps), alpha: (rgba.alpha / numOverlappingStamps))
关于swift - MTKView 顶点透明度在 "additive"混合模式下未拾取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48713020/
@秋意正寒 先讲怎么用,再讲大致原理。 1 拾取坐标 > 仅拾取椭球体表面坐标 使用 Camera.prototype.pickEllipsoid 方法,接受一个必选的屏幕坐标,返回一个三维世界坐标
我知道 OpenGL 选择模式已被弃用,并且除了少数 SGI 盒和 3DLabs GPU 之外从未进行过硬件加速。但我无法摆脱它(不是我的代码)。在其 C++ 代码下方: void GLWidget:
我有一个 .ipa,里面有 arm64 和 armv7 个片段。如果我在同时支持 arm64 和 armv7 的 iDevice 上运行它,运行时将选择哪个切片? 我可以通过打印 NSLog 或某种方
我想在建模为高度图的世界地面上的 OpenGL 场景中跟踪鼠标坐标。目前没有像硬件镶嵌这样的花哨的东西。注意这个问题是不是 关于物体拾取。 目前我正在执行以下操作,由于回读操作,这显然会降低性能: 渲
我正在将一个数组从 php 传递到 javascript,但它似乎在数组的开头和结尾处拾取了一个额外的“。 我的数组从 PHP 文件发送 json_encode($CheckItems."|".$Ch
我的光线拾取代码有问题。我的代码 我正在使用此代码进行选择计算: /*----------------------------------------------------------- Funct
我需要根据特定深度(用于光线转换)将 2D 鼠标坐标转换为 3D 世界坐标。我没有直接在 C++ 中使用 DirectX,我使用的是专有语言,但如果你用 C++ 或伪代码(首选 C++)给我一个答案,
我正在开发一款等距游戏,但在制定方 block 选择算法时遇到了问题。 这就是我渲染等距 map 的方式: for (int x = 0; x < 50; x++) { for (int y
我尝试在应用程序中导出 UTI,但 macOS (10.3.2) 未拾取它。我已经在一个较小的项目中复制了我的问题。这是 info.plist 的相关部分: UTExportedTypeDeclara
我正在尝试使用 Pyglet 的 OpenGL 包装器实现拾取,但我在转换 C tutorial 时遇到了问题到 Python。具体在下面的部分。 #define BUFSIZE 512GLuint
我有一个定义为 singleTop 的 Activity,因此只有一个实例存在。 我用一些数据设置了一个 Notification Intent,并将其包含在 PendingIntent 中,
场景中有一些物体,有些可能会遮挡其他物体。当我单击鼠标或拖动选择以获得选择矩形时,我只想选择/拾取从这个角度可以看到的对象。应用程序当前使用 GL_SELECT 渲染模式,但正如我们所知,这也会选择被
我在一个小项目中使用了SpringBootApplication。架构很简单: 入口文件: @SpringBootApplication @PropertySource("classpath:appl
我有以下媒体查询,以选择 iPad 视网膜和更小的显示器。 @media only screen and (min-device-width : 768px) and (max-device-widt
我需要将 Oauth 设置为我将要处理的 PHP 项目的一部分。 为此我跑了; sudo pecl install oauth 这完成了 OK,它指示我将 extension=oauth.so 添加到
我正在尝试使用 Angular4 和 Google Analytics 集成自定义维度。我看过类似的主题,但没有任何内容可以准确解决这个问题。 在 GA 中我设置了自定义维度: 它以索引 1 显示:
我试图阻止用户与 vtkCaptionWidget 中的 anchor 进行交互 (http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/CaptionWi
我找不到使用光线追踪方法在 3D 中拾取的正确且可理解的表达方式。有人用任何语言实现过这个算法吗?分享直接工作的代码,因为由于伪代码无法编译,所以它们通常是由缺少的部分编写的。 最佳答案 您所拥有的是
我有一个相对较新的 MVC5 项目,正在使用 TeamCity 构建并由 Octopus Deploy 部署。一切都很棒,直到我通过 NuGet 添加 SQLite。当项目构建完成后,我在 bin 目
我正在尝试使用 Spring Data REST(版本 2.3.0.RELEASE)进行预测。我读了reference documentation ,并收集到这些是我需要的部分: JPA 实体 @En
我是一名优秀的程序员,十分优秀!