Realistic game

Is this look realistic? It was made in UPBGE 0.36.1 and took 3 hours to make. Tell me in the comments!! :smile:

i used this script for make barrel effect for game check it:

Barrel.glsl
uniform sampler2D bgl_RenderedTexture; // Texture from the screen
uniform float focalLength = 0.6;  // Focal length (default: 0.6)
uniform float centerX = 0.5;      // Center X (default: 0.5)
uniform float centerY = 0.5;      // Center Y (default: 0.5)
uniform float scale = 0.8;        // Texture scale (default: 0.8)
uniform float k1 = 0.7;           // Radial distortion constant 1 (default: 0.7)
uniform float k2 = -0.5;          // Radial distortion constant 2 (default: -0.5)

in vec2 fragTexCoord;       // Input texture coordinate from vertex shader
out vec4 fragColor;         // Output color

void main()
{
    vec2 texcoord = fragTexCoord; // Current texture coordinates

    // Center the coordinates and scale them
    vec2 xy = (texcoord - vec2(centerX, centerY)) / vec2(focalLength) * scale;

    // Calculate radial distortion
    float r2 = dot(xy, xy);      // Squared distance
    float r4 = r2 * r2;          // Fourth power of distance
    float coeff = (k1 * r2 + k2 * r4); // Radial distortion coefficient

    // Apply distortion and restore the coordinates
    xy = xy + xy * coeff;
    xy = xy * focalLength + vec2(centerX, centerY);

    // Clamp coordinates to make sure they stay within [0, 1]
    xy = clamp(xy, 0.0, 1.0); // This ensures no out-of-bounds access

    // Sample the texture using the distorted coordinates
    fragColor = texture(bgl_RenderedTexture, xy);
}

This barrel effect script is not working and I don’t know where the error is :thinking:

1 Like

tell me here!!

it looks great
if only you used normal maps for the textures

1 Like

ok sure! i will do

1 Like

I guess you don’t provide properties for each uniform.

1 Like

How is that?

ah, no. That’s not the problem. (For each uniform you could the object have a property with that name, so you can change the value in gthe property)

This is the fix:
replace
//in vec2 fragTexCoord; // Input texture coordinate from vertex shader

with:
in vec4 bgl_TexCoord;

And
vec2 texcoord = fragTexCoord; // Current texture coordinates
with
vec2 texcoord = bgl_TexCoord.xy;

1 Like

cool!. so ill try and i will tell you result :ok_hand:

the script is working! :partying_face:
look

thank you for help! :smile:

1 Like