Graphics Reference
In-Depth Information
return float4(lerp(source, target.rgb, T), target.a);
}
// Adjust the image contrast
[numthreads(THREADSX, THREADSY, 1)]
void ContrastCS(uint groupIndex : SV_GroupIndex,
uint3 groupId : SV_GroupID,
uint3 groupThreadId: SV_GroupThreadID,
uint3 dispatchThreadId : SV_DispatchThreadID)
{
float4 sample = input[dispatchThreadId.xy];
// Adjust contrast by moving towards or away from gray
// Note: if LerpT == -1, we achieve a negative image
// LerpT == 0.0 will result in gray
// LerpT == 1.0 will result in no change
// LerpT > 1.0 will increase contrast
float3 target = float3(0.5,0.5,0.5);
output[dispatchThreadId.xy] = lerpKeepAlpha(target,
sample, LerpT);
}
2.
Next, we compile the shader as in the previous recipe; the only change is that we
must update the constant buffer before dispatching the compute shader threads:
// Set the source resource
context.ComputeShader.SetShaderResource(0, srcTextureSRV);
// Set the destination resource
context.ComputeShader.SetUnorderedAccessView(0, targetUAV);
context.ComputeShader.Set(cs);
var computeBuffer = new Buffer(device, Utilities.
SizeOf<ComputeConstants>(), ResourceUsage.Default, BindFlags.
ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
var constants = new ComputeConstants { LerpT = 0.5f };
context.UpdateSubresource(ref constants, computeBuffer);
// e.g. 640x480 -> Dispatch(20, 15, 1);
context.Dispatch(desc.Width / 32, desc.Height / 32, 1);
3.
Next, we will implement a similar shader to adjust the brightness of the image.
Everything is as per the ContrastCS shader; however, this time we set the target
variable to black:
// Adjust brightness by adding or removing Black
// LerpT == 1.0 original image
// LerpT > 1.0 brightens
// LerpT < 1.0 darkens
 
Search WWH ::




Custom Search