I'm new to shaders and currently following along in Godot with The Book of Shaders.

I noticed that when I color the albedo with:

void fragment() {
	vec2 st = FRAGCOORD.xy / VIEWPORT_SIZE;
	ALBEDO = vec3(st.r, st.g, 0.0);
}

The color of my PlaneMesh changes as I zoom in and out of the editor. I assume this is because FRAGCOORD is in terms of screen space so as I zoom in the amount of space it takes up is closer to the 0 and 1 of my normalized coordinates?

The following image is what I see zoomed out when using the above snippet.

The following image is what I see zoomed in when using the above snippet.

The following image is what I see when I switch to using UV instead.

If I want to essentially, have it span the entire [0,1) coordinate range do I just use UV? Is there any time when that wouldn't be a good idea?

Is SCREEN_UV the same as FRAGCOORD.xy / VIEWPORT_SIZE?
 
Sorry if I'm using the wrong technical terms as well.

  • xyz replied to this.

    LoganD FRAGCOORD has nothing to do with "zoom". It is a coordinate of the pixel in the viewport. If the viewport size is 1920x1080, FRAGCOORD.x will be in range 0-1920, and FRAGCOORD.y in range 0-1080. Pixel (0,0) is top-left in the viewport. It's totally irrelevant what's in the viewport. FRAGCOORD doesn't care about that.

    UV is object's texture coordinate. For a default quad it'll always be in 0-1 range in both directions.

    Like I said, apologies for the wrong use of terms. I understand that FRAGCOORD isn't related with "zoom", however I was implying that when you "zoom" in objects appear larger. When they "take up" up the entire screen the FRAGCOORD.x values will span the entire range 0-1920. However, if I "zoom" out and the object no longer spans the entire screen, the FRAGCOORD.x values might be something like 720-1200.

    If I map the FRAGCOORD.x values to the ALBEDO red channel for instance the color will change as I "zoom" in and out since the actual range of supplied "FRAGCOORD" values will change as well.

    My question is:

    • How do I normalize FRAGCOORD values to span the entire 0-1 range? Or should I not be using FRAGCOORDs at all?
    • xyz replied to this.

      LoganD How do I normalize FRAGCOORD values to span the entire 0-1 range?

      Entire 0-1 range of what?
      FRAGCOORD spans the viewport. Whatever happens to be rendered at a certain fragment, will get the color you assign to that fragment.
      If you want to map something to an object, use object's UV.