【发布时间】:2018-01-05 22:43:29
【问题描述】:
我正在编写一个金属着色器。
我想要的只是访问片段的当前颜色。
例如。
在我的片段着色器的末尾,当我把 返回 currentColor + 0.1,例如
结果将是在 FPS 时屏幕从黑色变为白色。 这是一个绘制填充屏幕的三角形条的基本程序。 最终目标是在着色器中编写路径跟踪器,我用 opengl + glsl 完成了这个。 我在使用缓冲区时遇到问题。我认为一个简单的解决方案是将当前输出颜色传回着色器并在那里平均。
这些是着色器:
#include <metal_stdlib>
using namespace metal;
#import "AAPLShaderTypes.h"
vertex float4 vertexShader(uint vertexID [[vertex_id]], constant AAPLVertex *vertices [[buffer(AAPLVertexInputIndexVertices)]], constant vector_uint2 *viewportSizePointer [[buffer(AAPLVertexInputIndexViewportSize)]], constant vector_float4 * seeds) {
float4 clipSpacePosition = vector_float4(0.0, 0.0, 0.0, 1.0);
float2 pixelSpacePosition = vertices[vertexID].position.xy;
vector_float2 viewportSize = vector_float2(*viewportSizePointer);
clipSpacePosition.xy = pixelSpacePosition / (viewportSize / 2.0);
return clipSpacePosition;
}
fragment float4 fragmentShader()
{
// I want to do this
// return currentColor + 0.1;
return float4(1.0, 1.0, 1.0, 1.0);
}
【问题讨论】:
标签: fragment-shader raytracing metal