yuqian
June 16, 2022, 3:45am
1
);
this._depthTexture = depthTexture;
this.onApplyObservable.add((effect: Effect) => {
if (!this._depthTexture) {
Logger.Warn("No depth texture set on CircleOfConfusionPostProcess");
return;
}
effect.setTexture("depthSampler", this._depthTexture);
// Circle of confusion calculation, See https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch23.html
const aperture = this.lensSize / this.fStop;
const cocPrecalculation = (aperture * this.focalLength) / (this.focusDistance - this.focalLength); // * ((this.focusDistance - pixelDistance)/pixelDistance) [This part is done in shader]
effect.setFloat("focusDistance", this.focusDistance);
effect.setFloat("cocPrecalculation", cocPrecalculation);
effect.setFloat2("cameraMinMaxZ", this._depthTexture.activeCamera!.minZ, this._depthTexture.activeCamera!.maxZ);
});
}
/**
* Depth texture to be used to compute the circle of confusion. This must be set here or in the constructor in order for the post process to function.
I Notice this line: aperture = this.lensSize / this.fStop
But isn’t fStop = focalLength / aperture
so aperture = focalLength / fStop
?
I wonder about the lensSize
here
Yup you are fully right and as I remember it in most setup and any realistic one, focalLenght should be equal to lensSize. It is actually weird to have both defined separately and can not happen on a camera I guess but it provides nice artistic tricks on how it might impact the shader.