使用computeshader对图片像素点进行操作。
使用computeshader生成渐变图像,与遮罩图进行混合。
根据传入的参数,将混合后的遮罩图根据灰度转换到色彩。
// 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> Result;
RWTexture2D<float4> _Mask;
RWStructuredBuffer<float4> _colors;
float offset;
float intension;
float clamp;
float value;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
float v = id.x / 256.0f;
//遮罩计算,根据v生成渐变图,乘边缘强度,加偏移量,乘mask贴图
Result[id.xy] = float4(v*intension + offset, v*intension + offset, v*intension + offset, 1)*_Mask[id.xy];
float4 f4 = Result[id.xy];
float f = f4.r*clamp;
if (f > clamp)
f = clamp;
if (f < 0)
f = 0;
R