• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Mac OSX Different result for a shader in mac

Ido-f

Member
Hi,
Running the same shader for the plane sprite from windows and mac,
windows gets the intended results:
Capture.PNG
But running it from my macbook air 2017 this image is being produced:
Screen Shot 2019-04-13 at 4.00.09.png

(again, this is regarding the plane sprite, the background difference is unrelated)

The shader is being compiled and applied, the base sprite would have had grey filling and no noise at all.
But on the mac the bright lines are horizontal and fragmented for some reason, instead of vertical.

Any idea for why that is/how it could be fixed?
Here's the code for the shader (u_time is the red number in the top left corner minus 28, so 0.76 in the pictures. I think the problematic parts are the EllipseDistort and VertDist functions):

Code:
//
//  vertex shader
//
attribute vec3 in_Position;                  // (x,y,z)
//attribute vec3 in_Normal;                  // (x,y,z)     unused in this shader.
attribute vec4 in_Colour;                    // (r,g,b,a)
attribute vec2 in_TextureCoord;              // (u,v)

varying vec2 v_vTexcoord_A;
varying vec2 v_vTexcoord_B;
varying vec2 v_vTexA_N;

uniform vec4 u_smp_dim; //startx, starty, width, height
uniform vec4 u_src_uv;

void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
 
    v_vTexcoord_A = in_TextureCoord;
    v_vTexA_N = (in_TextureCoord-u_src_uv.xy)/u_src_uv.zw;
    v_vTexcoord_B = (in_Position.xy-u_smp_dim.xy)/u_smp_dim.zw;
 
}
Code:
//
// fragment shader
//
varying vec2 v_vTexcoord_A;
varying vec2 v_vTexcoord_B;
varying vec2 v_vTexA_N;

const vec2 vert_wrap_weights = vec2(1.995, 0.005); //x+y=2, weights inside the sqrt of distance calculations
const float line_radius = 0.1; //in normalised uv
const float lines_num = 7.0;
const float line_base_spd = 0.075;
const float line_range_spd = 0.025;
const float line_brightness = 0.5;

uniform float u_alpha;
uniform float u_time;

float Random (float seed)
{
    return fract(sin(seed*12.9898+seed*78.233)*43758.5453);
}

vec3 Noise (vec2 _pos, float _brightness)
{
    float _val = fract(sin(dot(_pos*u_time ,vec2(12.9898,78.233))) * 43758.5453);
    return mix(vec3(0.0), vec3(_val), _brightness);
}

float VertDist (vec2 _pos1, vec2 _pos2)
{
    vec2 _d = _pos1 - _pos2;
    _d *= _d;
    return sqrt(dot(vert_wrap_weights, _d)); //basically an axis weighted distance calculation
}

float EllipseDistort (vec2 _pos1, vec2 _pos2)
{
    return (VertDist(_pos1, _pos2)/line_radius);
}

void main()
{
    vec4 src_col = texture2D( gm_BaseTexture, v_vTexcoord_A );
    vec2 _coords = vec2(v_vTexA_N.x, v_vTexcoord_B.y);
    float _brightness = 1.0;
    for (float i; i<lines_num; i++)
    {
        float _line_spd = line_base_spd+mix(-line_range_spd, line_range_spd, Random(i));
        float _line_x = mix(    -line_radius, 1.0+line_radius,
                                mod(Random(lines_num+i)+ _line_spd*u_time, 1.0));
        _brightness = min(_brightness, mix(line_brightness, 1.0, EllipseDistort(_coords, vec2(_line_x, 0.5))));
    }
 
    _brightness = abs(1.0-tan(_brightness+u_time));
 
    vec4 noise_col = vec4(Noise(v_vTexcoord_B, _brightness), src_col.a);
    vec4 col = mix(noise_col, src_col, u_alpha);
 
    //use step and mix to simulate branching in an old hardware friendly way
    float _replace = step(src_col.r, 0.1);
    gl_FragColor = mix(col, src_col, _replace);
}
 
Last edited:
Top