Refactor: Optimize compositor realization shader
This patch optimizes the compositor realization shader by moving the centring offset to the host code as opposed to the shader.
This commit is contained in:
@@ -85,9 +85,16 @@ void realize_on_domain(Context &context,
|
||||
const float3x3 transformation = math::from_origin_transform<float3x3>(
|
||||
local_transformation, float2(domain.size) / 2.0f);
|
||||
|
||||
/* Since an input image with an identity transformation is supposed to be centered in the domain,
|
||||
* we center the input by translating by the difference between the lower left corners of the
|
||||
* input image and the domain, which is half the difference between their sizes, because the
|
||||
* difference in size is on both sides of the centered image. */
|
||||
const float3x3 centered_transformation = math::translate(
|
||||
transformation, float2(domain.size - input_domain.size) / 2.0f);
|
||||
|
||||
/* Invert the transformation because the shader transforms the domain coordinates instead of the
|
||||
* input image itself and thus expect the inverse. */
|
||||
float3x3 inverse_transformation = math::invert(transformation);
|
||||
float3x3 inverse_transformation = math::invert(centered_transformation);
|
||||
|
||||
/* Bias translations in case of nearest interpolation to avoids the round-to-even behavior of
|
||||
* some GPUs at pixel boundaries. */
|
||||
|
||||
@@ -17,17 +17,9 @@ void main()
|
||||
* coordinates should be in homogeneous coordinates. */
|
||||
coordinates = (mat3(inverse_transformation) * vec3(coordinates, 1.0)).xy;
|
||||
|
||||
/* Since an input image with an identity transformation is supposed to be centered in the domain,
|
||||
* we subtract the offset between the lower left corners of the input image and the domain, which
|
||||
* is half the difference between their sizes, because the difference in size is on both sides of
|
||||
* the centered image. */
|
||||
ivec2 domain_size = imageSize(domain_img);
|
||||
ivec2 input_size = texture_size(input_tx);
|
||||
vec2 offset = vec2(domain_size - input_size) / 2.0;
|
||||
|
||||
/* Subtract the offset and divide by the input image size to get the relevant coordinates into
|
||||
* the sampler's expected [0, 1] range. */
|
||||
vec2 normalized_coordinates = (coordinates - offset) / vec2(input_size);
|
||||
vec2 normalized_coordinates = coordinates / vec2(texture_size(input_tx));
|
||||
|
||||
imageStore(domain_img, texel, SAMPLER_FUNCTION(input_tx, normalized_coordinates));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user