2017-07-30 94 views
0

我在写金属着色器。金属碎片着色器,访问当前帧缓冲区颜色

我想要的只是访问片段的当前颜色。

例如。

在我的片段着色器,结束的时候,我把 回报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); 
} 

回答

0

不用担心,得到的答复是整个时间盯着我的脸。

通行证在当前颜色分为采用float4 COLOR0片段着色器[[色(0)]]

通过这些2个选项设置 renderPassDescriptor.colorAttachments [0] = .storeAction MTLStoreActionStore; renderPassDescriptor.colorAttachments [0] .loadAction = MTLLoadActionLoad;

我的问题不是颜色,它是在计算平均值。 在我的情况下,我不能做正常的平均值,如加起来的所有颜色,除以样本数量。

我真正需要做的是计算一个移动平均值。

https://en.wikipedia.org/wiki/Moving_average#Cumulative_moving_average