给定CGAL中的3D线,如何计算该线上距离端点已知距离的点?
我想将深度缓冲区保存到金属纹理中,但我尝试过的似乎都不起作用。
_renderPassDesc.colorAttachments[1].clearColor = MTLClearColorMake(0.f, 0.f, 0.f, 1.f);
[self createTextureFor:_renderPassDesc.colorAttachments[1]
size:screenSize
withDevice:_device
format:MTLPixelFormatRGBA16Float];
_renderPassDesc.depthAttachment.loadAction = MTLLoadActionClear;
_renderPassDesc.depthAttachment.storeAction = MTLStoreActionStore;
_renderPassDesc.depthAttachment.texture = self.depthTexture;
_renderPassDesc.depthAttachment.clearDepth = 1.0;
Run Code Online (Sandbox Code Playgroud)
当我传递depthTexture到我的着色器(它与来自其他纹理的数据配合良好)时,我得到的只是红色像素。
当我更改clearDepth为接近零的值时,我会得到更深的红色阴影。也许我在着色器中没有正确采样纹理?
fragment float4 cubeFrag(ColorInOut in [[stage_in]],
texture2d<float> albedo [[ texture(0) ]],
texture2d<float> normals [[ texture(1) ]],
texture2d<float> albedo2 [[ texture(2) ]],
texture2d<float> normals2 [[ texture(3) ]],
texture2d<float> lightData [[ texture(4) ]],
texture2d<float> depth [[ texture(5) ]])
{
constexpr sampler texSampler(min_filter::linear, mag_filter::linear);
return depth.sample(texSampler, in.texCoord).rgba;
}
Run Code Online (Sandbox Code Playgroud)