Asset - Shaders TMC LUX Lighting Engine

icuurd12b42

TMC Founder
GMC Elder
Since I can no longer update my assets, here is the fix for GMS2 2.1.5.246
Picture In Picture GMS2 2.1.5.246 bug fix
script:
tmc_lux_do_sprited_lights
under:
scripts/TMC_LUX/Core Nothing To See Here/

Code:
//tmc_lux_do_sprited_lights()
if(global.tmc_lux_sprited_lights_on == 0) exit;
var success = false;
//show_debug_message(global.tmc_lux_sprited_shadows_at);
if(global.tmc_lux_sprited_lights_at or global.tmc_lux_sprited_shadows_at or global.tmc_lux_light_at)
{
   // dbug why only one shadow is drawn
    //if we are doing the app surface vesion
    if(!global.tmc_lux_sprited_lights_compatibility_mode && surface_exists(application_surface) && application_surface_is_enabled())
    {
        //do the application surface method 
        var as_w = surface_get_width(application_surface);
        var as_h = surface_get_height(application_surface);
        var xs = as_w/__view_get( e__VW.WView, 0 );
        var ys = as_h/__view_get( e__VW.HView, 0 );
        //if full on lighting blend with back buffer
        if(global.tmc_lux_sprited_lights_on_surface)
        {
            //grab the content of the application surface to the buffer
            global.tmc_lux_back_buffer = tmc_lux_safe_surface_create(global.tmc_lux_back_buffer,as_w,as_h);
            var as_clone = global.tmc_lux_back_buffer;
            if(as_clone!=-1)
            {
                draw_set_blend_mode(bm_normal);
                draw_enable_alphablend(0)
                surface_copy(as_clone,0,0,application_surface);
                //surface_set_target(as_clone);
                //draw_text_colour(100,100,"WTF",c_white,c_white,c_white,c_white,1);
                //surface_reset_target();
                draw_enable_alphablend(1)
                var viewx1 = 0,
                    viewy1 = 0,
                    viewx2 = __view_get( e__VW.WView, 0 ),
                    viewy2 = __view_get( e__VW.HView, 0 );
                 
                if(global.tmc_lux_sprited_shadows_on)
                {
                    if(global.tmc_lux_sprited_shadows_at)
                    {
                        global.tmc_lux_lights_buffer = tmc_lux_safe_surface_create(global.tmc_lux_lights_buffer,as_w,as_h);   
                        var surf_lights = global.tmc_lux_lights_buffer;
                        var processed_spr_lights = 0;
                        var processed_spr_lights_at = 0;
                        var processed_lights = 0;
                        var processed_lights_at = 0;
                        if(surf_lights!=-1)
                        {
                            surface_set_target(surf_lights);
                            {
                                draw_clear_alpha(c_black,0);
                                draw_set_blend_mode(bm_add);
                                var PlanePoint = tmc_lux_vect3(0,0,0);
                                var PlaneNormal = tmc_lux_vect3(0,0,1);
                                var out_IntersectPoint = tmc_lux_vect3(0,0,0);
                                var shadowEndPos = tmc_lux_vect3(0,0,0);
                                var shadowPos = tmc_lux_vect3(0,0,0);
                                var Segment = tmc_lux_segment(shadowPos,shadowEndPos);
                                var Direction3d = tmc_lux_vect3(0,0,0);
                                var cone_facing = tmc_lux_vect3(0,0,0);
                                var light,shadow,lx,ly,dx,dy,sx,sy,sz,dz,lzf,fac,range,dist,radius;
                                d3d_set_fog(1,c_white,0,0);
                                for(var j = 0; j<global.tmc_lux_sprited_shadows_at; ++j)
                                {
                                    shadow = global.tmc_lux_sprited_shadows[j];
                                 
                                    sz = shadow[SPRITED_SHADOWS.Z];
                                    sx = shadow[SPRITED_SHADOWS.X];
                                    sy = shadow[SPRITED_SHADOWS.Y];
                                    radius = shadow[SPRITED_SHADOWS.RADIUS];
                                    shadowPos[@0] = sx;
                                    shadowPos[@1] = sy;
                                    shadowPos[@2] = sz;
                                    for(var i = 0; i< global.tmc_lux_sprited_lights_at; ++i)
                                    {
                                        light = global.tmc_lux_sprited_lights[i];
                                        if(light[SPRITED_LIGHT.SHADOW_PROCESSED]==0)
                                        {
                                            if(light[SPRITED_LIGHT.SHADOW_CASTING]!=0)
                                            {
                                                lz = light[SPRITED_LIGHT.Z];
                                                lzf = lz;
                                                dz = sz-lz;
                                                var doit = lz>depth;
                                                //light[@SPRITED_LIGHT.SHADOW_PROCESSED] = doit;
                                                if(dz>1 and doit)
                                                {
                                                    processed_spr_lights[processed_spr_lights_at++] = i;
                                                    range = light[SPRITED_LIGHT.RADIUS];
                                                 
                                                    lx = light[SPRITED_LIGHT.X];
                                                    ly = light[SPRITED_LIGHT.Y];
                                                    lz = sz-400;
                                                    dist = point_distance(lx,ly,sx,sy);
                                                    //db[0] = range;
                                                    //db[1] = radius;
                                                    range+=radius;
                                                    //db[2] = range;
                                                    //show_debug_message(db)
                                                    //draw_circle_colour((lx-view_xview)* xs,(ly-view_yview)* ys,range* xs,c_dkgray,c_dkgray,1)
                                                     
                                                    if(dist<range)
                                                    {
                                                        Direction3d[@0] = sx-lx;
                                                        Direction3d[@1] = sy-ly;
                                                        Direction3d[@2] = sz-lz;
                                                        tmc_lux_vect_norm_self(Direction3d);
                                                        tmc_lux_vect_multr_self(Direction3d,10000000);
                                                        shadowEndPos[@0] = sx+Direction3d[0];
                                                        shadowEndPos[@1] = sy+Direction3d[1];
                                                        shadowEndPos[@2] = sz+Direction3d[2];
                                                     
                                                        //dx = sx-lx;
                                                        //dy = sy-ly;
                                                        //d = point_distance_3d(0,0,0,dx,dy,dz);
                                                        //fac = lzf+(dz)
                                                        //sx += dx*(d);
                                                        //sy += dy*(d);
                                                        if(tmc_lux_segment_intersect_plane(Segment, PlanePoint, PlaneNormal, out_IntersectPoint))
                                                        {
                                                         
                                                            var xx = (out_IntersectPoint[0]-__view_get( e__VW.XView, 0 ));
                                                            var yy = (out_IntersectPoint[1]-__view_get( e__VW.YView, 0 ));
                                                            if(xx+radius>viewx1 && xx-radius<viewx2 && yy+radius>viewy1 && yy-radius<viewy2)
                                                            {
                                                                draw_sprite_ext(
                                                                    shadow[SPRITED_SHADOWS.SPRITE],
                                                                    shadow[SPRITED_SHADOWS.INDEX],
                                                                    xx*xs,
                                                                    yy*ys,
                                                                    shadow[SPRITED_SHADOWS.XSCALE] * xs,
                                                                    shadow[SPRITED_SHADOWS.YSCALE] * ys,
                                                                    shadow[SPRITED_SHADOWS.ROT],
                                                                    c_white,
                                                                    shadow[SPRITED_SHADOWS.ALPHA]*(1-(dist/range)) * light[SPRITED_LIGHT.SHADOW_CASTING]
                                                                );
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    for(var i = 0; i< global.tmc_lux_light_at; ++i)
                                    {
                                        light = global.tmc_lux_lights[i];

                                        if(light[LIGHT.SHADOW_PROCESSED]==0)
                                        {
                                            if(light[LIGHT.SHADOW_CASTING]!=0)
                                            {
                                                lz = light[LIGHT.Z];
                                                lzf = lz;
                                                dz = sz-lz;
                                                if(dz>1)
                                                {
                                                    range = light[LIGHT.RANGE];
                                                 
                                                    lx = light[LIGHT.X];
                                                    ly = light[LIGHT.Y];
                                             
                                                    dist = point_distance_3d(lx,ly,lz,sx,sy,sz);
                                                    var doit = lz>depth;
                                                    //light[@LIGHT.SHADOW_PROCESSED] = doit;
                                                    if(dist<range and doit)
                                                    {
                                                        processed_lights[processed_lights_at++] = i;                                             
                                                        Direction3d[@0] = sx-lx;
                                                        Direction3d[@1] = sy-ly;
                                                        Direction3d[@2] = sz-lz;
                                                        tmc_lux_vect_norm_self(Direction3d);
                                                     
                                                     
                                                        //cone linmits
                                                        var cut_off = light[@LIGHT.CONE_CO]; //-2 is shere, -1 is a dimple sphere. .5 is half a sphere. .9 is a tight cone. must exclude 1
                                                        var cone_dot = 1;
                                                        if(cut_off>-2)
                                                        {
                                                            cone_facing[@0] = light[@LIGHT.FX];
                                                            cone_facing[@1] = light[@LIGHT.FY];
                                                            cone_facing[@2] = light[@LIGHT.FZ];
                                                            tmc_lux_vect_norm_self(cone_facing);
                                                            cone_dot = (tmc_lux_vect_dot(cone_facing,Direction3d) - cut_off)/(1.0-cut_off);
                                                            //vec3 cone_dir = normalize(vec3(-light[@LIGHT.FX],-light[@LIGHT.FY],light[@LIGHT.FZ]));
                                                            //cone_dir = normalize(vec3((cone_dir.x) * x_cosine - (cone_dir.y) * y_sine,
                                                            //                    (cone_dir.x) * y_sine + (cone_dir.y) * x_cosine,
                                                            //                    cone_dir.z));
                                                            // cone_dot = (dot(cone_dir,Final_Light)-cut_off)/(1.0-cut_off);
                                                            //db[0] = cone_facing;
                                                            //db[1] = Direction3d;
                                                            //db[2] = dot_product_3d_normalised(cone_facing[@1],cone_facing[@2],cone_facing[@3],Direction3d[@1],Direction3d[@2],Direction3d[@3]);
                                                            //db[3] = tmc_lux_vect_dot(cone_facing,Direction3d);
                                                            //db[4] = cone_dot;
                                                            //cone_dot=tmc_lux_vect_dot(cone_facing,Direction3d)-cut_off;
                                                            //db[0] = cone_dot;
                                                            //db[1] = tmc_lux_vect_dot(cone_facing,Direction3d);
                                                            //show_debug_message(db)
                                                            cone_dot = clamp(cone_dot,0.0,0.5) * 2;
                                                         
                                                        }
                                                     
                                                         
                                                         
                                                     
                                                        tmc_lux_vect_multr_self(Direction3d,10000000);
                                                        shadowEndPos[@0] = sx+Direction3d[0];
                                                        shadowEndPos[@1] = sy+Direction3d[1];
                                                        shadowEndPos[@2] = sz+Direction3d[2];
                                                     
                                                        //dx = sx-lx;
                                                        //dy = sy-ly;
                                                        //d = point_distance_3d(0,0,0,dx,dy,dz);
                                                        //fac = lzf+(dz)
                                                        //sx += dx*(d);
                                                        //sy += dy*(d);
                                                        if(cone_dot>0 and tmc_lux_segment_intersect_plane(Segment, PlanePoint, PlaneNormal, out_IntersectPoint))
                                                        {
                                                            var xx = (out_IntersectPoint[0]-__view_get( e__VW.XView, 0 ));
                                                            var yy = (out_IntersectPoint[1]-__view_get( e__VW.YView, 0 ));
                                                            if(xx+radius>viewx1 && xx-radius<viewx2 && yy+radius>viewy1 && yy-radius<viewy2)
                                                            {
                                                                //range = point_distance_3d(lx,ly,lz,out_IntersectPoint[0],out_IntersectPoint[1],out_IntersectPoint[2])
                                                                // var att = 2000.0 / (light[LIGHT.FALLOFF] + (light[LIGHT.FALLOFF]*range) + (light[LIGHT.FALLOFF]*range*range)); 
                                                                range = tmc_lux_range_from_falloff(light[LIGHT.R],light[LIGHT.G],light[LIGHT.B],light[LIGHT.POWER],light[LIGHT.FALLOFF],light[LIGHT.RANGE])
                                                                //arr[0] = dist;
                                                                //arr[1] = range;
                                                                range *= light[LIGHT.SHADOW_CASTING];
                                                                //arr[2] = range;
                                                                //arr[3] = shadow[SPRITED_SHADOWS.ALPHA]*(1-(dist/range)) *cone_dot * light[LIGHT.SHADOW_CASTING];
                                                                //show_debug_message(arr);
                                                                if(dist<range)
                                                                {
                                                                    draw_sprite_ext(
                                                                        shadow[SPRITED_SHADOWS.SPRITE],
                                                                        shadow[SPRITED_SHADOWS.INDEX],
                                                                        xx * xs,
                                                                        yy * ys,
                                                                        shadow[SPRITED_SHADOWS.XSCALE] * xs,
                                                                        shadow[SPRITED_SHADOWS.YSCALE] * ys,
                                                                        shadow[SPRITED_SHADOWS.ROT],
                                                                        c_white,
                                                                        shadow[SPRITED_SHADOWS.ALPHA]*(1-(dist/range)) *cone_dot//*att
                                                                    );
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                 
                                }
                                d3d_set_fog(0,c_white,0,0);
                                draw_set_blend_mode(bm_subtract);
                                for(var j = 0; j<global.tmc_lux_sprited_shadows_at; ++j)
                                {
                                    shadow = global.tmc_lux_sprited_shadows[j];
                                 
                                    draw_sprite_ext(
                                            shadow[SPRITED_SHADOWS.SPRITE],
                                            shadow[SPRITED_SHADOWS.INDEX],
                                            (shadow[SPRITED_SHADOWS.X]-__view_get( e__VW.XView, 0 )) * xs,
                                            (shadow[SPRITED_SHADOWS.Y]-__view_get( e__VW.YView, 0 )) * ys,
                                            shadow[SPRITED_SHADOWS.XSCALE] * xs,
                                            shadow[SPRITED_SHADOWS.YSCALE] * ys,
                                            shadow[SPRITED_SHADOWS.ROT],
                                            c_black,
                                            1
                                        )
                                }
                             
                                draw_set_blend_mode(bm_normal);
                             
                                for(var i=0; i< processed_spr_lights_at;++i)
                                {
                                    light = global.tmc_lux_sprited_lights[processed_spr_lights[i]];
                                    light[@SPRITED_LIGHT.SHADOW_PROCESSED] = 1;
                                }
                                for(var i=0; i< processed_lights_at;++i)
                                {
                                    light = global.tmc_lux_lights[processed_lights[i]];
                                    light[@LIGHT.SHADOW_PROCESSED] = 1;
                                }
                         
                            }
                            surface_reset_target();
                            if(surface_exists(as_clone))
                            {
                                surface_set_target(as_clone)
                                {
                                    //draw_set_blend_mode(bm_subtract);
                                    draw_surface_ext(surf_lights,0,0,1,1,0,c_black,global.tmc_lux_sprited_shadows_power);
                                    //draw_set_blend_mode(bm_normal);
                                    //draw_surface(as_clone,0,0);
                                }
                                surface_reset_target()
                            }
                        }
                        //global.tmc_lux_sprited_shadows_at = 0; //cleared next step
                    }
                }
            }
            //process the draw batch to the lights surface
            global.tmc_lux_lights_buffer = tmc_lux_safe_surface_create(global.tmc_lux_lights_buffer,as_w,as_h);   
            var surf_lights = global.tmc_lux_lights_buffer;
            if(surf_lights!=-1)
            {
                surface_set_target(surf_lights);
                {
                    draw_clear_alpha(c_black,0);
                    draw_set_blend_mode(bm_add);
                 
                    var light;
                    for(var i = 0; i< global.tmc_lux_sprited_lights_at; ++i)
                    {
                        light = global.tmc_lux_sprited_lights[i];
                        if(light[SPRITED_LIGHT.PROCESSED]==0)
                        {
                            light[@SPRITED_LIGHT.PROCESSED] = 1;
                            draw_sprite_ext(
                                light[SPRITED_LIGHT.SPRITE],
                                light[SPRITED_LIGHT.INDEX],
                                (light[SPRITED_LIGHT.X]-__view_get( e__VW.XView, 0 )) * xs,
                                (light[SPRITED_LIGHT.Y]-__view_get( e__VW.YView, 0 )) * ys,
                                light[SPRITED_LIGHT.XSCALE] * xs,
                                light[SPRITED_LIGHT.YSCALE] * ys,
                                light[SPRITED_LIGHT.ROT],
                                light[SPRITED_LIGHT.COLOUR],
                                light[SPRITED_LIGHT.ALPHA]
                            )
                       }
                    }
                 
                    draw_set_blend_mode(bm_normal);
                }
                surface_reset_target();
             
                //everything is still fine, final render the lights to the application surface
                if(surface_exists(surf_lights) and surface_exists(as_clone) and surface_exists(application_surface))
                {
                    var tex = surface_get_texture(surf_lights);
                 
                    //gms 2.1.5.246 bug fix
                    //surface_set_target(application_surface);
                    {
                     
                        shader_set(tmc_lux_sprited_light_shdr);
                        texture_set_stage(global.tmc_lux_sh_sprited_light_back_buffer, tex);
                        /////////
                        //gms 2.1.5.246 bug fix
                        //draw_surface(as_clone,0,0);
                        draw_surface_stretched(as_clone,__view_get(e__VW.XView,0),__view_get(e__VW.YView,0),__view_get(e__VW.WView,0),__view_get(e__VW.HView,0));
                        /////////
                        shader_reset();
                    }
                    //gms 2.1.5.246 bug fix
                    //surface_reset_target();
                    success = true;
                }
             
            }
            //if(surface_exists(surf_lights)) surface_free(surf_lights);
         
            //if(surface_exists(as_clone)) surface_free(as_clone);
        }
        else if(surface_exists(application_surface))
        {
            //use the back buffer is disabled, render bm_add to the app surface
            //gms 2.1.5.246 bug fix
            //surface_set_target(application_surface);
            {
                //loop through the draw batch and simply draw with bm_add
                draw_set_blend_mode(bm_add);
                var light;
                for(var i = 0; i< global.tmc_lux_sprited_lights_at; ++i)
                {
                    light = global.tmc_lux_sprited_lights[i];
                    if(light[SPRITED_LIGHT.PROCESSED]==0)
                    {
                        light[@SPRITED_LIGHT.PROCESSED] = 1;
                        draw_sprite_ext(
                            light[SPRITED_LIGHT.SPRITE],
                            light[SPRITED_LIGHT.INDEX],
                            //////
                            //gms 2.1.5.246 bug fix
                            //(light[SPRITED_LIGHT.X]-__view_get( e__VW.XView, 0 )) * xs,
                            //(light[SPRITED_LIGHT.Y]-__view_get( e__VW.YView, 0 )) * ys,
                            //light[SPRITED_LIGHT.XSCALE] * xs,
                            //light[SPRITED_LIGHT.YSCALE] * ys,
                            (light[SPRITED_LIGHT.X]),
                            (light[SPRITED_LIGHT.Y]),
                            light[SPRITED_LIGHT.XSCALE],
                            light[SPRITED_LIGHT.YSCALE],
                            //////
                            light[SPRITED_LIGHT.ROT],
                            light[SPRITED_LIGHT.COLOUR],
                            light[SPRITED_LIGHT.ALPHA]
                        )
                    }
                }
                draw_set_blend_mode(bm_normal);
            }
            //gms 2.1.5.246 bug fix
            //surface_reset_target();
            success = true;
        }         
    }
    if(success == false)
    {
        //to the screen if we have to, everything failed or compatibility mode is on so forced to use the screen
        draw_set_blend_mode(bm_add);
        var light;
        for(var i = 0; i< global.tmc_lux_sprited_lights_at; ++i)
        {
            //loop through the draw batch and simply draw with bm_add on the screen directly
            light = global.tmc_lux_sprited_lights[i];
            if(light[SPRITED_LIGHT.PROCESSED]==0)
            {
                light[@SPRITED_LIGHT.PROCESSED] = 1;
                draw_sprite_ext(
                    light[SPRITED_LIGHT.SPRITE],
                    light[SPRITED_LIGHT.INDEX],
                    (light[SPRITED_LIGHT.X]),
                    (light[SPRITED_LIGHT.Y]),
                    light[SPRITED_LIGHT.XSCALE],
                    light[SPRITED_LIGHT.YSCALE],
                    light[SPRITED_LIGHT.ROT],
                    light[SPRITED_LIGHT.COLOUR],
                    light[SPRITED_LIGHT.ALPHA]
                )
            }
        }
        draw_set_blend_mode(bm_normal);
    }
    //global.tmc_lux_sprited_lights_at = 0;
}
 
Last edited:

StakFallT

Member
hmmm... I'm a little curious. I recently (within a day or two of this post -- 12/23/2018 7:39PM ET) downloaded / updated through the My Library window in GMS 2 and the change notes in that window stats there was a PIP fix, yet when I compare a freshly downloaded version (within a few days of this post -- 12/23/2018 7:44PM ET) with the fix, I get differences in the file contents... I did read the bit about the inability to fix assets (not sure why that would be, I'm kind've curious as to why that would be the case) so I was about to post a url (in text form, since I believe I'm below the 5 post threshold) to a diff file containing the fix. However, I saw the bit in the changelog about the PIP fix. So now I'm kinda curious as to how the freshly downloaded version I got has content-differences than the fix.

On a side note (but maybe related): I'm having issues with TMC LUX giving a shader error (specifically mentioning tmc_lux_norm_spec_shdr -- though in the debug / compile tab all 4 shaders have an "Invalid shader (is it marked as incompatible type for this target?)" error and I know I've tested TMC LUX before from a freshly imported-into-new-project-of-its-own import. It may be because my video ram and regular ram are fragmented since I haven't rebooted in a few weeks (since having played some graphically intense games -- FFXV for one) but that seems a little odd for that to be the cause for the error given it seems to be a shader compilation error not a shader execution kind of thing. This -seems- like the right place to seek support for TMC LUX specifically since clicking the GMS2 compatible link in the marketplace took me to this thread; however that doesn't seem right either as if everyone posted their problem here it'd become a disorganized mess lol. I've checked TMC's site and the forums there seem almost not even barren it's so barren. I can provide more information (i.e. the Code Error and debugger logs) but I'll defer to icuurd12b42 or other TMC staff as to how best to proceed.
 

icuurd12b42

TMC Founder
GMC Elder
I can no longer upload/update assets on the store bc I lost my distributor credential file used the sign the asset.

as for shader compile error, I seen this a long while back. check the shader type. should be glsl....
 

StakFallT

Member
I sort've tried that before. I set tmc_lux_norm_shdr to GLSL (from GLSL ES) and no luck. This time around, I tried setting all 5 shaders to GLSL (from GLSL ES), now I get the error starting at line 345: shader_set(tmc_lux_sprited_light_shdr); in tmc_lux_do_sprited

It seems swapping around the setting from GLSL to GLSL ES and back gives the same result only it errors at a different point. I then tried variations (some GLSL ES and some not, and no dice). I also deleted the test project that was created when I told it to import all assets into its own project, and reimported into a new project again and still no joy.


And that sucks about the cred file. Sorry to hear that!
 

StakFallT

Member
How should I send it to you? Do you want a file-sharing link in this thread (not sure if a project file using a marketplace asset would be sufficient for someone to pull the asset out and use it without paying -- hence my reluctance to just posting a link without asking). I tried to see if I could DM it to you but I don't see where to do that, and the contact publisher link allows me to send you an email but no attachments.
 

StakFallT

Member
For anyone that's been following, are curious and that may have the issue I'm having, icuurd12b42 is still working with me to figure out what the shader issue I'm having is being caused by. It -definitely- looks like it's something on my side, but given various aspects of the issue (was working before -- maybe a month or two ago, other shader code work, HLSL versions of the code don't cause GMS2 to crash, etc.), it's hard to figure out what the actual culprit is. Hopefully, this will all be a little anecdote of things in the toolbox to try if someone else runs into a similar issue :)
 

Morendral

Member
Is there any planned compatibility update planned for this with GMS2? right now I get about 15FPS in the platformer demo. I didn't change any of the settings on the side to get that, disabling everything also doesn't help.
 

icuurd12b42

TMC Founder
GMC Elder
Is there any planned compatibility update planned for this with GMS2? right now I get about 15FPS in the platformer demo. I didn't change any of the settings on the side to get that, disabling everything also doesn't help.
the asset only requires the code top in post 51, top of this page to be gms2 compliant.

as for slowdown I'm not sure. this depends on your video card, the display you run it on. On the right of the demo are a bunch of sliders to tweak... reduce the app surface slider to 1080.

if you are running at 4k or a resolution too high for the video card, it may borderline the card efficiency...

Also check your nvidia control panel settings

upload_2019-2-19_14-48-59.png
 

icuurd12b42

TMC Founder
GMC Elder
Problem: Array too large for shader

Reported May 1st 2019 by Aaron Thorne... thanks for helping out!

On GMS MAC

Error:
shader_set_uniform_f_array: Array too large for shader

at gml_Script_tmc_lux_set_norm_shdr (line 130) - shader_set_uniform_f_array(global.tmc_lux_sh_norm_source_texture_pos, m_SrcTexPos);

############################################################################################
This is because I am calling shader_set_uniform_f_array using an array returned by background_get_uvs.
I assume they made some changes that makes this function return an array that is not compatible...

FIX:
Add a function
Code:
///ConvertArr(arr);
var arr = argument0;
return [arr[0],arr[1],arr[2],arr[3]];
This will convert the background_get_uvs() array to an array accepted by shader_set_uniform_f_array.

and replace all occurences of
variable = background/sprite_get_uvs(...);
variable = ConvertArr(background/sprite_get_uvs(...));


A less optimised fix is to call ConvertArr(m_Variable); for the following functions and lines...


tmc_lux_set_norm_shdr

==================

Line 130 shader_set_uniform_f_array(global.tmc_lux_sh_norm_source_texture_pos, ConvertArr(m_SrcTexPos));

Line 131 shader_set_uniform_f_array(global.tmc_lux_sh_norm_norm_texture_pos, ConvertArr(m_NormTexPos));


tmc_lux_set_norm_spec_shdr

=======================

Line 133 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_source_texture_pos, ConvertArr(m_SrcTexPos));

Line 134 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_norm_texture_pos, ConvertArr(m_NormTexPos));

Line 137shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_spec_texture_pos, ConvertArr(m_SpecTexPos));


tmc_lux_set_norm_occ_shdr

======================

Line 132 shader_set_uniform_f_array(global.tmc_lux_sh_norm_occ_source_texture_pos, ConvertArr(m_SrcTexPos));

Line 133 shader_set_uniform_f_array(global.tmc_lux_sh_norm_occ_norm_texture_pos, ConvertArr(m_NormTexPos));

Line 137 shader_set_uniform_f_array(global.tmc_lux_sh_norm_occ_amb_texture_pos, ConvertArr(m_OccTexPos));


tmc_lux_set_norm_spec_occ_shdr

===========================

Line 132 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_occ_source_texture_pos, ConvertArr(m_SrcTexPos));

Line 133 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_occ_norm_texture_pos, ConvertArr(m_NormTexPos));

Line 136 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_occ_spec_texture_pos, ConvertArr(m_SpecTexPos));

Line 139 shader_set_uniform_f_array(global.tmc_lux_sh_norm_spec_occ_amb_texture_pos, ConvertArr(m_OccTexPos));


Sorry for the inconvenience[/quote]
 

icuurd12b42

TMC Founder
GMC Elder
tmc_lux_norm_spec_occ_shdr and tmc_lux_norm_spec_shdr shaders need the following change for the totalLighting calculation

At one point, while refactoring the shaders, I replaced the line with that of the bare bone shader...

on or about line 78 of fragment shader
change
Code:
    //the calculation which brings it all together
    totalLighting += Diffuse * Attenuation * d * cone_dot;
to
Code:
    //the calculation which brings it all together
    totalLighting += Diffuse * Attenuation * d * cone_dot * SpecularMap.rgb * SpecularMap.a;
Note that the _spec shader takes a specular MASK as texture, defining how much light is reflected depending of both the angle of incidence of the light ray and the mask rgba value, white meaning all the light is reflected and black being none on the texture image. basically it is the power setting for the lighting effect for that pixel location.

the _occ variant of the shader, the occlusion mask works the same way but is applied globally and therefore not relative to the light rays angle of incidence.

Note the specular mask for the statue will cause it to have some odd artefacts... this is because, for some reason, some of the pixels in that mask are not pure grayscale, you can fix that converting the image to grayscale yourself....
 
Last edited:
tmc_lux_norm_spec_occ_shdr and tmc_lux_norm_spec_shdr shaders need the following change for the totalLighting calculation

At one point, while refactoring the shaders, I replaced the line with that of the bare bone shader...

on or about line 78 of fragment shader
change
Code:
    //the calculation which brings it all together
    totalLighting += Diffuse * Attenuation * d * cone_dot;
to
Code:
    //the calculation which brings it all together
    totalLighting += Diffuse * Attenuation * d * cone_dot * SpecularMap.rgb * SpecularMap.a;
Note that the _spec shader takes a specular MASK as texture, defining how much light is reflected depending of both the angle of incidence of the light ray and the mask rgba value, white meaning all the light is reflected and black being none on the texture image. basically it is the power setting for the lighting effect for that pixel location.

the _occ variant of the shader, the occlusion mask works the same way but is applied globally and therefore not relative to the light rays angle of incidence.

Note the specular mask for the statue will cause it to have some odd artefacts... this is because, for some reason, some of the pixels in that mask are not pure grayscale, you can fix that converting the image to grayscale yourself....

When I implemented this fix above. My "Compile Errors" spit this out...

Object: tmc_lux_demo_backwall_obj Event: Draw at line 30 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_cube_obj Event: Draw at line 12 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_sphere_obj Event: Draw at line 12 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_light_torch_obj Event: Draw at line 10 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_door_TRIGGER_obj Event: Draw at line 10 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_platform_TRIGGER_obj Event: Draw at line 10 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_lever_TRIGGER_obj Event: Draw at line 11 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_gargoyle_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_column_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_column_top_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_column_mid_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_demo_lux_floor_1_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_column_base_obj Event: Draw at line 13 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_demo_ship_obj Event: Draw at line 9 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided
Object: tmc_lux_preview_and_fix_tool_obj Event: Draw GUI at line 1739 : function "tmc_lux_set_norm_shdr" expects 1 arguments, 0 provided

(im on Mac)

Additionally, where you say "Add Function"...

GML:
///ConvertArr(arr);
var arr = argument0;
return [arr[0],arr[1],arr[2],arr[3]];
You dont say where or to what object, shader, script, etc... and what line. Maybe thats what is messing it up?
 
Last edited:
I followed post #64, and #65 to the letter. Only issue I found is where and what line to put the code on post #65. All the dev says is add function. Doesnt say where to. If I put that code in the shader that is suggested it give me that compile error.
 

kburkhart84

Firehammer Games
It seems that you need to add a script, and the below stuff is what needs to be in the script.
Code:
var arr = argument0;
return [arr[0],arr[1],arr[2],arr[3]];
Maybe that is is what you are missing.

I know when I added that shader code back when I used this, I didn't get any compile errors, so I know the advice is correct.
 

icuurd12b42

TMC Founder
GMC Elder
yes, add a new script/function in the script branch in the resource tree named ConvertArr

and paste the code:

///ConvertArr(arr);
var arr = argument0;
return [arr[0],arr[1],arr[2],arr[3]];
 
Im not sure what it was doing before, but that problem may be on my Mac only. Im on my windows and it seems fine. Anyways. a new problem has presented itself. The lighting system seems to be affecting my camera or parallax. Unsure which. Do you know of anything that maybe conflicting. Causing the camera to move faster than the player and split the screen. All I am using is this...

GML:
tmc_lux_add_sprited_light(tmc_lux_demo_light_spr, 0, x, y, -100, 6, 6, 0, c_white, .2, 100, false);
Screenshot_7.jpg
 

icuurd12b42

TMC Founder
GMC Elder
Im not sure what it was doing before, but that problem may be on my Mac only. Im on my windows and it seems fine. Anyways. a new problem has presented itself. The lighting system seems to be affecting my camera or parallax. Unsure which. Do you know of anything that maybe conflicting. Causing the camera to move faster than the player and split the screen. All I am using is this...

GML:
tmc_lux_add_sprited_light(tmc_lux_demo_light_spr, 0, x, y, -100, 6, 6, 0, c_white, .2, 100, false);
View attachment 32710
Apply the code patches listed in this thread. that should fix this.
 
Top