2017-07-30 99 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