Graphics Reference
In-Depth Information
public float Intensity;
public Vector3 _padding0;
}
Remember that constant buffers are aligned to 16 bytes, so we need
to include the additional Vector3 padding property (12 bytes).
3.
Create and update the constant buffer as shown here:
var computeBuffer = new Buffer(device,
Utilities.SizeOf<ComputeConstants>(),
ResourceUsage.Default, BindFlags.ConstantBuffer,
CpuAccessFlags.None, ResourceOptionFlags.None, 0);
var constants = new ComputeConstants {
Intensity = 0.5f
};
context.UpdateSubresource(ref constants, computeBuffer);
4.
Next, set the constant buffer to the compute shader pipeline stage:
context.ComputeShader.SetConstantBuffer(0, computeBuffer);
5. And finally we change our compute shader code so that it interpolates the values,
gradually adding gray to the result:
output[dispatchThreadId.xy] = float4(lerp(target, sample.rgb,
Intensity), sample.a) ;
With the lerp in place, it is now possible to control the level of saturation/desaturation with
negative/positive values for Intensity , respectively. The following figure shows the results
of applying different interpolation amounts, starting with (A) normal image at 1.0, (B) half
desaturated at 0.5, (C) oversaturated at 2.0, and (D) desaturated using 0.0:
Various levels of saturation - A: original, B: half desaturation, C: 100 percent saturation, D: 100 percent desaturation
 
Search WWH ::




Custom Search