Skip to main content

ComputeShaderDarknessReader

A class in Root.Township, the global namespace.

Client: darkness reader method that copies the player camera image each frame and measures how dark it is with a compute shader. When it's too dark, it calls the spawn request (from DarknessReader).

Constructors​

MemberWhat it is
ComputeShaderDarknessReader(DarknessReader reader, PlayerController character, Action requestSpawn)Creates a ComputeShaderDarknessReader from reader, character and requestSpawn.

Fields​

21 private and internal fields
MemberWhat it is
private static readonly int _ColorFilterShader property id for _ColorFilter.
private static readonly int _FinalResultsShader property id for _FinalResults.
private static readonly int _InputShader property id for _Input.
private static readonly int _MaxTotalDarknessShader property id for _MaxTotalDarkness.
private static readonly int _MaxValueShader property id for _MaxValue.
private static readonly int _ResultsCountShader property id for _ResultsCount.
private static readonly int _ResultsSumShader property id for _ResultsSum.
private static readonly int _TempRTShader property id for _TempRT. Not used.
private int BufferClearKernelKernel index that clears the result buffers.
private CommandBuffer cameraBufferCommand buffer that copies the camera image to samplingRT.
private ComputeShader computeShaderThe darkness compute shader from the reader settings.
private int DarknessReadKernelKernel index that samples the image into per-group sums and counts.
private int DarknessResultKernelKernel index that reduces the sums to one value.
private ComputeBuffer finalResultBufferOne-value buffer with the final darkness result.
private int heightSample texture height, the camera height scaled by DownSampleScale.
private ComputeBuffer resultCountBufferBuffer of 256 per-group sample counts.
private ComputeBuffer resultSumBufferBuffer of 256 per-group darkness sums.
private RenderTexture samplingRTDown-scaled temporary copy of the camera image.
private Camera targetCameraThe player's camera.
private static readonly CameraEvent targetCameraEventCamera event the copy runs at, after opaque image effects.
private int widthSample texture width, twice the scaled camera width.

Methods​

MemberWhat it is
protected override void DisableInternal()Removes the camera command buffer, stops the loop and releases the texture and buffers.
protected override void EnableInternal()Adds a command buffer that copies the camera image, sets up compute buffers and shader values, and starts the loop.
1 private and internal method
MemberWhat it is
private IEnumerator UpdateLoop() (iterator)Every ReadDarknessFrequency seconds, runs the kernels and calls the spawn request if darkness passes MaxTotalDarkness.