2026-03-18 20:09:32 +03:00

26 lines
901 B
Plaintext

// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D<float4> Camera1;
RWTexture2D<float4> Camera2;
RWTexture2D<float4> Result;
RWTexture2D<float4> Test;
RWStructuredBuffer<float> MonoChannelResult;
float ResX;
float Offset;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
int2 idxy1 = int2(clamp(id.x + Offset, 0, ResX), id.y);
int2 idxy2 = int2(clamp(id.x - Offset, 0, ResX), id.y);
float diffFactor = saturate(id.x - Offset) * saturate(ResX - (id.x + Offset));
float4 resVal = float4(((Camera1[idxy1] * diffFactor + Camera2[idxy2] * diffFactor) / 2).xyz, 1);
Result[id.xy] = resVal;
MonoChannelResult[id.x + id.y * ResX] = resVal.r;
//Test[id.xy] = resVal.w; //MonoChannelResult[id.x + id.y * ResX];
}