What kind of behavior does this shader do?

How does this shader fit in the imageResolution with the vertical and horizontal values of the image?

shader.vert

attribute vec3 position;
attribute vec2 uv;
varying vec2 vUv;

void main(void) {
    vUv = uv;
    gl_Position = vec4(position, 1.0);
}

shader.frag

uniform vec2 resolution;
uniform vec2 imageResolution;
uniform sampler2D texture;
varying vec2 vUv;

void main(void) {
    vec2 ratio = vec2(
                      min((resolution.x / resolution.y) / (imageResolution.x / imageResolution.y), 1.0),
                      min((resolution.y / resolution.x) / (imageResolution.y / imageResolution.x), 1.0)              );
    vec2 uv = vec2(
                   vUv.x * ratio.x + (1.0 - ratio.x) * 0.5,
                   vUv.y * ratio.y + (1.0 - ratio.y) * 0.5
                   );
    
    gl_FragColor = texture2D(texture, uv);
}

What happens to the image read as a texture?

have you tried ? :wink:

I did it, but there was no reaction.

void ofApp::setup(){
    ofShader imageshader;
    ofImage img;

    imageshader.load("Shaders/image.vert", "Shaders/image.frag");    
    img.load("download.jpg");
}

void ofApp::update(){
}

void ofApp::draw(){
    imageshader.begin();
    imageshader.setUniform2f("resolution", ofGetWidth(), ofGetHeight());
    imageshader.setUniform2f("imageResolution",img.getWidth(), img.getHeight());
    imageshader.setUniformTexture("texture", img.getTexture(), 0);
    ofRect(0,0,ofGetWidth(), ofGetHeight());
    imageshader.end();   
}

Is this writing way wrong?

it looks correct to me. But what do you mean as “reaction”? is this shader supposed to do change the image or not?
maybe this shader is just used to center the image in the screen.
What are you trying to do?