mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
gpu/shaders: compensate for GPU Framebuffer => texture transformation
Add fboTextureTransform shader function for cancelling the implied transformation from fragments output by the fragment shader and the (u, v) coordinates used to sample from it in a later pass. For OpenGL the transformation is the identity. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+15
-2
@@ -1,4 +1,17 @@
|
||||
#version 310 es
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
void blah() {
|
||||
// fboTextureTransform returns a transformation
|
||||
// that cancels the implied transformation between
|
||||
// the framebuffer and its texture.
|
||||
// Only two rows are returned. The last is implied
|
||||
// to be [0, 0, 1].
|
||||
vec3[2] fboTextureTransform() {
|
||||
vec3[2] t;
|
||||
t[0] = vec3(1.0, 0.0, 0.0);
|
||||
t[1] = vec3(0.0, 1.0, 0.0);
|
||||
return t;
|
||||
}
|
||||
|
||||
vec3 transform3x2(vec3[2] t, vec3 v) {
|
||||
return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
precision highp float;
|
||||
|
||||
#include <common.inc>
|
||||
|
||||
layout(binding = 0) uniform Block {
|
||||
float z;
|
||||
vec2 scale;
|
||||
@@ -24,5 +26,7 @@ layout(location = 1) out vec2 vUV;
|
||||
void main() {
|
||||
gl_Position = vec4(pos*scale + offset, z, 1);
|
||||
vUV = uv*uvScale + uvOffset;
|
||||
vCoverUV = uv*uvCoverScale+uvCoverOffset;
|
||||
vec3[2] fboTrans = fboTextureTransform();
|
||||
vec3 uv3 = transform3x2(fboTrans, vec3(uv, 1.0));
|
||||
vCoverUV = (uv3*vec3(uvCoverScale, 1.0)+vec3(uvCoverOffset, 0.0)).xy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user