我在寫金屬着色器。金屬碎片着色器,訪問當前幀緩衝區顏色
我想要的只是訪問片段的當前顏色。
例如。
在我的片段着色器,結束的時候,我把 回報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);
}