Saturday, August 27, 2022
HomeGame Developmentshaders - Generate Uniform distances in Distance Subject with out Sq. Textures?

shaders – Generate Uniform distances in Distance Subject with out Sq. Textures?


Following this Godot Tutorial I have been implementing a shader for 2D international illumination. Within the tutorial it mentions including a UV to World side ratio change throughout the raymarching perform to right distances which can be biased in the direction of both X or Y axis (relying on decision). This technique works, however is it potential to use this correction throughout the distance area shader itself?

Hopefully most of this is smart in case you’ve been paying consideration up till now. One presumably obscure half is perhaps remodeling the UV to world side ratio. We have to do that if our viewport is rectangular or our distances will probably be totally different relying on whether or not they’re biased in the direction of the X or X axis. We’ll have to translate again to UV house earlier than sampling any enter textures.

My authentic thought was to use this remodel to the coordinates themselves throughout the distance area shader, however I’ve not gotten anyplace with that implementation.

That is my present distance area fragment shader: (converts the output distance to a vec2 for elevated precision–because I am utilizing GameMaker which makes use of 8-bit RGBA elements for floor textures which can’t be modified)

various vec2 in_Coord; // UV coordinate of the present pixel fragment.
uniform vec2 in_Resol; // Width,Peak of the render decision.

// Converts a float to a normalized vec2().
float V2_F16(vec2 v) { return v.x + (v.y / 255.0); }
// Converts a normalized vec2() to a float.
vec2 F16_V2(float f) { return vec2(ground(f * 255.0) / 255.0, fract(f * 255.0)); }

void primary() {
    // Distance Subject from Leap Flood texture.
    vec4 jfuv = texture2D(gm_BaseTexture, in_Coord);
    vec2 jumpflood = vec2(V2_F16(jfuv.rg),V2_F16(jfuv.ba));
    gl_FragColor = vec4(F16_V2(distance(in_Coord, jumpflood)), 0.0, 1.0);
}

FIGURE A: (Rectangular Viewport/Decision)
enter image description here
FIGURE B: (Sq. Viewport/Decision)
enter image description here

The sq. output produces a way more uniform lighting output whereas the oblong viewport has a biased x-component when sampling the space texture which causes mild to unfold horizontally extra. (FIGBURE C) Whereas the sq. viewport is extra visually uniform. (FIGURE D)

FIGURE C:
enter image description here
FIGURE D:
enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments