Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Stefan

Pages: 1 2 [3] 4 5 ... 157
41
English forum / 200 demos converted and counting...
« on: June 10, 2015, 07:54:10 PM »
Instead of making further single forum topics, i'll add new demos here in future.

Download 200 converted demos here
Incl. some WIP demos that compile successfully, but fail to render properly.
Sort by date to catch the recently converted ones and don't forget to copy the textures.

All texture cubes are linked to the only one that comes with MadShaders.
No music, no keyboard support yet.

Code: [Select]
38911_BASIC_Bytes_free_gl2.xml
4d_soap_bubble_gl2.xml
Abandoned_base_gl2.xml
Alien_beacon_gl2.xml
Alien_tech_gl2.xml
AncientMars_gl2.xml
Ancient_ temple_gl2.xml
Another_Kaliset_Mod_gl2.xml
Anti_menger_sphere_sponge.xml
Audrey_gl2.xml
A_sphere_on_the_ floor_gl2.xml
Balls_and_shadows_gl2.xml
Ball_puzzle_gl2.xml
BirthMachine_gl2.xml
Blocks_gl2.xml
Brighton_beach_gl2.xml
Bubble_Buckey_Balls_gl2.xml
Canyon_gl2.xml
Castle_Argh_gl2.xml
Catacombs_gl2.xml
CeramicGlassMosaic_gl2.xml
Chains_and_gears_gl2.xml
Chains_gl2.xml
Chinese_puzzle_balls_gl2.xml
Cloud_Ten_gl2.xml
Clover_tree_gl2.xml
Congrats_Luxo_Jr_gl2.xml
Crazy_Springs_gl2.xml
CrossStructure_gl2.xml
crowded_cheesy_place_gl2.xml
crowded_dotty_place_gl2.xml
crowded_place_gl2.xml
crowded_psychedelic_place_gl2.xml
cune_gl2.xml
Curvature_Parametric_3D_gl2.xml
Curvature_Parametric_gl2.xml
Data_transfer_gl2.xml
dawn_of_the_tentacle_gl2.xml
Deadly_dreams_gl2.xml
demo_25707_0_gl2.xml
demo_26085_0_gl2.xml
demo_26098_7_gl2.xml
demo_26106_1gl2.xml
demo_26192_0_gl2.xml
demo_26245_4_gl2.xml
demo_26282_0_gl2.xml
demo_26314_0_gl2.xml
demo_26317_0_gl2.xml
descent_gl2.xml
Desert_morning_gl2.xml
Distance_field_fur_test_gl2.xml
Distance_Field_gl2.xml
doom_2_gl2.xml
Dubstep_my_ass_gl2.xml
Elevated_Coast_gl2.xml
Emerging_gl2.xml
EmuMandel_gl2.xml
Eschers_the_ prentententoonstelling_gl2.xml
EvilSeed_gl2.xml
Eye_trips_gl2.xml
Fire_and_water_gl2.xml
Flappy_Bird_gl2.xml
Fluid_with_obstacles_gl2.xml
Foggy_mountains_2_gl2.xml
Foreign_planet_gl2.xml
Frozen_Wasteland_gl2.xml
Galvanize_Tunnel_gl2.xml
Glassy_Blobs_gl2.xml
GLSL_IO_Cube_gl2.xml
GLSL_IO_Page_Curl_gl2.xml
GLSL_IO_Potleaf_gl2.xml
GLSL_IO_Swap_gl2.xml
GLSL_IO_Undulating_burn_gl2.xml
Golden_Mandelbox_gl2.xml
Go_Portugal_gl2.xml
Guilin_gl2.xml
Heartwing_Angel_gl2.xml
Heart_on_fire_gl2.xml
Holy_Cubes_gl2.xml
Hyperlepsy_gl2.xml
Hypertexture_trabeculum_gl2.xml
Hyper_dodecahedron_gl2.xml
Ice_lake_gl2.xml
Illustrated_equations_gl2.xml
Infinite_city_gl2.xml
Infinite_fractal_road_gl2.xml
Inflatable_Analyser_gl2.xml
Italian_Job_gl2.xml
Iterations_coral_gl2.xml
Jetstream_gl2.xml
Junkyard_gl2.xml
Long_slender_flexible_things_gl2.xml
Lost_in_ the_field_gl2.xml
machineroom_gl2.xml
Magnetismic_gl2.xml
manta_ray_gl2.xml
Mars_jetpack_gl2.xml
Meet_Billy_gl2.xml
Mengers_dream_gl2.xml
Mesas_gl2.xml
metamonolith_gl2.xml
Metro_tunnel_gl2.xml
Minefield_gl2.xml
Mist_Ring_gl2.xml
mod_rotwang_gl2.xml
Mona_Lisa_in_triangles_gl2.xml
Mountains_gl2.xml
Music_pirates_gl2.xml
My_First_raymarch_gl2.xml
nano_tubes_gl2.xml
New_Zealand_gl2.xml
NightRide_gl2.xml
One_To_Rule_Them_All_gl2.xml
Orchard_Night_gl2.xml
Page_Curl_Effect_Experiment_gl2.xml
Palmetto_Stalk_gl2.xml
Path_Traced_Ice_Cube_gl2.xml
pbr_test_gl2.xml
Pearls_of_magma_gl2.xml
piggy_gl2.xml
Pixie_sticks_gl2.xml
Playing_with_Refleks_gl2.xml
Prickly_Sphere_gl2.xml
Protophore_gl2.xml
Pseudo_Knightyan_gl2.xml
Psycho_dots_gl2.xml
pyroclastic_explosion_gl2.xml
Rainbow_Dash_gl2.xml
Rainbow_Spaghetti_gl2.xml
RayCast_rehabilitation_gl2.xml
raymarching_is_so_awesome_gl2.xml
Raymarching_primitives_gl2.xml
Raymarching_Worley_gl2.xml
Reflective_spheres_gl2.xml
Rendezvous_gl2.xml
Rolling_forever_gl2.xml
Rose_gl2.xml
Rotating_Structure_gl2.xml
Ruins_gl2.xml
sakura_revisited_gl2.xml
Satellites_eye_gl2.xml
Schroedingers_cat.gl2.xml
Screws_gl2.xml
Seabirds_at_Sunset_gl2.xml
Shadering_Chameleon_gl2.xml
shader_material_demo_gl2.xml
Shady_building_gl2.xml
Shakespeare_Quest_gl2.xml
Sharbat_Gula_gl2.xml
shmup_gl2.xml
Signal_Field_gl2.xml
Slisesix_gl2.xml
SoC_with_DEL_gl2.xml
SoC_with_Light_gl2.xml
space_egg_gl2.xml
Space_jewels_gl2.xml
Speed_Experiment_1_gl2.xml
spiderwaves_gl2.xml
Spout_gl2.xml
sRGB_corrected_marble_gl2.xml
Star_Nest_retro_gl2.xml
Star_nursery_gl2.xml
Star_Spangled_Banner_gl2.xml
Stuctures_gl2.xml
SubabaRecycle_gl2.xml
Synthetic_aperture_gl2.xml
syoyos_AS3_Ambient_Occlusion_gl2.xml
Terminator_gl2.xml
the_cave.gl2.xml
the_institute_gl2.xml
The_Mine_gl2.xml
Toy_train_gl2.xml
train_ride_gl2.xml
Trampoline_gl2.xml
Trees_gl2.xml
Trig _1_gl2.xml
Twistors_gl2.xml
Unlimited_confectionary_gl2.xml
Unreal_Intro_gl2.xml
useless_box_gl2.xml
Variations_of_Topologica_gl2.xml
Venice_gl2.xml
Voronoi_metrics_gl2.xml
Warp_and_Weave_gl2.xml
Weird_fractal_5_gl2.xml
Weird_fractal_6_gl2.xml
Who_goes_there_gl2.xml
Windyplains_gl2.xml
WIP_Bat_Signal_gl2.xml
WIP_FakeVolumetricClouds_gl2.xml
WIP_Floating_mountains_gl2.xml
WIP_Hall_of_Kings_gl2.xml
WIP_jellyfish_The_Jam_gl2.xml
WIP_JS4K_planets_gl2.xml
WIP_parallaxmapping_gl2.xml
WIP_particles_gl2.xml
WIP_Raymarch_210_chars_gl2.xml
WIP_Volcanic_gl2.xml
Wire_Eggs_gl2.xml
Woods_gl2.xml

42
Check out the incredible effects NVIDIA GameWorks brings to Batman Arkham Knight!  Smoke and fog react to the movement in the fight scenes, including when a box is thrown or part of the floor blows up into piece.  Paper debris gets kicked around as Batman takes on all the baddies. Enhanced rain allows the rain to naturally  bead off when coming into contact with Batman and his cape.

It’s Batman: Arkham Knight, The Way It’s Meant to Be Played.

GameWorks Technology shown in the video:
• Interactive Fog and Smoke:
• Interactive Paper Debris
• PhysX Destruction
• Enhanced Rain

43
Quote
The Latest Tegra K1 Device Is Literally An Oven (Related: The Oven Itself Seems Pretty Awesome)

Does the Tegra K1 in your Nexus 9 run a little toasty? Well, it's got nothing on NVIDIA's latest mobile chip design win, which is literally an oven. I'm sorry, NVIDIA, but the jokes basically write themselves here.
...
As for the selfie aspect, the June has a built-in full-HD camera with two bright white LEDs providing lighting for your foodographs and live-stream cooking action. It is, of course, powered by an NVIDIA Tegra K1 (quad-core, not Denver) processor, which seems like tremendous overkill, but then again, I'm not a smart oven engineer.

Not the usual "GPU baking"...

44
3D-Tech News Around The Web / NVIDIA Mech Ti DirectX 12 tech demo
« on: June 10, 2015, 05:55:01 PM »
Check out 4gamer.net and good luck with babelfish

45
3D-Tech News Around The Web / ASTC Compression Gets a CUDA Boost
« on: June 10, 2015, 05:41:19 PM »
NVIDIA is using CUDA and the power of GeForce to accelerate Adaptive Scalable Texture Compression (ASTC) along multiple axes!

Adaptive Scalable Texture Compression (ASTC) is a new standard for texture compression that provides development teams and art directors with the ability to balance texture quality and texture size. Texture compression is not new, but ASTC provides a far greater number of options than older standards. It has a wide spectrum of bit-rate selections, from 8bits/texel (4x4 tiles) to 0.89bits/texel (12x12 tiles). For more information on ASTC generally and how to best use it for different texture assets, check out NVIDIA's ASTC usage guide.
...

We still have a lot of work ahead of us to achieve two axis parallelism but we are progressing nicely. The current implementation with data-parallelism is a huge leap from the CPU based encoder and should assist developers in their testing and usage of ASTC. To that end, we have posted an alpha version of our encoder in the Download Center.

46
3D-Tech News Around The Web / (WebGL) America's Cup 2015
« on: June 10, 2015, 05:32:32 PM »
 America's Cup 2015   
         
  Render for trophy of america's cup 2015 in Chile

.

 

47
English forum / Re: The Institute converted
« on: June 09, 2015, 04:20:09 PM »
It appears that the variable name "layout" is illegal exclusively on AMD GPUs

Updated code with fix below

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/The Institute"
          width="800" height="400"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/Xll3Wn

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click

// illegal variable name "layout" replaced with "yikes"

//

//The Institute by eiffie

#define time iGlobalTime
#define size iResolution
#define AUTO_OVERSTEP

float px;
vec4 prp=vec4(0.0);
vec3 L;

float rnd(vec2 c){return fract(sin(dot(vec2(1.317,19.753),c))*413.7972);}
float rndStart(vec2 gl_FragCoord){
    return 0.5+0.5*rnd(gl_FragCoord.xy);
}
float smin(float a,float b,float k){float h=clamp(0.5+0.5*(b-a)/k,0.0,1.0);return b+h*(a-b-k+k*h);}
float noyz(vec2 p){//value noise - original author??
    vec2 c=floor(p),f=fract(p);f=f*f*(3.0-2.0*f);
    float k=257.0,u=c.x+c.y*k;
    vec4 v=vec4(u,u+1.0,u+k,u+k+1.0);v=fract(fract(v*1.23456789)*9.18273645*v);
    return mix(mix(v.x,v.y,f.x),mix(v.z,v.w,f.x),f.y);
}
float fbm(vec2 p){
    vec2 s=sin(p*0.3+2.4*sin(p.yx*0.3));
    float h=1.0+(s.x+s.y)*0.5,a=0.5;
    p+=s.yx*0.66;
    for(int i=0;i<3;i++){
        h+=noyz(p)*a;
        a*=0.3;p=vec2(p.x+p.y*0.7,p.x-p.y+0.13)*2.0;
    }   
    return h;
}
vec3 Sky(vec3 rd){
    vec3 col=mix(vec3(0.4,0.2,0.0),vec3(0.5,0.7,0.7),clamp(0.25-0.5*rd.z,0.0,1.0));
    col+=vec3(1.2,1.1,0.9)*pow(max(0.0,dot(rd,L)),100.0);
    float h=noyz(rd.xy*5.0)*0.5+noyz(vec2(2.0*abs(atan(rd.y,rd.x)),rd.z*20.0));
    col=mix(col,vec3(0.9,0.8,0.6),clamp(h*0.5-0.4,0.0,1.0));
    return mix(vec3(0.1,0.2,0.1),col,clamp((-rd.z+0.05)*20.0,0.0,1.0));
}

float capsule(vec3 p){return length(vec3(p.x,p.y-clamp(p.y,-3.0,10.0),p.z));}
float rcap(vec3 p){return length(vec2(p.x-clamp(p.x,-7.0,7.0),max(abs(p.y),abs(p.z))));}

float DE(in vec3 p){
    float yikes=(length(p.xy+vec2(8.0,-6.0))-45.0);
    yikes=smin(yikes,abs(p.y-28.0+sin(p.x*0.01)*40.0)-5.0,20.0)*0.02;
    float h=fbm(p.xy*0.1)*10.0*pow(clamp(yikes,0.0,1.0),0.7),d=-p.z+7.0-h,dG=d;
    for (int n = 0; n < 4; n++) {
        p=clamp(p, -3.1, 3.1) *2.0-p;
        p+=vec3(1.9,3.2,8.6);
        p=p.yzx;
        d=min(d,min(capsule(p)-3.0,rcap(p)-2.0));
    }
   
    if(d<0.25 && d<dG){
        float flr=floor(p.y);
        float rs=1.0+sin(flr)*0.5;
        p=vec3(rs,1.0,rs)*0.5-abs(mod(p,vec3(rs,1.0,rs))-vec3(rs,1.0,rs)*0.5);
        float d2=d+0.05;
        if(flr<-rs || rs<0.6)
            d=min(d2,max(d,min(p.y,min(p.x,p.z))-0.0125));
        else if(flr<rs*2.0 || rs<0.75)
            d=max(d,min(p.y,min(p.x,p.z))-0.025);
        else {
            d=max(d,min(p.y,max(p.x,p.z))-0.05);
            if(prp.x<0.0)prp=vec4((rs>1.3)?length(p):10.0,0.0,0.0,(max(p.x,p.z)<0.06)?4.0:3.0);
        }
        if(prp.x<0.0){
            if(d==d2)prp=vec4(10.0,0.0,0.0,2.0);
            else prp=vec4(10.0,0.0,0.0,3.0);
        }
    }else if(prp.x<0.0)prp=vec4(10.0,h,yikes,1.0);
    return d;
}

float shadao(vec3 ro, vec3 rd, float px,vec2 gl_FragCoord){//pretty much IQ's SoftShadow
    float res=1.0,d,t=10.0*px*rndStart(gl_FragCoord);
    for(int i=0;i<12;i++){
        d=max(0.0,DE(ro+rd*t)*1.5);
        t+=d;
        res=min(res,d/t);
    }
    return res;
}

vec3 Color(vec3 ro, vec3 rd, float t, vec3 col, bool bFill, vec2 gl_FragCoord){
    ro+=rd*t;
    prp.x=-1.0;
    float d=DE(ro),spec=0.0,n=noyz(ro.xy*3.0);
    vec2 e=vec2(px*t,0.0);
    vec3 dn=vec3(DE(ro-e.xyy),DE(ro-e.yxy),DE(ro-e.yyx));
    vec3 dp=vec3(DE(ro+e.xyy),DE(ro+e.yxy),DE(ro+e.yyx));
    vec3 N=(dp-dn)/(length(dp-vec3(d))+length(vec3(d)-dn));
    vec3 R=reflect(rd,N);
    vec3 lc=vec3(1.0,0.9,0.,sc,rc=Sky(R);
    if(prp.w<1.5){
        sc=mix(vec3(0.8,0.8,0.3),vec3(0.2),clamp(abs(abs(ro.y-28.0+sin(ro.x*0.01)*40.0)-0.25)*4.0,0.0,1.0));
        sc=mix(sc,mix(vec3(0.2,0.3,0.1),vec3(0.6,0.5,0.4),clamp(prp.y*0.05-0.25,0.0,1.0)),clamp(prp.z*100.0,0.0,1.0));
        spec=0.2;//clamp(2.5-prp.y,0.0,1.0);
        n*=0.1;
    }else if(prp.w<2.5){sc=vec3(0.4,0.5,0.6);spec=1.0;n*=0.3;
    }else if(prp.w<3.5){sc=vec3(0.6,0.63,0.62);spec=0.5;n*=0.4;}
    else {sc=vec3(0.5,0.5,0.0);spec=0.5;}
    sc*=(1.0-n);
    float sh=clamp(shadao(ro,L,px*t,gl_FragCoord)+0.2,0.0,1.0);
    sh=sh*(0.5+0.5*dot(N,L))+exp(-prp.x*5.0);
    vec3 scol=sh*lc*(sc+0.5*spec*rc*pow(max(0.0,dot(R,L)),2.0));
    if(bFill)d*=0.05;
    col=mix(scol,col,clamp(d/(px*t),0.0,1.0));
    return col;
}
mat3 lookat(vec3 fw){
    fw=normalize(fw);vec3 rt=normalize(cross(fw,vec3(0.0,0.0,-1.0)));return mat3(rt,cross(rt,fw),fw);
}
vec3 cpnt(float t){
    if(t<0.5)return vec3(-45.0,30.0,-38.0);
    if(t<1.5)return vec3(-20.0,23.0,-25.0);
    if(t<2.5)return vec3(-13.0,23.0,-2.5);
    if(t<3.5)return vec3(10.0,26.0,-2.5);
    return vec3(12.0,21.0,6.6);
}
vec3 path(float t){
    float t2=t-t*t*0.05;
    if(t<10.0)return vec3(-1000.0+t2*200.0,30.0-sin((-1000.0+t2*200.0)*0.01)*40.0,4.25);
    t2=time-10.0;
    float r=60.0-t2;
    if(t<25.0)return vec3(-8.0+r*cos(t2*0.3),6.0+r*sin(t2*0.25),-t2*4.0);
    if(t<45.0){
        t2=(t-25.0)/5.0;r=floor(t2);t2=fract(t2);
        return mix(cpnt(r),cpnt(r+1.0)-0.25*cpnt(r+2.0)*(1.0-t2),t2);
    }
    if(t<60.0){
        t2=t-45.0;
        t2=t2-t2*t2*0.025;
        r=500.0-t2*50.0;
        vec3 p=vec3(cos(t2*0.2)*r,sin(t2*0.2)*r,-30.0);
        float d1=DE(p),d2=DE(p+vec3(0.0,-10.0,0.0));
        p.z+=(d1+d2)*0.4;
        return p;
    }
    return vec3(-8.0+cos(t*0.3)*60.0,6.0+60.0*sin(t*0.2),-29.5+sin(t*0.1)*10.0);
}
void main()
{
    px=0.5/size.y;
    L=normalize(vec3(0.5,0.3,-0.6));
    float tim=time;
    vec3 ro=path(tim);
    vec3 ta=path(tim+0.5);
    if(tim>10.0 && tim<25.0)ta=vec3(0.0);
    if(tim>60.0)ta=vec3(0.0,0.0,-20.0);
    vec3 rd=lookat(ta-ro)*normalize(vec3((2.0*gl_FragCoord.xy-size.xy)/size.y,3.0));
    //ro=eye*10.0;rd=normalize(dir);
    float t=DE(ro)*rndStart(gl_FragCoord),d=0.0,od=1.0,step=0.0,os=0.0,pd=10.0;
    if(t<0.0){
        gl_FragColor=vec4(0.0,0.0,0.0,1.0);
        return;
    }
    vec4 edge=vec4(-1.0);
    bool bGrab=false;
    for(int i=0;i<78;i++){
        t+=step;
        d=DE(ro+rd*t);
#ifdef AUTO_OVERSTEP
        if(d>=os){        //we have NOT stepped over anything
            os=0.36*d*d/pd;//overstep based on ratio of this step to last
            step=d+os;    //add in the overstep
            pd=d;        //save this step length for next calc
        }else{step=-os;d=0.0001;pd=100000.0;os=0.0;}//remove overstep
#else
        step=d;
#endif

        if(d>od){
            if(bGrab && od<px*t && edge.x<0.0){
                edge=vec4(edge.yzw,t-od);
                bGrab=false;
            }
        }else bGrab=true;
        od=d;
        if(t>1000.0 || d<0.00001)break;
    }
    bool bFill=false;
    d*=0.05;
    if(d<px*t){
        if(edge.x>0.0)edge=edge.wxyz;
        edge=vec4(edge.yzw,t);
        bFill=true;
    }
    vec3 col=Sky(rd);
    for(int i=0;i<4;i++){
        if(edge.w>0.0)col=Color(ro,rd,edge.w,col,bFill,gl_FragCoord);
        edge=edge.wxyz;
        bFill=false;
    }
    float dimmer=clamp(min(abs(time-10.0),min(abs(time-25.0),min(abs(time-45.0),abs(time-60.0)))),0.0,1.0);
    gl_FragColor = vec4(1.5*col*dimmer*dimmer,1.0);
}

//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

-- tex0 = moon3d.image.load2d("./data/tex16.png")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/The institute", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>

48
English forum / Flappy Bird converted
« on: June 08, 2015, 11:04:47 PM »
Flappy Bird converted to GLSL Hacker format

iChannelTime[0] needs to be replaced with iGlobalTime

Copy the code and save as Flappy_Bird_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Flappy Bird"
          width="800" height="400"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/ls2GRt

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click

//iChannelTime[0] replaced with iGlobalTime

// Flappy Bird (tribute), fragment shader by movAX13h, Feb.2014

float rand(float n)
{
    return fract(sin(n * 12.9898) * 43758.5453)-0.5;
}

void pipe(inout vec3 col, vec2 p, float h)
{
    vec2 ap = abs(p);
    if (ap.y > h)
    {
        float dy = ap.y - h;
        if (dy < 60.0) ap.x *= 0.93;
        col = mix(col, vec3(0.322, 0.224, 0.290), step(ap.x, 65.0)); // outline
        if (dy > 60.0 || mod(dy, 55.0) > 5.0)
        {
            float gradient = 0.0;
            if (abs(dy - 57.5) > 7.5) gradient = max(0.0, 0.5*cos(floor((p.x+25.0)/5.0)*5.0*(0.026 - 0.006*step(dy, 10.0))));
            col = mix(col, vec3(0.322, 0.506, 0.129) + gradient, step(ap.x, 60.0)); // pipe
        }
    }
}

// constant-array-index workaround ---
float slice(int id)
{
    // flappy bird character (no worries, I have a tool)
    if (id == 0) return 2359296.0;
    if (id == 1) return 585.0;
    if (id == 2) return 4489216.0;
    if (id == 3) return 46674.0;
    if (id == 4) return 4751360.0;
    if (id == 5) return 2995812.0;
    if (id == 6) return 8945664.0;
    if (id == 7) return 3003172.0;
    if (id == return 9469963.0;
    if (id == 9) return 7248164.0;
    if (id == 10) return 2359385.0;
    if (id == 11) return 10897481.0;
    if (id == 12) return 6554331.0;
    if (id == 13) return 9574107.0;
    if (id == 14) return 2134601.0;
    if (id == 15) return 9492189.0;
    if (id == 16) return 3894705.0;
    if (id == 17) return 9474632.0;
    if (id == 18) return 2396785.0;
    if (id == 19) return 9585152.0;
    if (id == 20) return 14380132.0;
    if (id == 21) return 8683521.0;
    if (id == 22) return 2398500.0;
    if (id == 23) return 1.0;
    if (id == 24) return 4681.0;   
    return 0.0;   
}

vec3 color(int id)
{
    // flappy bird colors
    if (id == 0) return vec3(0.0);
    if (id == 1) return vec3(0.320,0.223,0.289);
    if (id == 2) return vec3(0.996,0.449,0.063);
    if (id == 3) return vec3(0.965,0.996,0.965);
    if (id == 4) return vec3(0.996,0.223,0.000);
    if (id == 5) return vec3(0.836,0.902,0.805);
    return vec3(0.965,0.707,0.191);
}
// ---

int sprite(vec2 p)
{
    // this time it's 3 bit/px (8 colors) and 8px/slice, 204px total
    int d = 0;
    p = floor(p);
    p.x = 16.0 - p.x;
   
    if (clamp(p.x, 0.0, 16.0) == p.x && clamp(p.y, 0.0, 11.0) == p.y)
    {
        float k = p.x + 17.0*p.y;
        float s = floor(k / 8.0);
        float n = slice(int(s));
        k = (k - s*8.0)*3.0;
        if (int(mod(n/(pow(2.0,k)),2.0)) == 1)         d += 1;
        if (int(mod(n/(pow(2.0,k+1.0)),2.0)) == 1)     d += 2;
        if (int(mod(n/(pow(2.0,k+2.0)),2.0)) == 1)     d += 4;
    }
    return d;
}

void hero(inout vec3 col, vec2 p, float angle)
{
    p = vec2(p.x * cos(angle) - p.y * sin(angle), p.y * cos(angle) + p.x * sin(angle));
    int i = sprite(p*0.2);
    col = mix(col, color(i), min(1.0, float(i)));
}

void ground(inout vec3 col, vec2 p)
{
    p = floor(p);
    if (p.y > -280.0) return;
    if (p.y < -285.0) col = color(1);
    if (p.y < -290.0) col = vec3(0.902, 1.000, 0.549);
    if (p.y < -295.0) col = mix(vec3(0.612, 0.906, 0.353), vec3(0.451, 0.745, 0.192), step(mod(p.x-floor(p.y/5.0)*5.0, 60.0), 30.0));
    if (p.y < -325.0) col = vec3(0.322, 0.506, 0.129);
    if (p.y < -330.0) col = vec3(0.839, 0.667, 0.290);
    if (p.y < -335.0) col = vec3(0.871, 0.843, 0.580);
}

void sky(inout vec3 col, vec2 p)
{
    col = mix(col, vec3(1.0), 0.3*sin(p.y*0.01));
}

float hAt(float i)
{
    return 250.0*rand(i*1.232157);
}

void main()
{
    float s = 2000.0/iResolution.x;
    vec2 p = max(1.6666667, s)*(gl_FragCoord.xy - iResolution.xy * 0.5);
    float dx = iGlobalTime * 320.0;
    p.x += dx;
   
    vec3 col = vec3(0.322, 0.745, 0.808);
    sky(col, vec2(0.0, -100.0)-p);
   
    pipe(col, vec2(mod(p.x, 400.0)-200.0, p.y + hAt(floor(p.x / 400.0)) - 80.0), 110.0);
   
    float hx = dx - 200.0; // hero x
    float sx = hx - 300.0; // sample x
    float i = floor(sx/400.0); // instance
    float ch = hAt(i); // current height
    float nh = hAt(i+1.0); // next height
    //    float bh = abs(60.0*sin(iChannelTime[0]*6.0)); // bounce height
    float bh = abs(60.0*sin(iGlobalTime*6.0)); // bounce height
    float hy = bh - mix(ch, nh, min(1.0, mod(sx, 400.0)*0.005)) + 80.0; // hero y
    float angle = -min(0.1, 0.002*(bh));
    hero(col, vec2(hx, hy)-p, angle);
   
    ground(col, p);
   
    gl_FragColor = vec4(col,1.0);
}



//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Flappy Bird", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


49
English forum / Re: Hypertexture trabeculum converted
« on: June 08, 2015, 04:28:48 PM »
OK,
i found the problem.
The interpreter of the forum software destroys the code by creating smileys even if you tell it not to do so.

Download an updated pack from here:
https://goo.gl/eXZvv4

I added more stuff like:
Palmetto stalk
Terminator
Unreal Intro
Shadering chameleon
Useless box
distance field

50
Over the past year or two AMD’s Mantle introduced the efficiency of low-level APIs to the PC gaming developer community. That sparked a trend leading to significant developments in graphics APIs like Vulkan™ and DirectX® 12. When asked what, in my opinion, is the greatest feature of those new graphics APIs, my answer is “concurrency,” The new APIs do not introduce any new shader stages. The main benefit they provide to developers is concurrency. This is important, since most computer graphics problems are almost embarrassingly parallel, and so is the hardware designed to accelerate it. However, past APIs often treated the GPU like a sequential machine, which often resulted in efficiency issues or bottlenecks. The new APIs will help avoid those bottlenecks.
read on...

51
English forum / Trampoline converted
« on: June 07, 2015, 07:23:52 AM »
Trampoline converted to GLSL Hacker format

I used the only cubemap that comes with MadShaders.
If you don't like that, study the code - i prepared it for random 2D textures.

Texture for the net tex08.jpg is somehow broken, load and save in e.g. IrfanView to fix.

Copy the code and save as Trampoline_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Trampoline"
          width="800" height="800"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/XtSGW1

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
uniform sampler2D iChannel0;
uniform sampler2D iChannel1; // Texture for the net tex08.jpg is somehow broken, load and save in e.g. IrfanView to fix.
//uniform sampler2D iChannel2;
uniform samplerCube iChannel2;

//

#define time iGlobalTime
#define EPSILON .0001
#define PI 3.14159265

const int MAX_ITER = 80;
vec3 lightDir    = normalize(vec3(-1.6, 0.7, -0.5));
float speedJump = 0.8;  //???
float heightJump = 7.;  //
float ballSize = 1.7;   //??

struct mat
{
  float typeMat; 
  bool  ref;     
     
};
mat materialMy = mat(0.0, false);
//-----------------------------
vec3 getNormal(in vec3 p);
float renderFunction(in vec3 pos);
float render(in vec3 posOnRay, in vec3 rayDir);
vec3 getColorPixel(inout vec3 ro, vec3 rd, inout vec3 normal, float dist, float typeColor);
float distMat(inout float curDist, float dist, in float typeMat, in bool refl);
//-----------------------------
vec3 rotationCoord(vec3 n, in float t, float paramRotate)
{
 vec3 result;
 //--------------------------------------------
   vec2 sc = vec2(sin(t), cos(t));
   mat3 rotate;
   if(paramRotate <= 0.1)
   {

      rotate = mat3(  1.0,  0.0,  0.0,
                      0.0,  1.0,  0.0,
                      0.0,  0.0,  1.0);   
   }
   else if(paramRotate <= 1.0)
   {
      rotate = mat3(  1.0,  0.0,  0.0,
                      0.0, sc.y,-sc.x,
                      0.0, sc.x, sc.y);
   }
   else if(paramRotate <= 2.0)
   {
       rotate = mat3(  1.0,  0.0,  0.0,
                       0.0, sc.y,sc.x,
                       0.0, -sc.x, sc.y); 
   }
   else if (paramRotate <= 3.0)
   {
      rotate = mat3( sc.y,  0.0, -sc.x,
                     0.0,   1.0,  0.0,
                     sc.x,  0.0, sc.y);   
   }
   else if (paramRotate <= 4.0)
   {
      rotate = mat3( sc.y,  0.0, sc.x,
                     0.0,   1.0,  0.0,
                    -sc.x,  0.0, sc.y);   
   }   
   else if (paramRotate <= 5.0)
   {
       rotate = mat3( sc.y,sc.x,  0.0,
                     -sc.x, sc.y, 0.0,
                      0.0,  0.0,  1.0); 
   }   
   else if (paramRotate <= 6.0)
   {
       rotate = mat3( sc.y,-sc.x, 0.0,
                      sc.x, sc.y, 0.0,
                      0.0,  0.0,  1.0); 
   }     
   else
   {
   mat3 rotate_x = mat3(  1.0,  0.0,  0.0,
                          0.0, sc.y,-sc.x,
                          0.0, sc.x, sc.y);
   mat3 rotate_y = mat3( sc.y,  0.0, -sc.x,
                         0.0,   1.0,  0.0,
                         sc.x,  0.0,  sc.y);
   mat3 rotate_z = mat3( sc.y, sc.x,  0.0,
                        -sc.x, sc.y,  0.0,
                         0.0,  0.0,   1.0);
   rotate = rotate_z * rotate_y * rotate_z;               
   }
  result = n * rotate;
  return result;
}
//----------------------------------------------------

//------------------------------------------
vec2 rot(vec2 p,float r){
  vec2 ret;
  ret.x=p.x*cos(r)-p.y*sin(r);
  ret.y=p.x*sin(r)+p.y*cos(r);
  return ret;
}
//------------------------------------------
vec2 rotsim(vec2 p,float s)
{
  vec2 ret=p;
  ret=rot(p,-PI/(s*2.0));
  ret=rot(p,floor(atan(ret.x,ret.y)/PI*s)*(PI/s));
  return ret;
}
//???
//------------------------------------------
float udRoundBox( vec3 p, vec3 b, float r )
{
  return length(max(abs(p)-b,0.0))-r;
}
//----------------------------------------------------
float dTorus(vec3 p, vec2 t)
{
   vec2 q = vec2(length(p.xz) - t.x, p.y);
   return length(q) - t.y;
}
//----------------------------------------------------
float dSphere(vec3 p, float r)
{
   return length(p) - r;
}
//----------------------------------------------------
float yCylinder(vec3 p, vec2 h)
{
    return max( length(p.xz)-h.x, abs(p.y)-h.y );
}
//--------------------------------------------------
// capsule in Y axis
float capsuleY(vec3 p, float r, float h)
{
    p.y -= clamp(p.y, 0.0, h);
    return length(p) - r;
}
//--------------------------------------------------
float sdCapsule( vec3 p, vec3 a, vec3 b, float r ) {
   vec3 pa = p - a, ba = b - a;
   float h = clamp( dot(pa, ba) / dot(ba , ba), 0.0, 1.0 );
       return length( pa - ba * h ) - r;
}
//---------------------------------------------------
float zCylinder(vec3 p, vec2 h)
{
    return max( length(p.xy)-h.x, abs(p.z)-h.y );
}
//------------------------------------------
//?? https://www.shadertoy.com/view/ltXGRj
float rays(in vec3 p, in vec2 size, in float r)
{
   float rad=length(p);
   return (length(p.xz)- size.x + size.y * (rad - r));
}
float astra(in vec3 p, in vec2 kol, in vec2 size, in float r)
{
   p.xy = rotsim(p.xy, kol.x);
   p.zy = rotsim(p.zy, kol.y);
   return rays(p, size, r);
}
//--------------------------------------------------
//-------------------------------------------------
//http://glslsandbox.com/e#20289.0
float dSegment(vec3 p,  vec3 a, vec3 b, float r1, float r2)
{
   vec3 pa = p - a;
   vec3 ba = b - a;
   float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
   return length( pa - ba*h ) - r1 + r2*h;
}
//--------------------------------------------------
float smin( float a, float b, float k )
{
   float h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 );
   return mix( b, a, h ) - k*h*(1.0-h);
}
//
//--------------------------------------------------???
float jumper(in vec3 pos, in float r,in float d)
{
   float d1 = 1.;
   vec3 p = pos;
   float angle = 0.;
   float r25 = r*0.25, r15 =r*0.15, r30 = r* 0.3, r50 = r*0.5, r40 = r*0.4,
         r60 = r*0.6, r80 = r*0.8, r70 = r*0.7, r90 = r*0.9;   
  d1 = dSphere(p , r90); //
  d1 = smin(d1, dSphere(p +  vec3(0., r25, -r80),r25), 0.1);
  p.x = abs(p.x);
  p -= vec3(r70, 0., r80);
  p.yz = rot(p.yz, 1.);
  d1 = max(d1, -dTorus(p , vec2(-r15, r40)));
 //--------//?
  p = pos;
  float t = fract(speedJump * time);//??
  t *= 4.0  * (1.0 - t);
  angle = clamp(2.7 * t, 0.2, 2.7);   //??? 
 
 vec3 offY = vec3(0., r + r50, 0.);
 d1 = min(d1,capsuleY(p + offY, r25, r50)); //
 p.x = abs(p.x);
 p -= vec3(r60, -(r+r90), 0.);
 p.xy = rot(p.xy, angle);
 d1 = min(d1,  capsuleY(p, r25,r*2.)); //?
 d1 = min(d1,  dSphere(p - vec3(0., r*2., 0.), r30));
 d =  distMat(d,  d1,2.0, false );
//----------- //??
  p = pos;
  p.x = abs(p.x);
  p -= vec3(r60, 0., r60);
  d =  distMat(d,  dSphere(p , r15) ,  4.0, false) ;
//----------//??
 p = pos;
 p.yz = rot(p.yz, -0.;
 d1 = min(d1, astra(p , vec2(20.), vec2(r25, 0.15 ), 0.));
 d1 = max(d1, -dSphere(p -  vec3(0., 0., r*2.),r*2.));
 d =  distMat(d,  d1   ,  5.0, false ); 
 //--------//?
 p = pos;
 offY = vec3(0., r*3.+r25, 0.); 
 d1 = capsuleY(p + offY, r90, r+r25);             //?
 //--------
 offY = vec3(r60, -(r+r80), 0.);
 p.x = abs(p.x);
 p -= offY;
 p.xy = rot(p.xy, angle);
 d1 = min(d1,  capsuleY(p, r40, r80));   //
 d =  distMat(d,  d1   ,  3.0, false );
 //-----------
 d =  distMat(d,  dSphere(p , r70) ,  4.0, false );
 //-------- //??
 angle = clamp(-1.5 * t, -2., 0.); 
 //------------------
 offY = vec3(0., r*3.+r60, 0.); 
 p = pos + offY;
 d1 = capsuleY(p, r80, r25); //?
//------------------
 p = pos;
 p.x = abs(p.x);
 offY = vec3(r50, -(r*4.), 0.);
 p -= offY;
//=================================================
  vec3 p1 = vec3(0.);
  vec3 p2 = vec3(0., -(r+r50), 0.);
  vec3 p3 = vec3(0., -(r+r50), 0.);
  p2.yz = rot(p2.yz, angle); 
  p3.xy += p2.xy;
   
  d1 = smin(d1, dSegment(p, p1, p2, r50, 0.), 0.1);  //???
  d =  distMat(d,  d1   ,  4.0, false ); 
  d1 = dSegment(p, p2, p3, r30, 0.);        //?
  d =  distMat(d,  d1   ,  2.0, false );
  p += vec3(0., r+r50, -r30);
  p.xy -= p2.xy;
  d1 = dSphere(p * vec3(1.5, 1.5, 0.6), r50);            //??
  d =  distMat(d,  d1   ,  5.0, false); 
//=================================================

  return d;
}

//--------------------------------------------------
float sinc(float x)
{
   return sin(x) / x;
}
//--------------------------------------------------
float getY(in vec2 p, float push, float ballz)
{
   float stiffness = 0.4;
   float dotP =dot(p,p);
   float punch = exp2(-stiffness * dotP);
   ballz -= (ballSize * ballSize - dotP);
   return min(punch * push, ballz);
}
//--------------------------------------------------
float  dTrampoline(in vec3 pos, in float r, in float d)
{
  vec3 p = pos;
  float d1 = 1.; 
  float t = fract(speedJump * time);
  float push = -ballSize * sinc(42. * t); //?
 
   float y = getY(p.xz, push, heightJump);
   p.y -= y ;
   d1=  yCylinder(p, vec2(r*7., 0.02));      //??
   d =  distMat(d,  d1   ,  7.0, false );   
   d1 = dTorus(p, vec2(r*7., r*0.4));         //?
   d =  distMat(d,  d1   ,  4.0, false );
   //----------
   p = pos + vec3(0.,r*2., 0.);

   p.xz = rotsim( p.xz, 6.);
   p.xz = abs(p.xz);
   p.z -= r*7.;
   p.xy = rot(p.xy, 0.5);   
   d1 = capsuleY(p, r*0.4, r*2.5);       //??
   d =  distMat(d,  d1   ,  1.0, false);     
   //---------- 
  return d;
}
//------------------------------------------
float distMat(inout float curDist, float dist, in float typeMat, in bool refl)
{
   float res = curDist;
   if (dist < curDist)
   {
      materialMy.typeMat     = typeMat;
      materialMy.ref         = refl;
      res                    = dist;
     return res;
   }
   return curDist;
}

//--------------------------------------------------
float myObject(in vec3 p)
{
   float d =  1.0;
   float r = 0.7;
   materialMy.typeMat = 0.0;
   materialMy.ref = false;
   vec3 pos = p;
   pos += vec3(0., 8., 0.);

  d =  distMat(d,   udRoundBox( pos, vec3(10, 0.3, 10. ), 0.5),  1.0, true);   
//======================================??
  pos = p + vec3(0., 6.,  0.);
  d =  dTrampoline(pos, r,  d);
//======================================???
  pos.y -= r*7.;
  float t = fract(speedJump * time);//??
  t *= 4.0  * (1.0 - t);
  pos.y -= heightJump * t ;
  pos = rotationCoord(pos,t * 4., 3.);   
//  pos = rotationCoord(pos,t * 8., 1.);   
  d = jumper(pos,r,d);

   return d;
}
//-------------------------------------------------
//???
float renderFunction(in vec3 pos)
{
    return  myObject(pos);   
}
//-------------------------------------------------
vec3 getNormal(in vec3 p)
{

const float precis = 0.00001;
    vec3  eps = vec3(precis,0.0,0.0);
    vec3 nor;
    nor.x = renderFunction(p+eps.xyy) - renderFunction(p-eps.xyy);
    nor.y = renderFunction(p+eps.yxy) - renderFunction(p-eps.yxy);
    nor.z = renderFunction(p+eps.yyx) - renderFunction(p-eps.yyx);
    return normalize(nor);

}
//???,? -??  ? IQ
//https://www.shadertoy.com/view/Xds3zN
//-------------------------------------------------
float calcAO( in vec3 pos, in vec3 nor )
{
   float occ = 0.0;
    float sca = 1.0;
    for( int i=0; i<5; i++ )
    {
        float hr = 0.01 + 0.12*float(i)/4.0;
        vec3 aopos =  nor * hr + pos;
        float dd = renderFunction( aopos );
        occ += -(dd-hr)*sca;
        sca *= 0.95;
    }
    return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );   
}
//-------------------------------------------------
float softshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
{
   float res = 1.0;
    float t = mint;
    for( int i=0; i<16; i++ )
    {
      float h = renderFunction( ro + rd*t );
        res = min( res, 8.0*h/t );
        t += clamp( h, 0.02, 0.10 );
        if( h<0.001 || t>tmax ) break;
    }
    return clamp( res, 0.0, 1.0 );
}

//-------------------------------------------------
vec3 getLighting1(in vec3 ro, in vec3 rd ,in vec3 norm, in vec3 lightDir, in vec3 color, in float dist)
{
   vec3 col = color;
   float occ = calcAO( ro, norm );
   vec3 ref = reflect( rd, norm );
   float amb = clamp( 0.5+0.5*norm.y, 0.0, 1.0 );
   float dif = clamp( dot( norm, lightDir ), 0.0, 1.0 );
   float bac = clamp( dot( norm, normalize(vec3(-lightDir.x,0.0,-lightDir.z))), 0.0, 1.0 )*clamp( 1.0-ro.y,0.0,1.0);
   float dom = smoothstep( -0.1, 0.1, ref.y );
   float fre = pow( clamp(1.0+dot(norm,rd),0.0,1.0), 2.0 );
   float spe = pow(clamp( dot( ref, lightDir ), 0.0, 1.0 ),16.0);
   dif *= softshadow( ro, lightDir, 0.02, 2.5 );
   dom *= softshadow( ro, ref, 0.02, 2.5 );
   vec3 brdf = vec3(0.0);
   brdf += 1.20*dif*vec3(1.00,0.90,0.60);
   brdf += 1.20*spe*vec3(1.00,0.90,0.60)*dif;
   brdf += 0.30*amb*vec3(0.50,0.70,1.00)*occ;
   brdf += 0.40*dom*vec3(0.50,0.70,1.00)*occ;
   brdf += 0.30*bac*vec3(0.25,0.25,0.25)*occ;
   brdf += 0.40*fre*vec3(1.00,1.00,1.00)*occ;
   if(materialMy.ref)
         //col += pow(texture2D( iChannel2, ref ).xyz,vec3(2.2));
         col += pow(textureCube( iChannel2, ref ).xyz,vec3(2.2));
   col = col*brdf;
//   col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0005*dist*dist ) );
   return col ;
}

//----------------------------------------------------------------------
vec3 getColorPixel(inout vec3 ro, vec3 rd, inout vec3 normal, float dist, float typeColor)
{

  //vec3 color = texture2D( iChannel2, rd ).xyz;//vec4(1.);
  vec3 color = textureCube( iChannel2, rd ).xyz;//vec4(1.);
  vec3 hitPos = ro + rd * dist;
  normal = normalize(getNormal(hitPos)); 
//----------------------------------

  if (materialMy.typeMat == 0.0)
  {
    //color = texture2D( iChannel2, rd ).xyz;
    color = textureCube( iChannel2, rd ).xyz;
   }
 else if (materialMy.typeMat == 1.0)   
        color.rgb = texture2D( iChannel0, 0.15 * hitPos.xz ).xyz;
 else if (materialMy.typeMat == 2.0)   
        color = vec3(1., 0.61, 0.43);     
 else if (materialMy.typeMat == 3.0)   
        color = vec3(0.3, 0.7, 1.);
 else if (materialMy.typeMat == 4.0)   
        color = vec3(0.07, 0.08, 0.46);
 else if (materialMy.typeMat == 5.0)   
        color = vec3(0.38, 0.23, 0.67);
 else if (materialMy.typeMat == 7.)
      color = texture2D( iChannel1, 0.15 * hitPos.xz ).xyz;
 else
       color = vec3(0.5);

   if(materialMy.typeMat !=0. )
   {
       color = getLighting1(hitPos, rd, normal, lightDir, color,dist);
   }   
    ro = hitPos;

  return color;
}

//-------------------------------------------------
float render(in vec3 posOnRay, in vec3 rayDir)
{
  float t = 0.0;
  float maxDist = 40.;
  float d = 0.1; 

  for(int i=0; i<MAX_ITER; ++i)
  {
    if (abs(d) <EPSILON || t > maxDist)
         break;
    t += d;
    vec3 ro = posOnRay + t*rayDir;
    d = renderFunction(ro);     
  }

   return t;
}
//------------------------------------------
void main()
{
    vec2 pos     =  gl_FragCoord.xy / iResolution.xy * 2. - 1.;
    pos.x *= iResolution.x / iResolution.y; 
    vec2 m = vec2(0.);
    if( iMouse.z>0.0 )m = iMouse.xy/iResolution.xy*PI*2.;
   
    vec3 camPos = vec3(0., 3., 17.);
    camPos.yz=rot(camPos.yz, m.y);
    camPos.xz=rot(camPos.yz, m.x+ 0.1*time+1.);
    vec3 camP = rotationCoord(camPos,time * 0.1, 3.);
    vec3 camUp = vec3(0. , 1., 0.);
    vec3 camDir = normalize(-camP);
    vec3 u = normalize(cross(camUp,camDir));
    vec3 v = cross(camDir,u);
    vec3 rayDir = normalize(camDir * 2. + pos.x * u + pos.y * v); 

   vec4 color    = vec4(1.0);
    vec3 normal   = vec3(1.0);
    vec3 posOnRay = camP;
    float path = 0.;
  //---------------------------
     path =  render(posOnRay, rayDir); 
     color.rgb = getColorPixel(posOnRay, rayDir, normal, path, materialMy.typeMat);
    // Gamma correct
     color.rgb = pow(color.rgb , vec3(0.45));
    // Contrast adjust - cute trick learned from iq
     color.rgb  = mix( color.rgb , vec3(dot(color.rgb ,vec3(0.333))), -0.6 );
     color.a = 1.;
     gl_FragColor =  color;

}

//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

tex0 = moon3d.image.load2d("./data/tex06.jpg")
tex1 = moon3d.image.load2d("./data/tex08.jpg")
-- tex2 = moon3d.image.load2d("./data/cubemap01_posz.jpg")
cubemap = moon3d.image.loadCubeMap("./data/cubemap01_posx.jpg", "./data/cubemap01_negx.jpg", "./data/cubemap01_posy.jpg", "./data/cubemap01_negy.jpg", "./data/cubemap01_posz.jpg", "./data/cubemap01_negz.jpg")
moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex1, 1)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex2, 2)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, cubemap, 2)

moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/trampoline", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


52
English forum / Clover tree converted
« on: June 07, 2015, 06:43:33 AM »
Clover tree converted to GLSL Hacker format.

I used the only cubemap that comes with MadShaders.
If you don't like that, study the code - i prepared it for random 2D textures.

Copy the code and save as Clover_tree_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Clover tree"
          width="800" height="800"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/4dlXR4

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
uniform sampler2D iChannel0;
// uniform sampler2D iChannel1;
// uniform sampler2D iChannel2;
uniform samplerCube iChannel1;
uniform samplerCube iChannel2;

//

// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// Domain repetition. A (simple) clover shape is repeated over space.

// Clearly NOT the way to do it (super slow). I run out of instructions (and speed), so
// I couldn't add variation or detail or lighting really. But the basic technique is there.

float hash1( vec3 p )
{
    return fract(sin(dot(p,vec3(1.0,57.0,113.0)))*43758.5453);
}
vec3 hash3( float n )
{
    return fract(sin(vec3(n,n+1.0,n+2.0))*vec3(43758.5453123,22578.1459123,19642.3490423));
}
vec3 hash3( vec3 p )
{
    return fract(sin(vec3( dot(p,vec3(1.0,57.0,113.0)),
                           dot(p,vec3(57.0,113.0,1.0)),
                           dot(p,vec3(113.0,1.0,57.0))))*43758.5453);
}

// simple clover shape
float shape( in vec3 p, in float s )
{
    float a = atan( p.x, p.y );
    float r = length( p.xy );
   
    float ra = 0.2 + 0.3*sqrt(0.5+0.5*sin( 3.0*a ));
    ra *= s;
    return min( max(length(p.xy)-0.04*(0.5+0.5*p.z),-p.z), max( length(p.xy)-ra, abs(p.z-0.2*r)-0.06*s*clamp(1.0-1.5*r,0.0,1.0) ) );
}

// df
vec4 map( vec3 p )
{
    p.x += 0.1*sin( 3.0*p.y );
   
    float rr = length(p.xz);
    float ma = 0.0;
    vec2 uv = vec2(0.0);
   
    float d1 = rr - 1.5;
    if( d1<1.8 )
    {
       
        float siz = 6.0;
        vec3 x = p*siz + 0.5;
        vec3 xi = floor( x );
        vec3 xf = fract( x );

        vec2 d3 = vec2( 1000.0, 0.0 );
        for( int k=-1; k<=1; k++ )
        for( int j=-1; j<=1; j++ )
        for( int i=-1; i<=1; i++ )
        {
            vec3 b = vec3( float(i), float(j), float(k) );
            vec3 c = xi + b;
           
            float ic = dot(c.xz,c.xz)/(siz*siz);
           
            float re = 1.5;
           
            if( ic>(1.0*1.0) && ic < (re*re) )
            {
            vec3 r = b - xf + 0.5 + 0.4*(-1.0+2.0*hash3( c ));
            //vec3 r = c + 0.5 - x;

            vec3 ww = normalize( vec3(c.x,0.0,c.z) );
            ww.y += 1.0; ww = normalize(ww);
            ww += 0.25 * (-1.0+2.0*hash3( c+123.123 ));
               
            vec3 uu = normalize( cross( ww, vec3(0.0,1.0,0.0) ) );
            vec3 vv = normalize( cross( uu, ww ) );
            r = mat3(  uu.x, vv.x, ww.x,
                       uu.y, vv.y, ww.y,
                       uu.z, vv.z, ww.z )*r;
            float s = 0.75 + 0.5*hash1( c+167.7 );               
            float d = shape(r,s)/siz;
            if( d < d3.x )
            {
                d3 = vec2( d, 1.0 );
                ma = hash1( c.yzx+712.1 );
                uv = r.xy;
            }
            }
        }
        d1 = mix( rr-1.5, d3.x, d3.y );
    }
   
    d1 = min( d1, rr - 1.0 );

    return vec4(d1, ma, uv );
   
}


vec4 intersect( in vec3 ro, in vec3 rd )
{
    const float maxd = 10.0;
   
    float h = 1.0;
    float t = 0.0;
    float m = -1.0;
    vec2  u = vec2(0.0);
    for( int i=0; i<50; i++ )
    {
        if( h<0.001||t>maxd ) continue;//break;
        t += h;
        vec4 res = map( ro+rd*t );
        h = res.x;
        m = res.y;
        u = res.zw;
    }

    if( t>maxd ) m=-1.0;
    return vec4( t, m, u );
}

vec3 calcNormal( in vec3 pos )
{
    vec2 eps = vec2(0.001,0.0);

    return normalize( vec3(
           map(pos+eps.xyy).x - map(pos-eps.xyy).x,
           map(pos+eps.yxy).x - map(pos-eps.yxy).x,
           map(pos+eps.yyx).x - map(pos-eps.yyx).x ) );
}


void main()
{
    vec2 q = gl_FragCoord.xy / iResolution.xy;
    vec2 p = -1.0 + 2.0 * q;
    p.x *= iResolution.x/iResolution.y;
    vec2 m = iMouse.xy/iResolution.xy;
   
    // camera
    float an = 20.0 + 0.15*iGlobalTime - 7.0*m.x;
    vec3  ro = 3.1*normalize(vec3(sin(an),0.5-0.4*m.y, cos(an)));
    vec3  ta = vec3( 0.0, 0.8, 0.0 );
    float rl = 0.5*sin(0.35*an);
    vec3  ww = normalize( ta - ro );
    vec3  uu = normalize( cross(ww,vec3(sin(rl),cos(rl),0.0) ) );
    vec3  vv = normalize( cross(uu,ww));
    vec3  rd = normalize( p.x*uu + p.y*vv + 1.5*ww );

    // render
    // vec3 col = texture2D( iChannel2, rd ).xyz; col = col*col;
    //
    vec3 col = textureCube( iChannel2, rd ).xyz; col = col*col;
   
    // raymarch
    vec4 tmat = intersect(ro,rd);
    if( tmat.y>-0.5 )
    {
        // geometry
        vec3 pos = ro + tmat.x*rd;
        vec3 nor = calcNormal(pos);
        vec3 ref = reflect( rd, nor );

        // material
        vec3 mate = vec3(0.3,0.5,0.1);
        mate = mix( mate, vec3(0.5,0.25,0.1), smoothstep( 0.9,0.91, tmat.y) );
        mate += 0.1*sin( tmat.y*10.0  + vec3(0.0,2.0,2.0));
        mate *= 0.8+0.4*tmat.y;
        vec2 uv = tmat.zw;
        float r = length(uv);
        float a = atan(uv.y,uv.x);
        mate += vec3(0.2,0.15,0.1)*smoothstep(0.8,1.0,-cos(3.0*a))*(1.0-1.5*r);
        mate *= 0.2+r;
       
        // lighting
        float amb = clamp(0.5+0.5*nor.y,0.0,1.0);
        amb *= 0.1 + 0.9*pow( clamp( (length(pos.xz)-1.0)/(1.5-1.0), 0.0, 1.0 ), 2.0 );
        vec3 snor = normalize( nor + normalize( vec3(pos.x,0.0,pos.y) ) );
        // vec3 lin = 1.0*texture2D( iChannel1, snor ).xyz*amb;
        //
        vec3 lin = 1.0*textureCube( iChannel1, snor ).xyz*amb;
        col = mate*lin;
        float kd = pow(clamp(1.0+dot(rd,nor),0.0,1.0),3.0);
        // col += 0.2*kd*pow( texture2D( iChannel2, ref ).xyz, vec3(2.2) )*amb;
        //
        col += 0.2*kd*pow( textureCube( iChannel2, ref ).xyz, vec3(2.2) )*amb;
    }

    // gamma
    col = pow( col, vec3(0.45) );
   
    // vigneting
    col *= 0.5 + 0.5*pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.15 );
   
    gl_FragColor = vec4( col,1.0 );
}

//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

tex0 = moon3d.image.load2d("./data/noise_texture_0010_256x256.jpg")
-- tex1 = moon3d.image.load2d("./data/tex10.png")
-- tex2 = moon3d.image.load2d("./data/ground013.jpg")
cubemap = moon3d.image.loadCubeMap("./data/cubemap01_posx.jpg", "./data/cubemap01_negx.jpg", "./data/cubemap01_posy.jpg", "./data/cubemap01_negy.jpg", "./data/cubemap01_posz.jpg", "./data/cubemap01_negz.jpg")
moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
-- moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex1, 1)
-- moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex2, 2)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, cubemap, 1)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, cubemap, 2)

moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Clover tree", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


53
English forum / Audrey converted
« on: June 06, 2015, 01:09:09 PM »
Audrey converted to GLSL Hacker format

Copy the code and save as Audrey_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Audrey"
          width="800" height="800"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/4df3D8

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
//uniform sampler2D iChannel0;



//

// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// These are 316 gaussian points (201 brushes by using local symmetry) forming the picture
// of Audrey Hepburn. They pack down to 800 bytes (34 bits per point) before huffman/arithmetic
// compression.
//
// The points were chosen by (very quickly) runing this
//
// http://www.iquilezles.org/www/articles/genetic/genetic.htm
//
// with some importance sampling for the eyes, nouse and mouth.

float brush( float col, vec2 p, in vec4 b, float an )
{
    p += an*cos( iGlobalTime + 100.0*b.yz );
               
    vec2 dd = p - b.yz;
    col = mix( col, b.x, exp( -b.w*b.w*dot(dd,dd) ) );
    if( abs(b.z-0.5)<0.251 )
    {
        dd.x = p.x - 1.0 + b.y;
        col =  mix( col, b.x, exp( -b.w*b.w*dot(dd,dd) ) );
    }
    return col;
}

void main()
{
    vec2 uv = gl_FragCoord.xy / iResolution.y;
    uv.x -=  0.5*(iResolution.x / iResolution.y - 1.0);

    float an = smoothstep( 0.0, 1.0, cos(iGlobalTime) );

    float col = 0.0;

    col = brush( col, uv, vec4(1.000,0.371,0.379,11.770), an );
    col = brush( col, uv, vec4(0.992,0.545,0.551,8.359), an );
    col = brush( col, uv, vec4(0.749,0.623,0.990,36.571), an );
    col = brush( col, uv, vec4(1.000,0.510,0.395,11.315), an );
    col = brush( col, uv, vec4(1.000,0.723,0.564,15.170), an );
    col = brush( col, uv, vec4(0.953,0.729,0.750,14.629), an );
    col = brush( col, uv, vec4(0.706,0.982,0.033,16.254), an );
    col = brush( col, uv, vec4(1.000,0.855,0.652,26.256), an );
    col = brush( col, uv, vec4(1.000,0.664,0.623,81.920), an );
    col = brush( col, uv, vec4(0.000,0.881,0.750,8.031), an );
    col = brush( col, uv, vec4(0.686,0.682,0.900,27.676), an );
    col = brush( col, uv, vec4(1.000,0.189,0.684,18.618), an );
    col = brush( col, uv, vec4(0.000,0.904,0.750,8.031), an );
    col = brush( col, uv, vec4(1.000,0.422,0.195,44.522), an );
    col = brush( col, uv, vec4(1.000,0.779,0.750,16.787), an );
    col = brush( col, uv, vec4(1.000,0.645,0.330,14.222), an );
    col = brush( col, uv, vec4(1.000,0.197,0.648,22.505), an );
    col = brush( col, uv, vec4(0.702,0.512,0.393,35.310), an );
    col = brush( col, uv, vec4(1.000,0.744,0.621,14.949), an );
    col = brush( col, uv, vec4(0.671,0.885,0.092,24.675), an );
    col = brush( col, uv, vec4(0.000,0.344,0.750,8.031), an );
    col = brush( col, uv, vec4(1.000,0.760,0.465,40.960), an );
    col = brush( col, uv, vec4(0.008,0.908,0.311,8.031), an );
    col = brush( col, uv, vec4(0.016,0.959,0.750,10.039), an );
    col = brush( col, uv, vec4(0.004,0.930,0.750,12.800), an );
    col = brush( col, uv, vec4(1.000,0.555,0.250,19.883), an );
    col = brush( col, uv, vec4(1.000,0.770,1.018,15.876), an );
    col = brush( col, uv, vec4(0.000,0.828,0.756,36.571), an );
    col = brush( col, uv, vec4(0.580,0.566,0.424,89.043), an );
    col = brush( col, uv, vec4(0.988,0.162,0.691,40.157), an );
    col = brush( col, uv, vec4(0.000,0.314,0.750,8.031), an );
    col = brush( col, uv, vec4(0.000,0.947,0.125,32.000), an );
    col = brush( col, uv, vec4(0.914,0.844,0.725,52.513), an );
    col = brush( col, uv, vec4(1.000,0.313,0.762,42.667), an );
    col = brush( col, uv, vec4(0.996,0.676,0.689,85.333), an );
    col = brush( col, uv, vec4(0.980,0.346,0.559,24.675), an );
    col = brush( col, uv, vec4(1.000,0.553,0.250,18.789), an );
    col = brush( col, uv, vec4(0.004,0.258,0.248,8.031), an );
    col = brush( col, uv, vec4(1.000,0.420,0.742,30.567), an );
    col = brush( col, uv, vec4(0.906,0.543,0.250,22.756), an );
    col = brush( col, uv, vec4(0.863,0.674,0.322,20.078), an );
    col = brush( col, uv, vec4(0.753,0.357,0.686,78.769), an );
    col = brush( col, uv, vec4(0.906,0.795,0.705,37.236), an );
    col = brush( col, uv, vec4(0.933,0.520,0.365,38.642), an );
    col = brush( col, uv, vec4(0.996,0.318,0.488,14.734), an );
    col = brush( col, uv, vec4(0.337,0.486,0.281,81.920), an );
    col = brush( col, uv, vec4(0.965,0.691,0.516,16.650), an );
    col = brush( col, uv, vec4(0.808,0.582,0.973,52.513), an );
    col = brush( col, uv, vec4(0.012,0.240,0.928,8.063), an );
    col = brush( col, uv, vec4(1.000,0.496,0.217,31.508), an );
    col = brush( col, uv, vec4(0.000,0.658,0.953,34.133), an );
    col = brush( col, uv, vec4(0.871,0.582,0.172,62.061), an );
    col = brush( col, uv, vec4(0.855,0.346,0.342,17.504), an );
    col = brush( col, uv, vec4(0.878,0.787,0.648,28.845), an );
    col = brush( col, uv, vec4(0.000,0.984,0.111,35.310), an );
    col = brush( col, uv, vec4(0.855,0.514,0.965,66.065), an );
    col = brush( col, uv, vec4(0.561,0.613,0.350,81.920), an );
    col = brush( col, uv, vec4(0.992,0.818,0.902,21.558), an );
    col = brush( col, uv, vec4(0.914,0.746,0.615,40.157), an );
    col = brush( col, uv, vec4(0.557,0.580,0.125,60.235), an );
    col = brush( col, uv, vec4(0.475,0.547,0.414,70.621), an );
    col = brush( col, uv, vec4(0.843,0.680,0.793,20.277), an );
    col = brush( col, uv, vec4(1.000,0.230,0.758,56.889), an );
    col = brush( col, uv, vec4(1.000,0.299,0.691,68.267), an );
    col = brush( col, uv, vec4(0.737,0.518,0.100,68.267), an );
    col = brush( col, uv, vec4(0.996,0.227,0.514,41.796), an );
    col = brush( col, uv, vec4(0.929,0.850,0.770,62.061), an );
    col = brush( col, uv, vec4(0.682,0.834,0.111,30.118), an );
    col = brush( col, uv, vec4(0.996,0.854,0.793,58.514), an );
    col = brush( col, uv, vec4(0.490,0.736,0.889,19.321), an );
    col = brush( col, uv, vec4(0.980,0.465,0.725,16.126), an );
    col = brush( col, uv, vec4(0.992,0.484,1.010,23.273), an );
    col = brush( col, uv, vec4(0.008,0.949,0.727,23.540), an );
    col = brush( col, uv, vec4(0.012,0.086,0.086,8.031), an );
    col = brush( col, uv, vec4(1.000,0.121,0.750,44.522), an );
    col = brush( col, uv, vec4(0.427,0.617,0.891,27.676), an );
    col = brush( col, uv, vec4(0.804,0.693,0.633,78.769), an );
    col = brush( col, uv, vec4(0.012,0.711,0.084,13.745), an );
    col = brush( col, uv, vec4(0.082,0.584,0.338,107.789), an );
    col = brush( col, uv, vec4(0.929,0.613,0.268,19.692), an );
    col = brush( col, uv, vec4(0.200,0.549,0.420,128.000), an );
    col = brush( col, uv, vec4(1.000,0.402,0.717,26.947), an );
    col = brush( col, uv, vec4(0.000,0.551,0.168,45.511), an );
    col = brush( col, uv, vec4(0.992,0.627,0.621,56.889), an );
    col = brush( col, uv, vec4(0.902,0.361,0.748,40.960), an );
    col = brush( col, uv, vec4(0.984,0.344,0.754,38.642), an );
    col = brush( col, uv, vec4(0.902,0.203,0.818,51.200), an );
    col = brush( col, uv, vec4(1.000,0.230,0.803,52.513), an );
    col = brush( col, uv, vec4(0.922,0.738,0.691,47.628), an );
    col = brush( col, uv, vec4(0.000,0.385,0.797,43.574), an );
    col = brush( col, uv, vec4(0.000,0.725,0.305,62.061), an );
    col = brush( col, uv, vec4(0.000,0.150,0.750,45.511), an );
    col = brush( col, uv, vec4(1.000,0.742,0.408,47.628), an );
    col = brush( col, uv, vec4(0.000,0.645,0.643,60.235), an );
    col = brush( col, uv, vec4(1.000,0.645,0.438,35.310), an );
    col = brush( col, uv, vec4(0.510,0.564,0.789,18.450), an );
    col = brush( col, uv, vec4(0.863,0.211,0.781,30.567), an );
    col = brush( col, uv, vec4(0.106,0.508,0.328,89.043), an );
    col = brush( col, uv, vec4(0.012,0.410,0.875,14.629), an );
    col = brush( col, uv, vec4(1.000,0.871,0.877,48.762), an );
    col = brush( col, uv, vec4(1.000,0.258,0.779,37.926), an );
    col = brush( col, uv, vec4(0.000,0.436,0.807,28.845), an );
    col = brush( col, uv, vec4(0.918,0.861,0.836,49.951), an );
    col = brush( col, uv, vec4(1.000,0.291,0.770,40.960), an );
    col = brush( col, uv, vec4(0.000,0.750,0.283,27.676), an );
    col = brush( col, uv, vec4(0.965,0.596,0.572,28.055), an );
    col = brush( col, uv, vec4(0.902,0.803,0.953,24.976), an );
    col = brush( col, uv, vec4(0.957,0.498,0.600,16.126), an );
    col = brush( col, uv, vec4(0.914,0.322,0.432,15.634), an );
    col = brush( col, uv, vec4(0.008,0.025,0.621,17.809), an );
    col = brush( col, uv, vec4(0.000,0.916,0.713,56.889), an );
    col = brush( col, uv, vec4(0.914,0.547,0.971,47.628), an );
    col = brush( col, uv, vec4(0.000,0.207,0.432,37.926), an );
    col = brush( col, uv, vec4(0.875,0.176,0.793,46.545), an );
    col = brush( col, uv, vec4(0.000,0.646,0.668,41.796), an );
    col = brush( col, uv, vec4(1.000,0.721,0.691,51.200), an );
    col = brush( col, uv, vec4(0.451,0.559,0.754,49.951), an );
    col = brush( col, uv, vec4(0.969,0.846,0.750,58.514), an );
    col = brush( col, uv, vec4(0.000,0.900,0.146,36.571), an );
    col = brush( col, uv, vec4(1.000,0.613,0.635,85.333), an );
    col = brush( col, uv, vec4(0.596,0.807,0.150,58.514), an );
    col = brush( col, uv, vec4(0.898,0.330,0.760,40.157), an );
    col = brush( col, uv, vec4(0.694,0.594,0.012,51.200), an );
    col = brush( col, uv, vec4(0.698,0.592,0.055,53.895), an );
    col = brush( col, uv, vec4(0.902,0.268,0.773,39.385), an );
    col = brush( col, uv, vec4(0.925,0.838,0.660,58.514), an );
    col = brush( col, uv, vec4(0.843,0.670,0.242,28.444), an );
    col = brush( col, uv, vec4(0.243,0.465,0.285,85.333), an );
    col = brush( col, uv, vec4(0.816,0.588,0.674,44.522), an );
    col = brush( col, uv, vec4(0.008,0.283,0.115,8.031), an );
    col = brush( col, uv, vec4(0.247,0.414,0.691,60.235), an );
    col = brush( col, uv, vec4(1.000,0.104,0.781,60.235), an );
    col = brush( col, uv, vec4(0.000,0.619,0.660,60.235), an );
    col = brush( col, uv, vec4(0.584,0.650,0.994,46.545), an );
    col = brush( col, uv, vec4(0.000,0.219,0.393,36.571), an );
    col = brush( col, uv, vec4(1.000,0.307,0.645,97.524), an );
    col = brush( col, uv, vec4(0.953,0.639,0.771,38.642), an );
    col = brush( col, uv, vec4(0.000,0.238,0.357,34.712), an );
    col = brush( col, uv, vec4(0.922,0.713,0.352,53.895), an );
    col = brush( col, uv, vec4(0.965,0.387,0.748,43.574), an );
    col = brush( col, uv, vec4(0.000,0.898,0.633,41.796), an );
    col = brush( col, uv, vec4(0.941,0.352,0.488,14.734), an );
    col = brush( col, uv, vec4(0.933,0.439,0.725,30.567), an );
    col = brush( col, uv, vec4(0.310,0.541,0.906,47.628), an );
    col = brush( col, uv, vec4(0.941,0.502,0.689,24.094), an );
    col = brush( col, uv, vec4(0.094,0.527,0.330,85.333), an );
    col = brush( col, uv, vec4(0.000,0.090,0.688,55.351), an );
    col = brush( col, uv, vec4(0.000,0.652,0.713,75.852), an );
    col = brush( col, uv, vec4(0.949,0.320,0.623,107.789), an );
    col = brush( col, uv, vec4(0.890,0.775,0.750,22.505), an );
    col = brush( col, uv, vec4(0.012,0.918,0.490,14.322), an );
    col = brush( col, uv, vec4(1.000,0.871,0.967,58.514), an );
    col = brush( col, uv, vec4(0.000,0.324,0.676,64.000), an );
    col = brush( col, uv, vec4(0.008,0.141,0.248,8.031), an );
    col = brush( col, uv, vec4(0.000,0.633,0.707,75.852), an );
    col = brush( col, uv, vec4(0.910,0.385,0.207,44.522), an );
    col = brush( col, uv, vec4(0.012,0.703,0.182,31.508), an );
    col = brush( col, uv, vec4(0.000,0.617,0.703,73.143), an );
    col = brush( col, uv, vec4(0.890,0.352,0.225,45.511), an );
    col = brush( col, uv, vec4(0.933,0.826,0.604,44.522), an );
    col = brush( col, uv, vec4(0.914,0.777,0.574,25.924), an );
    col = brush( col, uv, vec4(0.631,0.781,0.182,68.267), an );
    col = brush( col, uv, vec4(1.000,0.873,0.916,48.762), an );
    col = brush( col, uv, vec4(0.694,0.520,0.113,81.920), an );
    col = brush( col, uv, vec4(0.000,0.900,0.926,58.514), an );
    col = brush( col, uv, vec4(0.184,0.598,0.344,146.286), an );
    col = brush( col, uv, vec4(0.863,0.678,0.250,35.310), an );
    col = brush( col, uv, vec4(0.090,0.566,0.332,78.769), an );
    col = brush( col, uv, vec4(0.420,0.445,0.301,56.889), an );
    col = brush( col, uv, vec4(0.973,0.617,0.516,18.124), an );
    col = brush( col, uv, vec4(0.000,0.191,0.500,39.385), an );
    col = brush( col, uv, vec4(0.000,0.240,0.326,31.508), an );
    col = brush( col, uv, vec4(0.000,0.264,0.322,55.351), an );
    col = brush( col, uv, vec4(0.000,0.604,0.699,70.621), an );
    col = brush( col, uv, vec4(0.000,0.113,0.604,43.574), an );
    col = brush( col, uv, vec4(0.894,0.760,0.697,49.951), an );
    col = brush( col, uv, vec4(0.914,0.725,0.383,55.351), an );
    col = brush( col, uv, vec4(0.000,0.199,0.467,48.762), an );
    col = brush( col, uv, vec4(0.000,0.904,0.660,52.513), an );
    col = brush( col, uv, vec4(0.922,0.611,0.191,45.511), an );
    col = brush( col, uv, vec4(0.059,0.789,0.869,30.118), an );
    col = brush( col, uv, vec4(0.976,0.641,0.213,40.960), an );
    col = brush( col, uv, vec4(0.918,0.402,0.742,47.628), an );
    col = brush( col, uv, vec4(0.945,0.717,0.582,40.157), an );
    col = brush( col, uv, vec4(0.000,0.299,0.672,58.514), an );
    col = brush( col, uv, vec4(0.000,0.719,0.666,48.762), an );
    col = brush( col, uv, vec4(0.882,0.697,0.271,58.514), an );
    col = brush( col, uv, vec4(0.929,0.752,0.436,64.000), an );
    col = brush( col, uv, vec4(1.000,0.867,0.813,56.889), an );
    col = brush( col, uv, vec4(0.643,0.588,0.090,64.000), an );
    col = brush( col, uv, vec4(0.012,0.063,0.922,10.952), an );
    col = brush( col, uv, vec4(0.878,0.186,0.750,31.508), an );
    col = brush( col, uv, vec4(0.953,0.648,0.613,120.471), an );
    col = brush( col, uv, vec4(0.973,0.180,0.576,45.511), an );
    col = brush( col, uv, vec4(0.741,0.943,0.076,52.513), an );
    col = brush( col, uv, vec4(0.059,0.545,0.332,89.043), an );
    col = brush( col, uv, vec4(0.094,0.295,0.734,85.333), an );
    col = brush( col, uv, vec4(0.008,0.676,0.721,85.333), an );
    col = brush( col, uv, vec4(0.550,0.350,0.650,85.000), an );

    gl_FragColor = vec4(col,col,col,1.0);
}


//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

-- tex0 = moon3d.image.load2d("./data/tex16.png")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Audrey", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


54
English forum / Schrödinger's cat converted
« on: June 06, 2015, 01:02:58 PM »
Schrödinger's cat converted to GLSL Hacker format.

If you never heard about Schrödinger's cat, check Wikipedia article

Copy the code and save as Schroedingers_cat _gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Schrödinger's cat"
          width="800" height="400"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/lsjXW3

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
//uniform sampler2D iChannel0;



//

// "Schroedinger's Cat" by dr2 - 2014
// License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

const vec4 cHashA4 = vec4 (0., 1., 57., 58.);
const vec3 cHashA3 = vec3 (1., 57., 113.);
const float cHashM = 43758.54;

float Hashfv2 (vec2 p)
{
  return fract (sin (dot (p, cHashA3.xy)) * cHashM);
}

vec4 Hashv4f (float p)
{
  return fract (sin (p + cHashA4) * cHashM);
}

float Noisefv2 (vec2 p)
{
  vec2 i = floor (p);
  vec2 f = fract (p);
  f = f * f * (3. - 2. * f);
  vec4 t = Hashv4f (dot (i, cHashA3.xy));
  return mix (mix (t.x, t.y, f.x), mix (t.z, t.w, f.x), f.y);
}

float Fbm2 (vec2 p)
{
  float s = 0.;
  float a = 1.;
  for (int i = 0; i < 5; i ++) {
    s += a * Noisefv2 (p);
    a *= 0.5;
    p *= 2.;
  }
  return s;
}

float Fbmn (vec3 p, vec3 n)
{
  vec3 s = vec3 (0.);
  float a = 1.;
  for (int i = 0; i < 5; i ++) {
    s += a * vec3 (Noisefv2 (p.yz), Noisefv2 (p.zx), Noisefv2 (p.xy));
    a *= 0.5;
    p *= 2.;
  }
  return dot (s, abs (n));
}

vec3 VaryNf (vec3 p, vec3 n, float f)
{
  vec3 e = vec3 (0.2, 0., 0.);
  float s = Fbmn (p, n);
  vec3 g = vec3 (Fbmn (p + e.xyy, n) - s,
     Fbmn (p + e.yxy, n) - s, Fbmn (p + e.yyx, n) - s);
  return normalize (n + f * (g - n * dot (n, g)));
}

float SmoothMin (float a, float b, float r)
{
  float h = clamp (0.5 + 0.5 * (b - a) / r, 0., 1.);
  return mix (b, a, h) - r * h * (1. - h);
}

float SmoothBump (float lo, float hi, float w, float x)
{
  return (1. - smoothstep (hi - w, hi + w, x)) * smoothstep (lo - w, lo + w, x);
}

float Length4 (vec2 p)
{
  p *= p;
  p *= p;
  return pow (p.x + p.y, 1./4.);
}

float Length8 (vec2 p)
{
  p *= p;
  p *= p;
  p *= p;
  return pow (p.x + p.y, 1./8.);
}

vec3 RgbToHsv (vec3 c)
{
  vec4 p = mix (vec4 (c.bg, vec2 (-1., 2./3.)), vec4 (c.gb, vec2 (0., -1./3.)),
     step (c.b, c.g));
  vec4 q = mix (vec4 (p.xyw, c.r), vec4 (c.r, p.yzx), step (p.x, c.r));
  float d = q.x - min (q.w, q.y);
  const float e = 1.e-10;
  return vec3 (abs (q.z + (q.w - q.y) / (6. * d + e)), d / (q.x + e), q.x);
}

vec3 HsvToRgb (vec3 c)
{
  vec3 p = abs (fract (c.xxx + vec3 (1., 2./3., 1./3.)) * 6. - 3.);
  return c.z * mix (vec3 (1.), clamp (p - 1., 0., 1.), c.y);
}

float PrSphDf (vec3 p, float r)
{
  return length (p) - r;
}

float PrBoxDf (vec3 p, vec3 b)
{
  vec3 d = abs (p) - b;
  return min (max (d.x, max (d.y, d.z)), 0.) + length (max (d, 0.));
}

float PrCylDf (vec3 p, float r, float h)
{
  return max (length (p.xy) - r, abs (p.z) - h);
}

float PrCapsDf (vec3 p, float r, float h)
{
  return length (p - vec3 (0., 0., h * clamp (p.z / h, -1., 1.))) - r;
}

float PrTorus88Df (vec3 p, float ri, float rc)
{
  vec2 q = vec2 (Length8 (p.xy) - rc, p.z);
  return Length8 (q) - ri;
}

int idObj;
mat3 bodyMat, headMat, tailMat, boxMat, boxMatR;
vec3 catPos, qHit, ltDir;
float bdLen, boxSize, tCur, tSeq, nSeq;
bool isLive;
const float dstFar = 150.;
const float pi = 3.14159;
const int idBody = 11, idLegs = 12, idTail = 13, idHead = 14, idEars = 15,
   idTongue = 16, idEyes = 17, idNose = 18, idWhisk = 19, idFloor = 20,
   idWall = 21, idWallR = 22, idHinge = 23, idJar = 24;

float CatBodyDf (vec3 p, float dHit)
{
  vec3 q, qh;
  float h, d, w, a, ca, sa;
  q = p;
  w = q.z / bdLen;
  d = PrCapsDf (q * vec3 (1.3, 1., 1.), 0.7 * bdLen * (1. - 0.07 * w * w), bdLen);
  if (d < dHit) {
    dHit = d;  idObj = idBody;  qHit = q;
  }
  q = p - bdLen * vec3 (0., -0.8, 0.);
  vec3 qo = q;
  q.xz = abs (q.xz) - bdLen * vec2 (0.5, 0.9);
  q.xz += q.y * vec2 (0.1, 0.3);
  h = 0.6 * bdLen;
  w = q.y / h;
  d = PrCapsDf (q.xzy, 0.15 * bdLen * (1. - 0.3 * w * w), h);
  if (d < dHit + 0.2) {
    dHit = SmoothMin (dHit, d, 0.2);  idObj = idLegs;  qHit = q * sign (qo.zyx);
  }
  q = p - bdLen * vec3 (0., 0., -1.;
  w = q.z / bdLen;
  if (isLive) q.y += bdLen * (w * (1.1 - 0.3 * w) - 1.1);
  h = 0.7 * bdLen;
  if (isLive) a = 0.8 * sin (0.7 * 2. * pi * tCur);
  else a = 0.;
  ca = cos (a);
  sa = sin (a);
  tailMat = mat3 (ca, 0., - sa, 0., 1., 0., sa, 0., ca);
  q.z -= h;
  q = tailMat * q;
  q.z += h;
  d = PrCapsDf (q, 0.12 * bdLen * (1. - 0.1 * w), h);
  if (d < dHit + 0.2) {
    dHit = SmoothMin (dHit, d, 0.2);  idObj = idTail;  qHit = q;
  }
  return dHit;
}

float CatHeadDf (vec3 p, float dHit)
{
  vec3 q, qh;
  float r, h, d, w, rw, a, ca, sa;
  qh = p - bdLen * vec3 (0., 0.9, 1.5);
  if (isLive) a = 0.8 * sin (0.7 * 2. * pi * tCur);
  else a = 0.;
  ca = cos (a);
  sa = sin (a);
  headMat = mat3 (ca, 0., - sa, 0., 1., 0., sa, 0., ca);
  qh = headMat * qh;
  q = qh;
  q.y += 0.4 * q.z;
  d = PrCapsDf (q * vec3 (1., 1.2, 1.), 0.65 * bdLen, 0.05 * bdLen);
  d = max (d, - PrCylDf (q * vec3 (1., 2., 1.) - bdLen * vec3 (0., -0.42, 0.7),
     0.15 * bdLen, 0.2 * bdLen));
  if (d < dHit + 0.1) {
    dHit = SmoothMin (dHit, d, 0.1);  idObj = idHead;  qHit = q;
  }
  q.y += 0.22 * bdLen;
  if (isLive) a = 0.15 * sin (0.9 * 2. * pi * tCur);
  else a = -0.15;
  q.z -= bdLen * (0.5 + a);
  d = PrCapsDf (q * vec3 (1., 2., 1.), 0.12 * bdLen, 0.17 * bdLen);
  if (d < dHit) {
    dHit = d;  idObj = idTongue;  qHit = q;
  }
  vec3 qe = qh - bdLen * vec3 (0., 0.75, -0.1);
  vec3 qo = qe;
  qe.x = abs (q.x) - 0.4 * bdLen;
  r = 0.3 * bdLen;
  w = qe.x / r;
  rw = r * (1. - 0.5 * w * w);
  q = qe;
  q.z -= 0.5 * q.x;
  float d1 = max (PrCylDf (q.yxz, rw, 0.03 * bdLen), - q.x);
  q = qe;
  q.z += 0.1 * q.x;
  float d2 = max (PrCylDf (q.yxz, rw, 0.03 * bdLen), q.x);
  d = min (d1, d2);
  if (d < dHit + 0.1) {
    dHit = SmoothMin (dHit, d, 0.1);  idObj = idEars;  qHit = q * sign (qo.zyx);
  }
  q = qh - bdLen * vec3 (0., 0., 0.37);
  q.x = abs (q.x) - 0.3 * bdLen;
  d = PrSphDf (q * vec3 (1., 1.5, 1.), 0.2 * bdLen);
  if (d < dHit) {
    dHit = d;  idObj = idEyes;  qHit = q;
  }
  q = qh - bdLen * vec3 (0., -0.2, 0.65);
  q.z += 0.5 * q.y;
  d = PrCapsDf (q, 0.1 * bdLen, 0.03 * bdLen);
  if (d < dHit + 0.05) {
    dHit = SmoothMin (dHit, d, 0.05);  idObj = idNose;  qHit = q;
  }
  q = qh - bdLen * vec3 (0., -0.3, 0.65);
  q.xy = abs (q.xy) - bdLen * vec2 (0.1, -0.005);
  q.yz += 0.1 * q.x * vec2 (-1., 1.);
  d = PrCylDf (q.zyx, 0.01 * bdLen, 0.6 * bdLen);
  if (d < dHit) {
    dHit = d;  idObj = idWhisk;  qHit = q;
  }
  return dHit;
}

float CatDf (vec3 p, float dHit)
{
  vec3 q = p;
  if (! isLive) {
    q.x -= 1.05 * bdLen;
    q *= vec3 (1.5, 1., 1.);
  }
  dHit = CatBodyDf (q, dHit);
  dHit = CatHeadDf (q, dHit);
  return 0.5 * dHit;
}

vec3 FurCol (vec3 p, vec3 n)
{
  const vec3 c1 = vec3 (0.7, 0.6, 0.), c2 = vec3 (0.1), c3 = vec3 (0.9);
  p *= 2.5;
  float s = Fbmn (p, n);
  return mix (mix (c1, c2, smoothstep (0.8, 1.2, s)), c3,
     smoothstep (1.4, 1.7, s));
}

vec4 CatCol (vec3 n)
{
  vec3 col = vec3 (0.);
  float spec = 1.;
  const vec3 wCol = vec3 (0.9);
  vec3 q = 2. * qHit / bdLen;
  if (idObj >= idBody && idObj <= idEars) {
    if (idObj == idLegs || idObj == idHead) q *= 1.5;
    else if (idObj == idTail || idObj == idEars) q *= 2.;
    if (idObj == idTail) n = tailMat * n;
    else if (idObj == idHead || idObj == idEars) n = headMat * n;
    if (idObj == idEars && n.z > 0.4) col = vec3 (0.8, 0.6, 0.6);
    else {
      vec3 anis = vec3 (1.);
      if (idObj == idBody) anis = vec3 (1., 0.7, 1.);
      else if (idObj == idHead) anis = vec3 (1., 1., 1.3);
      col = FurCol (q * anis, n);
    }
    qHit /= bdLen;
    if (idObj == idBody) col = mix (mix (wCol, col,
       smoothstep (-0.65, -0.35, qHit.y)),
       wCol, (1. - smoothstep (-1.15, -0.95, qHit.z)) *
       smoothstep (0.3, 0.5, qHit.y));
    else if (idObj == idHead)
       col = mix (col, wCol, smoothstep (0.25, 0.45, qHit.z));
    else if (idObj == idTail)
      col = mix (col, wCol, smoothstep (0.25, 0.45, qHit.z));
    spec = 0.1;
  } else if (idObj == idTongue) {
    col = vec3 (0.9, 0.4, 0.4);
  } else if (idObj == idEyes) {
    n = headMat * n;
    col = vec3 (0., 0.7, 0.2);
    if (length (qHit - bdLen * vec3 (0.16, 0.12, 0.3)) < 0.4) {
      col = vec3 (0.4, 0., 0.);
      spec = 5.;
    }
  } else if (idObj == idNose) {
    col = vec3 (0.3, 0.2, 0.1);
  } else if (idObj == idWhisk) {
    col = vec3 (0.9, 0.7, 0.);
    spec = 5.;
  }
  if (! isLive && idObj != idTongue)
     col = HsvToRgb (RgbToHsv (col) * vec3 (1., 0.3, 0.);
  return vec4 (col, spec);
}

float BoxDf (vec3 p, float dHit)
{
  vec3 q, qb, qh;
  float d;
  float bb = 4. * boxSize;
  float bh = 2.5 * boxSize;
  float bt = 0.08 * boxSize;
  q = p - vec3 (0., -0.5 * bt, 0.);
  d = PrBoxDf (q, vec3 (bb - bt, bt, bb - bt));
  if (d < dHit) {
    dHit = d;  idObj = idFloor;  qHit = q;
  }
  qb = q;
  int nx = 0;
  if (qb.x < 0.) nx = 1;
  qb.x = abs (qb.x) - 0.5 * bb;
  qh = qb;
  float a = 0.;
  if (tSeq > 1. && tSeq < 2.) a = - pi * (tSeq - 1.);
  else if (tSeq > 8. && tSeq < 9.) a = - pi * (9. - tSeq);
  else if (tSeq >= 2. && tSeq <= 8.) a = - pi;
  float ca = cos (a);
  float sa = sin (a);
  boxMat = mat3 (ca, - sa, 0., sa, ca, 0., 0., 0., 1.);
  boxMatR = mat3 (ca, sa, 0., - sa, ca, 0., 0., 0., 1.);
  qb.x -= 0.5 * bb;
  qb = boxMat * qb;
  qb.x += 0.5 * bb;
  q = qb - vec3 (0.5 * bb, bh - bt, 0.);
  d = PrBoxDf (q, vec3 (bt, bh, bb - bt));
  if (d < dHit) {
    dHit = d;  idObj = idWall + nx;  qHit = q;
  }
  q = qb - vec3 (0., bh - bt, 0.);
  q.z = abs (q.z) - bb;
  d = PrBoxDf (q, vec3 (0.5 * bb + bt, bh, bt));
  if (d < dHit) {
    dHit = d;  idObj = idWall;  qHit = q;
  }
  q = qb - vec3 (0., 2. * bh - 0.5 * bt, 0.);
  d = PrBoxDf (q, vec3 (0.5 * bb + bt, bt, bb + bt));
  if (d < dHit) {
    dHit = d;  idObj = idWall;  qHit = q;
  }

  q = qb - vec3 (-0.1 * bb, bt + 2. * bh - 0.5 * bt, 0.);
  d = PrTorus88Df (q.yzx, 1.5 * bt, 0.2 * bb);
  d = max (d, - q.y);
  if (d < dHit) {
    dHit = d;  idObj = idWall;  qHit = q;
  }
  q = qh - vec3 (0.5 * bb, 0., 0.);
  q.z = abs (q.z) - 0.5 * bb;
  d = PrCylDf (q.yxz, 1.8 * bt, 0.25 * bb);
  if (d < dHit) {
    dHit = d;  idObj = idHinge;  qHit = q;
  }
  return dHit;
}

vec3 WoodCol (vec3 p, vec3 n)
{
  p *= 4.;
  float f = dot (vec3 (Fbm2 (p.yz * vec2 (1., 0.1)),
     Fbm2 (p.zx * vec2 (1., 0.1)), Fbm2 (p.yx * vec2 (1., 0.1))), abs (n));
  return 2. * mix (vec3 (0.8, 0.4, 0.2), vec3 (0.45, 0.25, 0.1), f);
}

vec4 BoxCol (vec3 n)
{
  vec3 col = vec3 (0.);
  float spec = 1.;
  if (idObj == idFloor) {
    col = WoodCol (qHit, n);
  } else if (idObj == idWall) {
    col = WoodCol (qHit, boxMat * n);
  } else if (idObj == idWallR) {
    col = WoodCol (qHit, boxMatR * n);
  } else if (idObj == idHinge) {
    col = vec3 (0.7, 0.5, 0.1);
    spec = 10.;
  }
  return vec4 (col, spec);
}

float JarDf (vec3 p, float dHit)
{
  vec3 q;
  float d;
  q = p - boxSize * vec3 (-3., 0.5, 3.);
  d = PrCylDf (q.xzy, 0.5 * boxSize, 0.5 * boxSize);
  if (d < dHit) {
    dHit = d;  idObj = idJar;  qHit = q;
  }
  return dHit;
}

vec4 JarCol (vec3 n)
{
  vec3 col;
  float spec = 1.;
  vec3 q = qHit;
  if (n.y < 0.95) {
    float a = abs (atan (qHit.x, qHit.z));
    a = min (a, abs (pi - a));
    col = vec3 (1., 1., 0.) *
       (1. - SmoothBump (-0.25, 0.25, 0.03, a - 1.3 * abs (qHit.y))) *
       (1. - SmoothBump (-0.1, 0.25, 0.03, Length4 (vec2 (a, qHit.y -
       0.3 * boxSize))));
  } else {
    if (isLive) col = vec3 (0., 1., 0.);
    else col = vec3 (1., 0., 0.);
    col *= 0.6 * (1. + cos (3. * 2. * pi * tSeq));
  }
  return vec4 (col, spec);
}

float ObjDf (vec3 p)
{
  float dHit = dstFar;
  dHit = CatDf (bodyMat * (p - catPos), dHit);
  dHit = BoxDf (p, dHit);
  dHit = JarDf (p, dHit);
  return dHit;
}

float ObjRay (vec3 ro, vec3 rd)
{
  const float dTol = 0.001;
  float d;
  float dHit = 0.;
  for (int j = 0; j < 150; j ++) {
    d = ObjDf (ro + dHit * rd);
    dHit += d;
    if (d < dTol || dHit > dstFar) break;
  }
  return dHit;
}

vec3 ObjNf (vec3 p)
{
  const vec3 e = vec3 (0.001, -0.001, 0.);
  float v0 = ObjDf (p + e.xxx);
  float v1 = ObjDf (p + e.xyy);
  float v2 = ObjDf (p + e.yxy);
  float v3 = ObjDf (p + e.yyx);
  return normalize (vec3 (v0 - v1 - v2 - v3) + 2. * vec3 (v1, v2, v3));
}

float ObjSShadow (vec3 ro, vec3 rd)
{
  float sh = 1.;
  float d = 0.1;
  for (int i = 0; i < 100; i++) {
    float h = ObjDf (ro + rd * d);
    sh = min (sh, 20. * h / d);
    d += 0.1;
    if (h < 0.001) break;
  }
  return clamp (sh, 0., 1.);
}

vec4 ObjCol (vec3 n)
{
  vec4 col4 = vec4 (0.);
  if (idObj >= idBody && idObj <= idWhisk) col4 = CatCol (bodyMat * n);
  else if (idObj >= idFloor && idObj <= idHinge) col4 = BoxCol (n);
  else if (idObj == idJar) col4 = JarCol (n);
  return col4;
}

void CatPM (float t)
{
  float frq = 0.44;
  float rl = 0.;
  float az = 0.;
  float el = 0.;
  if (isLive) {
    catPos = vec3 (0., bdLen * (1.94 + 0.4 * sin (2. * pi * frq * tCur)), 0.);
    az += 0.7 * sin (pi * frq * tCur);
    el -= 0.4 * (1. + sin (2. * pi * frq * tCur));
  } else {
    float ps = 2. * mod (nSeq, 2.) - 1.;
    catPos = vec3 (0., bdLen * (0.45 + 1.05 * ps), 0.);
    rl -= 0.5 * pi * ps;
  }
  vec3 ca = cos (vec3 (el, az, rl));
  vec3 sa = sin (vec3 (el, az, rl));
  bodyMat = mat3 (ca.z, - sa.z, 0., sa.z, ca.z, 0., 0., 0., 1.) *
     mat3 (1., 0., 0., 0., ca.x, - sa.x, 0., sa.x, ca.x) *
     mat3 (ca.y, 0., - sa.y, 0., 1., 0., sa.y, 0., ca.y);
}

vec3 ShowScene (vec3 ro, vec3 rd)
{
  vec3 vn, objCol;
  float dstHit;
  vec3 col = vec3 (0., 0., 0.02);
  idObj = -1;
  dstHit = ObjRay (ro, rd);
  int idObjT = idObj;
  if (idObj < 0) dstHit = dstFar;
  if (dstHit < dstFar) {
    ro += rd * dstHit;
    vn = ObjNf (ro);
    idObj = idObjT;
    if (idObj >= idBody && idObj <= idTongue) vn = VaryNf (20. * qHit, vn, 0.4);
    vec4 col4 = ObjCol (vn);
    objCol = col4.xyz;
    float spec = col4.w;
    float dif = max (dot (vn, ltDir), 0.);
    vec3 vl = 30. * ltDir - ro;
    float di = 1. / length (vl);
    float br = min (1.1, 40. * di);
    float f = dot (ltDir, vl) * di;
    col = (0.1 + pow (f, 16.)) * br * objCol * (0.2 * (1. +
       max (dot (vn, - normalize (vec3 (ltDir.x, 0., ltDir.z))), 0.)) +
       max (0., dif) * ObjSShadow (ro, ltDir) *
       (dif + spec * pow (max (0., dot (ltDir, reflect (rd, vn))), 64.)));
  }
  col = sqrt (clamp (col, 0., 1.));
  return col;
}

void main()
{
  vec2 uv = 2. * gl_FragCoord.xy / iResolution.xy - 1.;
  uv.x *= iResolution.x / iResolution.y;
  float zmFac = 4.8;
  tCur = iGlobalTime;
  tCur = max (tCur - 2., 0.);
  const float tPer = 10.;
  nSeq = floor (tCur / tPer);
  float tBase = tPer * nSeq;
  tSeq = tCur - tBase;
  isLive = (sin (tBase) + sin (1.7 * tBase) + sin (2.7 * tBase)) > -0.5;
  boxSize = 2.;
  bdLen = boxSize;
  if (! isLive) {
    float s = tSeq / tPer;
    bdLen *= 1. - 0.95 * s * s * s;
  }
  float dist = 50.;
  float el = 0.4 + 0.2 * sin (0.042 * tCur);
  float az = pi + 0.6 * sin (0.093 * tCur);
  float cEl = cos (el);
  float sEl = sin (el);
  float cAz = cos (az);
  float sAz = sin (az);
  mat3 vuMat = mat3 (1., 0., 0., 0., cEl, - sEl, 0., sEl, cEl) *
     mat3 (cAz, 0., sAz, 0., 1., 0., - sAz, 0., cAz);
  vec3 rd = normalize (vec3 (uv, zmFac)) * vuMat;
  vec3 ro = - vec3 (0., 0., dist) * vuMat;
  ro.y += 0.08 * dist;
  ltDir = normalize (vec3 (0.5, 1., -1.));
  ltDir *= vuMat;
  CatPM (tCur);
  vec3 col = ShowScene (ro, rd);
  gl_FragColor = vec4 (col, 1.);
}


//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

-- tex0 = moon3d.image.load2d("./data/tex16.png")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Schrödinger's cat", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


55
English forum / Raymarching primitives converted
« on: June 06, 2015, 12:53:05 PM »
Raymarching primitives converted to GLSL Hacker format

Copy the code and save as Raymarching_primitives_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Raymarching primitives"
          width="800" height="400"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/Xds3zN

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
//uniform sampler2D iChannel0;



//

// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// A list of usefull distance function to simple primitives, and an example on how to
// do some interesting boolean operations, repetition and displacement.
//
// More info here: http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm

float sdPlane( vec3 p )
{
    return p.y;
}

float sdSphere( vec3 p, float s )
{
    return length(p)-s;
}

float sdBox( vec3 p, vec3 b )
{
  vec3 d = abs(p) - b;
  return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}

float udRoundBox( vec3 p, vec3 b, float r )
{
  return length(max(abs(p)-b,0.0))-r;
}

float sdTorus( vec3 p, vec2 t )
{
  return length( vec2(length(p.xz)-t.x,p.y) )-t.y;
}

float sdHexPrism( vec3 p, vec2 h )
{
    vec3 q = abs(p);
#if 0
    return max(q.z-h.y,max((q.x*0.866025+q.y*0.5),q.y)-h.x);
#else
    float d1 = q.z-h.y;
    float d2 = max((q.x*0.866025+q.y*0.5),q.y)-h.x;
    return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
#endif
}

float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
    vec3 pa = p-a, ba = b-a;
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
    return length( pa - ba*h ) - r;
}

float sdTriPrism( vec3 p, vec2 h )
{
    vec3 q = abs(p);
#if 0
    return max(q.z-h.y,max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5);
#else
    float d1 = q.z-h.y;
    float d2 = max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5;
    return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
#endif
}

float sdCylinder( vec3 p, vec2 h )
{
  vec2 d = abs(vec2(length(p.xz),p.y)) - h;
  return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}


float sdCone( in vec3 p, in vec3 c )
{
    vec2 q = vec2( length(p.xz), p.y );
#if 0
    return max( max( dot(q,c.xy), p.y), -p.y-c.z );
#else
    float d1 = -p.y-c.z;
    float d2 = max( dot(q,c.xy), p.y);
    return length(max(vec2(d1,d2),0.0)) + min(max(d1,d2), 0.);
#endif   
}

float length2( vec2 p )
{
    return sqrt( p.x*p.x + p.y*p.y );
}

float length6( vec2 p )
{
    p = p*p*p; p = p*p;
    return pow( p.x + p.y, 1.0/6.0 );
}

float length8( vec2 p )
{
    p = p*p; p = p*p; p = p*p;
    return pow( p.x + p.y, 1.0/8.0 );
}

float sdTorus82( vec3 p, vec2 t )
{
  vec2 q = vec2(length2(p.xz)-t.x,p.y);
  return length8(q)-t.y;
}

float sdTorus88( vec3 p, vec2 t )
{
  vec2 q = vec2(length8(p.xz)-t.x,p.y);
  return length8(q)-t.y;
}

float sdCylinder6( vec3 p, vec2 h )
{
  return max( length6(p.xz)-h.x, abs(p.y)-h.y );
}

//----------------------------------------------------------------------

float opS( float d1, float d2 )
{
    return max(-d2,d1);
}

vec2 opU( vec2 d1, vec2 d2 )
{
    return (d1.x<d2.x) ? d1 : d2;
}

vec3 opRep( vec3 p, vec3 c )
{
    return mod(p,c)-0.5*c;
}

vec3 opTwist( vec3 p )
{
    float  c = cos(10.0*p.y+10.0);
    float  s = sin(10.0*p.y+10.0);
    mat2   m = mat2(c,-s,s,c);
    return vec3(m*p.xz,p.y);
}

//----------------------------------------------------------------------

vec2 map( in vec3 pos )
{
    vec2 res = opU( vec2( sdPlane(     pos), 1.0 ),
                    vec2( sdSphere(    pos-vec3( 0.0,0.25, 0.0), 0.25 ), 46.9 ) );
    res = opU( res, vec2( sdBox(       pos-vec3( 1.0,0.25, 0.0), vec3(0.25) ), 3.0 ) );
    res = opU( res, vec2( udRoundBox(  pos-vec3( 1.0,0.25, 1.0), vec3(0.15), 0.1 ), 41.0 ) );
    res = opU( res, vec2( sdTorus(     pos-vec3( 0.0,0.25, 1.0), vec2(0.20,0.05) ), 25.0 ) );
    res = opU( res, vec2( sdCapsule(   pos,vec3(-1.3,0.20,-0.1), vec3(-1.0,0.20,0.2), 0.1  ), 31.9 ) );
    res = opU( res, vec2( sdTriPrism(  pos-vec3(-1.0,0.25,-1.0), vec2(0.25,0.05) ),43.5 ) );
    res = opU( res, vec2( sdCylinder(  pos-vec3( 1.0,0.30,-1.0), vec2(0.1,0.2) ), 8.0 ) );
    res = opU( res, vec2( sdCone(      pos-vec3( 0.0,0.50,-1.0), vec3(0.8,0.6,0.3) ), 55.0 ) );
    res = opU( res, vec2( sdTorus82(   pos-vec3( 0.0,0.25, 2.0), vec2(0.20,0.05) ),50.0 ) );
    res = opU( res, vec2( sdTorus88(   pos-vec3(-1.0,0.25, 2.0), vec2(0.20,0.05) ),43.0 ) );
    res = opU( res, vec2( sdCylinder6( pos-vec3( 1.0,0.30, 2.0), vec2(0.1,0.2) ), 12.0 ) );
    res = opU( res, vec2( sdHexPrism(  pos-vec3(-1.0,0.20, 1.0), vec2(0.25,0.05) ),17.0 ) );

    res = opU( res, vec2( opS(
                     udRoundBox(  pos-vec3(-2.0,0.2, 1.0), vec3(0.15),0.05),
                     sdSphere(    pos-vec3(-2.0,0.2, 1.0), 0.25)), 13.0 ) );
    res = opU( res, vec2( opS(
                     sdTorus82(  pos-vec3(-2.0,0.2, 0.0), vec2(0.20,0.1)),
                     sdCylinder(  opRep( vec3(atan(pos.x+2.0,pos.z)/6.2831,
                                              pos.y,
                                              0.02+0.5*length(pos-vec3(-2.0,0.2, 0.0))),
                                         vec3(0.05,1.0,0.05)), vec2(0.02,0.6))), 51.0 ) );
    res = opU( res, vec2( 0.7*sdSphere(    pos-vec3(-2.0,0.25,-1.0), 0.2 ) +
                                       0.03*sin(50.0*pos.x)*sin(50.0*pos.y)*sin(50.0*pos.z),
                                       65.0 ) );
    res = opU( res, vec2( 0.5*sdTorus( opTwist(pos-vec3(-2.0,0.25, 2.0)),vec2(0.20,0.05)), 46.7 ) );

    return res;
}

vec2 castRay( in vec3 ro, in vec3 rd )
{
    float tmin = 1.0;
    float tmax = 20.0;
   
#if 0
    float tp1 = (0.0-ro.y)/rd.y; if( tp1>0.0 ) tmax = min( tmax, tp1 );
    float tp2 = (1.6-ro.y)/rd.y; if( tp2>0.0 ) { if( ro.y>1.6 ) tmin = max( tmin, tp2 );
                                                 else           tmax = min( tmax, tp2 ); }
#endif
   
    float precis = 0.002;
    float t = tmin;
    float m = -1.0;
    for( int i=0; i<50; i++ )
    {
        vec2 res = map( ro+rd*t );
        if( res.x<precis || t>tmax ) break;
        t += res.x;
        m = res.y;
    }

    if( t>tmax ) m=-1.0;
    return vec2( t, m );
}


float softshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
{
    float res = 1.0;
    float t = mint;
    for( int i=0; i<16; i++ )
    {
        float h = map( ro + rd*t ).x;
        res = min( res, 8.0*h/t );
        t += clamp( h, 0.02, 0.10 );
        if( h<0.001 || t>tmax ) break;
    }
    return clamp( res, 0.0, 1.0 );

}

vec3 calcNormal( in vec3 pos )
{
    vec3 eps = vec3( 0.001, 0.0, 0.0 );
    vec3 nor = vec3(
        map(pos+eps.xyy).x - map(pos-eps.xyy).x,
        map(pos+eps.yxy).x - map(pos-eps.yxy).x,
        map(pos+eps.yyx).x - map(pos-eps.yyx).x );
    return normalize(nor);
}

float calcAO( in vec3 pos, in vec3 nor )
{
    float occ = 0.0;
    float sca = 1.0;
    for( int i=0; i<5; i++ )
    {
        float hr = 0.01 + 0.12*float(i)/4.0;
        vec3 aopos =  nor * hr + pos;
        float dd = map( aopos ).x;
        occ += -(dd-hr)*sca;
        sca *= 0.95;
    }
    return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );   
}




vec3 render( in vec3 ro, in vec3 rd )
{
    vec3 col = vec3(0.8, 0.9, 1.0);
    vec2 res = castRay(ro,rd);
    float t = res.x;
    float m = res.y;
    if( m>-0.5 )
    {
        vec3 pos = ro + t*rd;
        vec3 nor = calcNormal( pos );
        vec3 ref = reflect( rd, nor );
       
        // material       
        col = 0.45 + 0.3*sin( vec3(0.05,0.08,0.10)*(m-1.0) );
       
        if( m<1.5 )
        {
           
            float f = mod( floor(5.0*pos.z) + floor(5.0*pos.x), 2.0);
            col = 0.4 + 0.1*f*vec3(1.0);
        }

        // lighting       
        float occ = calcAO( pos, nor );
        vec3  lig = normalize( vec3(-0.6, 0.7, -0.5) );
        float amb = clamp( 0.5+0.5*nor.y, 0.0, 1.0 );
        float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
        float bac = clamp( dot( nor, normalize(vec3(-lig.x,0.0,-lig.z))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0);
        float dom = smoothstep( -0.1, 0.1, ref.y );
        float fre = pow( clamp(1.0+dot(nor,rd),0.0,1.0), 2.0 );
        float spe = pow(clamp( dot( ref, lig ), 0.0, 1.0 ),16.0);
       
        dif *= softshadow( pos, lig, 0.02, 2.5 );
        dom *= softshadow( pos, ref, 0.02, 2.5 );

        vec3 brdf = vec3(0.0);
        brdf += 1.20*dif*vec3(1.00,0.90,0.60);
        brdf += 1.20*spe*vec3(1.00,0.90,0.60)*dif;
        brdf += 0.30*amb*vec3(0.50,0.70,1.00)*occ;
        brdf += 0.40*dom*vec3(0.50,0.70,1.00)*occ;
        brdf += 0.30*bac*vec3(0.25,0.25,0.25)*occ;
        brdf += 0.40*fre*vec3(1.00,1.00,1.00)*occ;
        brdf += 0.02;
        col = col*brdf;

        col = mix( col, vec3(0.8,0.9,1.0), 1.0-exp( -0.0005*t*t ) );

    }

    return vec3( clamp(col,0.0,1.0) );
}

mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
{
    vec3 cw = normalize(ta-ro);
    vec3 cp = vec3(sin(cr), cos(cr),0.0);
    vec3 cu = normalize( cross(cw,cp) );
    vec3 cv = normalize( cross(cu,cw) );
    return mat3( cu, cv, cw );
}

void main()
{
    vec2 q = gl_FragCoord.xy/iResolution.xy;
    vec2 p = -1.0+2.0*q;
    p.x *= iResolution.x/iResolution.y;
    vec2 mo = iMouse.xy/iResolution.xy;
         
    float time = 15.0 + iGlobalTime;

    // camera   
    vec3 ro = vec3( -0.5+3.2*cos(0.1*time + 6.0*mo.x), 1.0 + 2.0*mo.y, 0.5 + 3.2*sin(0.1*time + 6.0*mo.x) );
    vec3 ta = vec3( -0.5, -0.4, 0.5 );
   
    // camera-to-world transformation
    mat3 ca = setCamera( ro, ta, 0.0 );
   
    // ray direction
    vec3 rd = ca * normalize( vec3(p.xy,2.5) );

    // render   
    vec3 col = render( ro, rd );

    col = pow( col, vec3(0.4545) );

    gl_FragColor=vec4( col, 1.0 );
}

//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

-- tex0 = moon3d.image.load2d("./data/tex16.png")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Raymarching primitives", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


56
English forum / Pyroclastic explosion converted
« on: June 06, 2015, 12:49:09 PM »
Pyroclastic explosion converted to GLSL Hacker format

Copy the code and save as Pyroclastic_explosion_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/pyroclastic explosion"
          width="800" height="800"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/XdfGz8

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
//uniform sampler2D iChannel0;



//

// volume explosion shader
// simon green / nvidia 2012
// http://developer.download.nvidia.com/assets/gamedev/files/gdc12/GDC2012_Mastering_DirectX11_with_Unity.pdf

// sorry, port from HLSL!
#define float3 vec3
#define float4 vec4

// parameters
// be nice if we had sliders for these!
const int _MaxSteps = 64;
const float _StepDistanceScale = 0.5;
const float _MinStep = 0.001;
const float _DistThreshold = 0.005;

const int _VolumeSteps = 32;
const float _StepSize = 0.02;
const float _Density = 0.1;

const float _SphereRadius = 0.5;
const float _NoiseFreq = 4.0;
const float _NoiseAmp = -0.5;
const float3 _NoiseAnim = float3(0, -1, 0);

// iq's nice integer-less noise function

// matrix to rotate the noise octaves
mat3 m = mat3( 0.00,  0.80,  0.60,
              -0.80,  0.36, -0.48,
              -0.60, -0.48,  0.64 );

float hash( float n )
{
    return fract(sin(n)*43758.5453);
}


float noise( in vec3 x )
{
    vec3 p = floor(x);
    vec3 f = fract(x);

    f = f*f*(3.0-2.0*f);

    float n = p.x + p.y*57.0 + 113.0*p.z;

    float res = mix(mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
                        mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
                    mix(mix( hash(n+113.0), hash(n+114.0),f.x),
                        mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
    return res;
}

float fbm( vec3 p )
{
    float f;
    f = 0.5000*noise( p ); p = m*p*2.02;
    f += 0.2500*noise( p ); p = m*p*2.03;
    f += 0.1250*noise( p ); p = m*p*2.01;
    f += 0.0625*noise( p );
    p = m*p*2.02; f += 0.03125*abs(noise( p ));   
    return f/0.9375;
}


// distance field stuff
float sphereDist(float3 p, float4 sphere)
{
    return length(p - sphere.xyz) - sphere.w;
}

// returns signed distance to nearest surface
// displace is displacement from original surface (0, 1)
float distanceFunc(float3 p, out float displace)
{   
    //float d = length(p) - _SphereRadius;    // distance to sphere
    float d = length(p) - (sin(iGlobalTime*0.25)+0.5);    // animated radius
   
    // offset distance with pyroclastic noise
    //p = normalize(p) * _SphereRadius;    // project noise point to sphere surface
    displace = fbm(p*_NoiseFreq + _NoiseAnim*iGlobalTime);
    d += displace * _NoiseAmp;
   
    return d;
}

// calculate normal from distance field
float3 dfNormal(float3 pos)
{
    float eps = 0.001;
    float3 n;
    float s;
#if 0
    // central difference
    n.x = distanceFunc( float3(pos.x+eps, pos.y, pos.z), s ) - distanceFunc( float3(pos.x-eps, pos.y, pos.z), s );
    n.y = distanceFunc( float3(pos.x, pos.y+eps, pos.z), s ) - distanceFunc( float3(pos.x, pos.y-eps, pos.z), s );
    n.z = distanceFunc( float3(pos.x, pos.y, pos.z+eps), s ) - distanceFunc( float3(pos.x, pos.y, pos.z-eps), s );
#else
    // forward difference (faster)
    float d = distanceFunc(pos, s);
    n.x = distanceFunc( float3(pos.x+eps, pos.y, pos.z), s ) - d;
    n.y = distanceFunc( float3(pos.x, pos.y+eps, pos.z), s ) - d;
    n.z = distanceFunc( float3(pos.x, pos.y, pos.z+eps), s ) - d;
#endif

    return normalize(n);
}

// color gradient
// this should be in a 1D texture really
float4 gradient(float x)
{
    const float4 c0 = float4(4, 4, 4, 1);    // hot white
    const float4 c1 = float4(1, 1, 0, 1);    // yellow
    const float4 c2 = float4(1, 0, 0, 1);    // red
    const float4 c3 = float4(0.4, 0.4, 0.4, 4);    // grey
   
    float t = fract(x*3.0);
    float4 c;
    if (x < 0.3333) {
        c =  mix(c0, c1, t);
    } else if (x < 0.6666) {
        c = mix(c1, c2, t);
    } else {
        c = mix(c2, c3, t);
    }
    //return float4(x);
    //return float4(t);
    return c;
}

// shade a point based on position and displacement from surface
float4 shade(float3 p, float displace)
{   
    // lookup in color gradient
    displace = displace*1.5 - 0.2;
    displace = clamp(displace, 0.0, 0.99);
    float4 c = gradient(displace);
    //c.a *= smoothstep(1.0, 0.8, length(p));
   
    // lighting
    float3 n = dfNormal(p);
    float diffuse = n.z*0.5+0.5;
    //float diffuse = max(0.0, n.z);
    c.rgb = mix(c.rgb, c.rgb*diffuse, clamp((displace-0.5)*2.0, 0.0, 1.0));
   
    //return float4(float3(displace), 1);
    //return float4(dfNormal(p)*float3(0.5)+float3(0.5), 1);
    //return float4(diffuse);
    //return gradient(displace);
    return c;
}

// procedural volume
// maps position to color
float4 volumeFunc(float3 p)
{
    float displace;
    float d = distanceFunc(p, displace);
    float4 c = shade(p, displace);
    return c;
}

// sphere trace
// returns hit position
float3 sphereTrace(float3 rayOrigin, float3 rayDir, out bool hit, out float displace)
{
    float3 pos = rayOrigin;
    hit = false;
    displace = 0.0;   
    float d;
    //float3 hitPos;
    float disp;
    for(int i=0; i<_MaxSteps; i++) {
        d = distanceFunc(pos, disp);
            if (d < _DistThreshold) {
            hit = true;
            displace = disp;
            //hitPos = pos;
                //break;    // early exit from loop doesn't work in ES?
            }
        //d = max(d, _MinStep);
        pos += rayDir*d*_StepDistanceScale;
    }
   
    return pos;
    //return hitPos;
}


// ray march volume from front to back
// returns color
float4 rayMarch(float3 rayOrigin, float3 rayStep, out float3 pos)
{
    float4 sum = float4(0, 0, 0, 0);
    pos = rayOrigin;
    for(int i=0; i<_VolumeSteps; i++) {
        float4 col = volumeFunc(pos);
        col.a *= _Density;
        col.a = min(col.a, 1.0);
       
        // pre-multiply alpha
        col.rgb *= col.a;
        sum = sum + col*(1.0 - sum.a);   
#if 0
        // exit early if opaque
            if (sum.a > _OpacityThreshold)
                    break;
#endif       
        pos += rayStep;
    }
    return sum;
}

void main()
{
    vec2 q = gl_FragCoord.xy / iResolution.xy;
    vec2 p = q*2.0-1.0;
    p.x *= iResolution.x / iResolution.y;
   
    float rotx = (iMouse.y / iResolution.y)*4.0;
    float roty = 0.2*iGlobalTime - (iMouse.x / iResolution.x)*4.0;
   
    // camera
    vec3 ro = 2.0*normalize(vec3(cos(roty), cos(rotx), sin(roty)));
    vec3 ww = normalize(vec3(0.0,0.0,0.0) - ro);
    vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww ));
    vec3 vv = normalize(cross(ww,uu));
    vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww );

    // sphere trace distance field
    bool hit;
    float displace;
    vec3 hitPos = sphereTrace(ro, rd, hit, displace);

    vec4 col = vec4(0, 0, 0, 1);
    if (hit) {
        // shade
           col = shade(hitPos, displace);    // opaque version
        //col = rayMarch(hitPos, rd*_StepSize, hitPos);    // volume render
    }

    gl_FragColor = col;
}


//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

-- tex0 = moon3d.image.load2d("./data/tex16.png")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
--moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/pyroclastic explosion", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


57
English forum / The Cave converted
« on: June 06, 2015, 12:46:54 PM »
The Cave converted to GLSL Hacker format

Copy the code and save as The_Cave_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/The Cave"
          width="800" height="800"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="shadertoy_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     

// https://www.shadertoy.com/view/MsX3RH

uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;



//

// constants for the camera tunnel
const vec2 cama=vec2(-2.6943,3.0483);
const vec2 camb=vec2(0.2516,0.1749);
const vec2 camc=vec2(-3.7902,2.4478);
const vec2 camd=vec2(0.0865,-0.1664);

const vec2 lighta=vec2(1.4301,4.0985);
const vec2 lightb=vec2(-0.1276,0.2347);
const vec2 lightc=vec2(-2.2655,1.5066);
const vec2 lightd=vec2(-0.1284,0.0731);

// calculates the position of a single tunnel
vec2 Position(float z, vec2 a, vec2 b, vec2 c, vec2 d)
{
    return sin(z*a)*b+cos(z*c)*d;
}

// calculates 3D positon of a tunnel for a given time
vec3 Position3D(float time, vec2 a, vec2 b, vec2 c, vec2 d)
{
    return vec3(Position(time,a,b,c,d),time);
}

// 2d distance field for a slice of a single tunnel
float Distance(vec3 p, vec2 a, vec2 b, vec2 c, vec2 d, vec2 e, float r)
{
    vec2 pos=Position(p.z,a,b,c,d);   
    float radius=max(5.0,r+sin(p.z*e.x)*e.y)/10000.0;
    return radius/dot(p.xy-pos,p.xy-pos);
}

// 2d distance field for a slice of the tunnel network
float Dist2D(vec3 pos)
{
    float d=0.0;
   
    d+=Distance(pos,cama,camb,camc,camd,vec2(2.1913,15.4634),70.0000);
    d+=Distance(pos,lighta,lightb,lightc,lightd,vec2(0.3814,12.7206),17.0590);
    d+=Distance(pos,vec2(2.7377,-1.2462),vec2(-0.1914,-0.2339),vec2(-1.3698,-0.6855),vec2(0.1049,-0.1347),vec2(-1.1157,13.6200),27.3718);
    d+=Distance(pos,vec2(-2.3815,0.2382),vec2(-0.1528,-0.1475),vec2(0.9996,-2.1459),vec2(-0.0566,-0.0854),vec2(0.3287,12.1713),21.8130);
    d+=Distance(pos,vec2(-2.7424,4.8901),vec2(-0.1257,0.2561),vec2(-0.4138,2.6706),vec2(-0.1355,0.1648),vec2(2.8162,14.8847),32.2235);
    d+=Distance(pos,vec2(-2.2158,4.5260),vec2(0.2834,0.2319),vec2(4.2578,-2.5997),vec2(-0.0391,-0.2070),vec2(2.2086,13.0546),30.9920);
    d+=Distance(pos,vec2(0.9824,4.4131),vec2(0.2281,-0.2955),vec2(-0.6033,0.4780),vec2(-0.1544,0.1360),vec2(3.2020,12.2138),29.1169);
    d+=Distance(pos,vec2(1.2733,-2.4752),vec2(-0.2821,-0.1180),vec2(3.4862,-0.7046),vec2(0.0224,0.2024),vec2(-2.2714,9.7317),6.3008);
    d+=Distance(pos,vec2(2.6860,2.3608),vec2(-0.1486,0.2376),vec2(2.0568,1.5440),vec2(0.0367,0.1594),vec2(-2.0396,10.2225),25.5348);
    d+=Distance(pos,vec2(0.5009,0.9612),vec2(0.1818,-0.1669),vec2(0.0698,-2.0880),vec2(0.1424,0.1063),vec2(1.7980,11.2733),35.7880);
   
    return d;
}

vec3 nmap(vec2 t, sampler2D tx, float str)
{
    float d=1.0/1024.0;

    float xy=texture2D(tx,t).x;
    float x2=texture2D(tx,t+vec2(d,0)).x;
    float y2=texture2D(tx,t+vec2(0,d)).x;
   
    float s=(1.0-str)*1.2;
    s*=s;
    s*=s;
   
    return normalize(vec3(x2-xy,y2-xy,s/8.0));///2.0+0.5;
}

void main()
{
    float time=iGlobalTime/3.0+291.0;//+43.63/3.0;

    //calculate camera by looking ahead in the tunnel
   
    vec2 p1=Position(time+0.05,cama,camb,camc,camd); //position ahead
    vec3 Pos=Position3D(time,cama,camb,camc,camd); //current position
    vec3 oPos=Pos;
   
    vec3 CamDir=normalize(vec3(p1.x-Pos.x,-p1.y+Pos.y,0.1));
    vec3 CamRight=normalize(cross(CamDir,vec3(0,1,0)));
    vec3 CamUp=normalize(cross(CamRight,CamDir));   
    mat3 cam=mat3(CamRight,CamUp,CamDir);

    //ray calculation   
    vec2 uv=2.0*gl_FragCoord.xy/iResolution.xy-1.0;
    float aspect=iResolution.x/iResolution.y;
   
    vec3 Dir=normalize(vec3(uv*vec2(aspect,1.0),1.0))*cam;
   
    //raymarching
    float fade=0.0;
   
    const float numit=75.0; //raymarch precision
    const float threshold=1.20; //defines the thickness of tunnels
    const float scale=1.5; //tunnel z depth
   
    vec3 Posm1=Pos;
   
    //calculate first hit
    for (float x=0.0; x<numit; x++)
    {
        if (Dist2D(Pos)<threshold)
        {
            fade=1.0-x/numit;
            break;
        }
        Posm1=Pos;
        Pos+=Dir/numit*scale;//*(1.0+x/numit);
    }

    //track back to get better resolution
    for (int x=0; x<6; x++)
    {
        vec3 p2=(Posm1+Pos)/2.0;
        if (Dist2D(p2)<threshold)
            Pos=p2;
        else
            Posm1=p2;
    }   

    //lighting   
    vec3 n=normalize(vec3(Dist2D(Pos+vec3(0.01,0,0))-Dist2D(Pos+vec3(-0.01,0,0)),
                          Dist2D(Pos+vec3(0,0.01,0))-Dist2D(Pos+vec3(0,-0.01,0)),
                          Dist2D(Pos+vec3(0,0,0.01))-Dist2D(Pos+vec3(0,0,-0.01))));
   
    //triplanar blend vector
    vec3 tpn=normalize(max(vec3(0.0),(abs(n.xyz)-vec3(0.2))*7.0))*0.5;
   
    //position of the light - uncomment the second line to get a more interesting path
    vec3 lp=Position3D(time+0.5,cama,camb,camc,camd); //current light position
    //lp=Position3D(time+0.3,lighta,lightb,lightc,lightd);
   
    vec3 ld=lp-Pos;    //light direction
    float lv=1.0;
   
    const float ShadowIT=15.0; //shadow precision
   
    //shadow calc
    for (float x=1.0; x<ShadowIT; x++)
        if (Dist2D(Pos+ld*(x/ShadowIT))<threshold)
        {
            lv=0.0;
            break;
        }

    vec3 tuv=Pos*vec3(3.0,3.0,1.5);    //texture coordinates
   
    //normal mapping
    float nms=0.19;
    vec3 nmx=nmap(tuv.yz,iChannel0,nms)+nmap(-tuv.yz,iChannel0,nms);
    vec3 nmy=nmap(tuv.xz,iChannel1,nms)+nmap(-tuv.xz,iChannel1,nms);
    vec3 nmz=nmap(tuv.xy,iChannel2,nms)+nmap(-tuv.xy,iChannel2,nms);
   
    vec3 nn=normalize(nmx*tpn.x+nmy*tpn.y+nmz*tpn.z);
   
    float dd;
    //normalmapped version:
    dd=max(0.0,dot(nn,normalize(ld*mat3(vec3(1,0,0),vec3(0,0,1),n))));
    //standard version:
    //dd=max(0.0,dot(n,normalize(ld)));
   
    vec4 diff=vec4(dd*1.2*lv)+vec4(0.2);

    //wisp
    float w=pow(dot(normalize(Pos-oPos),normalize(lp-oPos)),5000.0);
    if (length(Pos-oPos)<length(lp-oPos)) w=0.0;   

    //texturing
    //double sampling to fix seams on texture edges
    vec4 tx=texture2D(iChannel0,tuv.yz)+texture2D(iChannel0,-tuv.yz);
    vec4 ty=texture2D(iChannel1,tuv.xz)+texture2D(iChannel1,-tuv.xz);
    vec4 tz=texture2D(iChannel2,tuv.xy)+texture2D(iChannel2,-tuv.xy);
   
    vec4 col=tx*tpn.x+ty*tpn.y+tz*tpn.z;
   
    gl_FragColor = col*diff*min(1.0,fade*10.0)+w;
}

//

]]></raw_data_ps>

</gpu_program>

 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

tex0 = moon3d.image.load2d("./data/tex06.jpg")
tex1 = moon3d.image.load2d("./data/tex01.jpg")
tex2 = moon3d.image.load2d("./data/tex09.jpg")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex0, 0)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex1, 1)
moon3d.madshaders.setShadertoyTexture(shadertoy_prog, tex2, 2)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/The Cave", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


58
3D-Tech News Around The Web / gShaderReplacer 1.2
« on: June 05, 2015, 05:51:02 PM »
gShaderReplacer - OpenGL proxy dll for shader replacement and debugging.

Copyright 2009-2015 Henrik Münther - psycho@loonies.dk

WHY
===
-Use the included config to run stuff that does not work otherwise.
-Fix non-working stuff without help from the authors (and maybe tell him
 what to fix afterwards).
-Easy debugging of your own stuff on different hardware, without the need
 for dev-tools.
-Analyzing/optimizing of released stuff.
-Peek in other ppl's shader sources ;) (sorry, could not find a reasonable way
 to avoid that while keeping main functionality).

HOW
===
Place the opengl32.dll in the same directory as your executable and do the
neccesary changes to gshaderreplacer.xml.
Depending on configuration the opengl will dump and/or replace all shaders
sent to OpenGL from executables in the directory.

BUT HOW?
========
The included gshaderreplacer.xml should be more or less self explaining.
For the general configuration you can tell it to dump shaders to disk or not
(no need to dump for "user" mode) and make global replacers. Replacers can also
be restricted to a specific .exe file, by putting it into an Application block.
There is no pattern matching for executables, but several names can be written,
like: <Application Name="intro.exe" Name0="intro_safe.exe" Name1="intro_low.exe">
etc.
Replacers can be either string (inlined in .xml file) or file (seperate file)
based - FileReplacers are useful for debugging but final fixes should be a couple
of StringReplacers.
Replacers can be restricted to a certain graphics card vendor, by using the
Vendor=ATI or Vendor=NVIDIA attribute. So if you are making a workaround for a
specific vendor, you should use this, but if you are just making the code
glsl-conformant (typically fixing something the nvidia compiler happily
compiles) there is no reason for a vendor attribute.

UPDATES
=======
I hope we can extend the default gshaderreplacer.xml to fix (or optimize) more
and more intros, so please send in additions to the file and I will update the
archive. Luckily the file is not too long at the moment, as most people fix the
errors when told how :)

PROBLEMS?
=========
For speed reasons it's not doing init code for every opengl function, so if
someone (incorrectly) hits a normal gl function before the context is set up,
it will crash. However, that's pretty easy to fix from the crash message,
where the  illegal jump adress tells which function that needs the init-code.
It intercepts shader source calls for the ARB extension and GL2.0.

HISTORY
=======
1.0 First public release.
1.0.1 Few fixes, more shaders
1.1 Support for glCreateShaderProgramv
1.2 Fixed a buffer overrun, more shaders

59
English forum / Hypertexture trabeculum converted
« on: June 05, 2015, 01:30:53 PM »
Hypertexture trabeculum converted to GLSL Hacker format

edit: code removed


60
English forum / Slisesix converted
« on: June 05, 2015, 01:14:51 PM »
Slisesix converted to GLSL Hacker format

Copy the code and save as slisesix_gl2.xml in demo folder of MadShaders.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - GLSLSandbox/Slisesix"
          width="800" height="400"
          gl_version_major="2" gl_version_minor="1" />
         
         
<gpu_program name="glslsandbox_prog" >
    <raw_data_vs><![CDATA[     
void main()
{   
    gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;       
}
  ]]></raw_data_vs>
 
    <raw_data_ps><![CDATA[     


//

// http://glslsandbox.com/e#4456.6

/*
Code for the 4k procedural graphics Slisesix from the demoscene
(http://www.pouet.net/prod.php?which=51074).
It made 1st position in the Euskal Party 2008 in Bilbao (Spain).
It's raymarching in a procedural distance field
*/
// port by @rotwang *** help needed ***
// removing unsupported stuff like
// if( (((submat>>10)&7)>6) )

#ifdef GL_ES
precision highp float;
#endif

#extension GL_EXT_gpu_shader4: enable

uniform vec2 resolution;
uniform float time;
uniform sampler2D tex0;

float random(vec2 co){
    return fract(sin(dot(co.xy,vec2(12.9898,78.233))) * 43758.5453);
}

int icoolfFunc3d2( in int n )
{
   // n=(n<<13)^n;
   // return (n*(n*n*15731+789221)+1376312589) & 0x7fffffff;
    float st = random( vec2(n));
    return int(st);
}

float coolfFunc3d2( in int n )
{
    return float(icoolfFunc3d2(n));
}

float noise3f( in vec3 p )
{
    ivec3 ip = ivec3(floor(p));
    vec3 u = fract(p);
    u = u*u*(3.0-2.0*u);

    int n = ip.x + ip.y*57 + ip.z*113;

    float res = mix(mix(mix(coolfFunc3d2(n+(0+57*0+113*0)),
                            coolfFunc3d2(n+(1+57*0+113*0)),u.x),
                        mix(coolfFunc3d2(n+(0+57*1+113*0)),
                            coolfFunc3d2(n+(1+57*1+113*0)),u.x),u.y),
                    mix(mix(coolfFunc3d2(n+(0+57*0+113*1)),
                            coolfFunc3d2(n+(1+57*0+113*1)),u.x),
                        mix(coolfFunc3d2(n+(0+57*1+113*1)),
                            coolfFunc3d2(n+(1+57*1+113*1)),u.x),u.y),u.z);

    return 1.0 - res*(1.0/1073741824.0);
}

float fbm( in vec3 p )
{
    return 0.5000*noise3f(p*1.0) +
           0.2500*noise3f(p*2.0) +
           0.1250*noise3f(p*4.0) +
           0.0625*noise3f(p*8.0);
}


float techo( in float x, in float y )
{
    y = 1.0 - y;
    if( x<0.1 || x>0.9 ) return y;
    x = x - 0.5;
    return -(sqrt(x*x+y*y)-0.4);
}


float distToBox( in vec3 p, in vec3 abc )
{
    vec3 di=max(abs(p)-abc,0.0);
    return dot(di,di);
}


float columna( in float x, in float y, in float z, in float mindist, in float offx )
{
    vec3 p=vec3(x,y,z);
    float di0=distToBox( p, vec3(0.14,1.0,0.14) );
    if( di0 > (mindist*mindist) ) return mindist + 1.0;

    float y2=y-0.40;
    float y3=y-0.35;
    float y4=y-1.00;

    float di1=distToBox( p, vec3(0.10,1.00,0.10) );
    float di2=distToBox( p, vec3(0.12,0.40,0.12) );
    float di3=distToBox( p, vec3(0.05,0.35,0.14) );
    float di4=distToBox( p, vec3(0.14,0.35,0.05) );
    float di9=distToBox( vec3(x,y4,z), vec3(0.14,0.02,0.14) );

    float di5=distToBox( vec3((x-y2)*0.7071, (y2+x)*0.7071, z), vec3(0.10*0.7071,  0.10*0.7071, 0.12) );
    float di6=distToBox( vec3(x, (y2+z)*0.7071, (z-y2)*0.7071), vec3(0.12,  0.10*0.7071, 0.10*0.7071) );
    float di7=distToBox( vec3((x-y3)*0.7071, (y3+x)*0.7071, z), vec3(0.10*0.7071,  0.10*0.7071, 0.14) );
    float di8=distToBox( vec3(x, (y3+z)*0.7071, (z-y3)*0.7071), vec3(0.14,  0.10*0.7071, 0.10*0.7071) );

    float di=min(min(min(di1,di2),min(di3,di4)),min(min(di5,di6),min(di7,di8)));
    di=min(di,di9);

  //  di += 0.00000003*max( fbm(10.1*p), 0.0);

    return di;
}



float bicho( vec3 x, in float mindist )
{
//    float ramo = noise3f( vec3(2.0*time, 2.3*time, 0.0) );

    x -= vec3(0.64,0.5,1.5);

    float r2 = dot(x,x);

    float sa = smoothstep(0.0,0.5,r2);
    float fax = 0.75 + 0.25*sa;
    float fay = 0.80 + 0.20*sa;

    x.x *= fax;
    x.y *= fay;
    x.z *= fax;

    r2 = dot(x,x);

    float r = sqrt(r2);

    float a1 = 1.0-smoothstep( 0.0, 0.75, r );
    a1 *= 0.40;
    float si1 = sin(a1);
    float co1 = cos(a1);
    x.xy = mat2(co1,si1,-si1,co1)*x.xy;


    float mindist2 = 100000.0;

    float rr = 0.05+sqrt(dot(x.xz,x.xz));
    float ca = (0.5-0.045*0.75) -6.0*rr*exp2(-10.0*rr);
    for( int j=1; j<7; j++ )
    {
        float an = (6.2831/7.0) * float(j);
        float aa = an + 0.40*rr*noise3f( vec3(4.0*rr, 2.5, an) ) + 0.29;
        float rc = cos(aa);
        float rs = sin(aa);
        vec3 q = vec3( x.x*rc-x.z*rs, x.y+ca, x.x*rs+x.z*rc );
        float dd = dot(q.yz,q.yz);
        if( q.x>0.0 && q.x<1.5 && dd<mindist2 ) mindist2=dd;
    }

    float c = sqrt(mindist2) - 0.045;
    float d = r-0.30;
    float a = clamp( r*3.0, 0.0, 1.0 );
    return c*a + d*(1.0-a);
}


float map( in vec3 pos, out int sid, out int submat )
{
    submat = 0;
    float dis, mindist;

    //-----------------------
    // suelo
    //-----------------------
    dis = pos.y;
    vec2 axz = vec2(128.0) + 6.0*vec2(pos.x+pos.z,pos.x-pos.z);
    ivec2 ixz = ivec2( floor(axz) );
    submat = icoolfFunc3d2(ixz.x+53*ixz.y);
    vec2 peldxz = fract( axz );
    float peld = smoothstep( 0.975, 1.0, max( peldxz.x, peldxz.y ) );
   
//    if( (((submat>>10)&7)>6) )
    if( submat>3 )
    {
        peld = 1.0;
    }
    dis += 0.005*peld;
    mindist = dis;
    sid = 0;
    if( peld>0.0000001 ) sid = 2;

    //-----------------------
    // techo
    //-----------------------
    float fx = fract( pos.x+128.0 );
    float fz = fract( pos.z+128.0 );
    if( pos.y>1.0 )
    {
        dis = max(techo(fx,pos.y),techo(fz,pos.y));
        if( dis<mindist )
        {
            mindist = dis;
            sid = 5;
        }
    }
    fx = fract( pos.x+128.0+.5 );
    fz = fract( pos.z+128.0+.5 );

    //-----------------------
    // columnas
    dis = columna( fx-.5, pos.y, fz-.5, mindist, 13.1*floor(pos.x)+17.7*floor(pos.z) );
    if( dis<(mindist*mindist) )
    {
        mindist = sqrt(dis);
        sid = 1;
    }

    //-----------------------
    // bicho
    //-----------------------

    dis = bicho( pos, mindist );
    if( dis<mindist )
    {
        mindist = dis;
        sid = 4;
    }
    //-----------------------

    return mindist;
}

vec3 calcNormal( in vec3 pos )
{
    float eps = 0.0002;
    vec3 nor;
    int kk, kk2;
    nor.x = map( vec3(pos.x+eps, pos.y, pos.z), kk, kk2 ) - map( vec3(pos.x-eps, pos.y, pos.z), kk, kk2 );
    nor.y = map( vec3(pos.x, pos.y+eps, pos.z), kk, kk2 ) - map( vec3(pos.x, pos.y-eps, pos.z), kk, kk2 );
    nor.z = map( vec3(pos.x, pos.y, pos.z+eps), kk, kk2 ) - map( vec3(pos.x, pos.y, pos.z-eps), kk, kk2 );
    return normalize( nor );
}



void main(void)
{
    vec2 pixel = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
    float an = time*0.15;
    vec2 sc = vec2(cos(an),sin(an));

    float r2 = pixel.x*pixel.x*0.32 + pixel.y*pixel.y;
    float tt = (7.0-sqrt(37.5-11.5*r2))/(r2+1.0);
    pixel *= tt;

    float asp = resolution.x/resolution.y;
    vec3 rd = normalize(vec3(asp*pixel.x*sc.x-sc.y,pixel.y,sc.x+asp*pixel.x*sc.y));
    vec3 ro = vec3(0.5+1.4*sc.y,0.5,1.5-1.4*sc.x);

    float t=0.5;
    int matID=666;
    int subMatID;
    vec3 pos;
    vec3 rgb = vec3(0.0);

    // cast ray
   int nt=0;
   // for( t=0.5; t<12.0; )
    for( int nt=0; nt<60; nt++)
    {
        pos = ro + t*rd;
        float h = map( pos, matID, subMatID );
        if( h<0.01 )
        break;
        t += h;
        if( t>12.0 )
        break;
    }
   

    // shade
    if( matID!=666 )
    {
        // calc normal
        vec3 nor = calcNormal(pos);


        // bump mapping
        float kke=0.0001;
        float bumpa=0.0075;
        if( matID!=5 ) bumpa*=0.75;
        if( matID==4 ) bumpa*=0.50;
        bumpa /= kke;
        float kk = fbm(32.0*pos);
        nor.x += bumpa*(fbm(32.0*vec3(pos.x+kke, pos.y, pos.z))-kk);
        nor.y += bumpa*(fbm(32.0*vec3(pos.x, pos.y+kke, pos.z))-kk);
        nor.z += bumpa*(fbm(32.0*vec3(pos.x, pos.y, pos.z+kke))-kk);
        nor = normalize(nor);

        // light
        float spe = 0.0;
        vec3 lig = vec3( 0.5-pos.x, 0.8-pos.y, 1.5-pos.z );
        float llig = dot(lig,lig);
        float im = inversesqrt(llig);
        lig = lig * im;
        float dif = dot(nor,lig);
        if( matID==4 )
            {dif=0.5+0.5*dif;}
        else
            {dif=0.1+0.9*dif;}
        //if( dif<0.0 ) dif=0.0;
        //dif=max(dif,0.0);
        dif = clamp(dif,0.0,1.0);
        dif *= 2.5*exp2(-1.75*llig);
        float dif2=(nor[0]+nor[1])*0.075;


        // materials
        if( matID==0 )
        {
        //float xoff = 13.1*float(subMatID&255);
            float xoff = 13.1*float(subMatID);
            float fb = fbm(16.0*vec3(pos.x+xoff,pos.y,pos.z));
            rgb = vec3(0.7) + fb*vec3(0.20,0.22,0.25);

           // float baldscale = float((subMatID>>9)&15)/14.0;
        float baldscale = float(subMatID)/14.0;
            baldscale = 0.51 + 0.34*baldscale;
            rgb *= baldscale;
            float fx = 1.0;
       
        //if( (subMatID&256)!=0 )
            if( (subMatID)!=0 )
            fx = -1.0;
       
            float m = sin( 64.0*pos.z*fx +  64.0*pos.x + 4.0*fb );
            m = smoothstep( 0.25, 0.5, m ) - smoothstep( 0.5, 0.75, m );
            rgb += m*vec3(0.15);
        }
        else if( matID==2 )
        {
            rgb = vec3(0.0);
        }
        else if( matID==1 )
        {
            float fb = fbm( 16.0*pos );
            float m = sin( 64.0*pos.z +  64.0*pos.x + 4.0*fb );
            m = smoothstep( 0.30, 0.5, m ) - smoothstep( 0.5, 0.70, m );
            rgb = vec3(0.59) + fb*vec3(0.17,0.18,0.21) + m*vec3(0.15) + vec3(dif2);
        }
        else if( matID==4 )
        {
            float ft = fbm( 16.0*pos );
            rgb = vec3(0.82,0.73,0.65) + ft*vec3(0.1);

            float fs = 0.9+0.1*fbm( 32.0*pos );
            rgb *= fs;

            float fre = max( -dot( nor, rd ), 0.0);
            rgb -= vec3(fre*fre*0.45);
            spe = clamp((nor.y-nor.z)*0.707,0.0,1.0);
            spe = 0.20*pow(spe,32.0);
        }
        // techo
        else //if( matID==5 )
        {
            float fb = fbm( 16.0*pos );
            rgb = vec3(0.64,0.61,0.59) + fb*vec3(0.21,0.19,0.19) + dif2;
        }
   
        // AO
        float ao;
        float totao = 0.0;
        float sca = 10.0;
        for( int aoi=0; aoi<5; aoi++ )
        {
            float hr = 0.01 + 0.015*float(aoi*aoi);
            vec3 aopos =  nor * hr + pos;
            int kk, kk2;
            float dd = map( aopos, kk, kk2 );
            ao = -(dd-hr);
            totao += ao*sca;
            sca *= 0.5;
        }
        ao = 1.0 - clamp( totao, 0.0, 1.0 );
   
        // shadow
        float so = 0.0;
        for( int i=0; i<6; i++ )
        {
            float h = float(i)/6.0;
            float hr = 0.01 + h;
            vec3 aopos = lig * hr + pos;
            int kk, kk2;
            float dd = map( aopos, kk, kk2 );
            so += (1.0-h)*dd*2.0 * (10.0/6.0);
        }
        dif *= clamp( (so-0.40)*1.5, 0.0, 1.0 );
   
        // lighting
        rgb = vec3(spe) + rgb * (ao*vec3(0.25,0.30,0.35) + dif*vec3(1.95,1.65,1.05));
        // fog
        rgb = rgb * exp2( -0.4*t );
    }

    // color correct
    rgb =(sqrt(rgb)*0.7+0.3*rgb)*vec3(0.83,1.0,0.83)*1.2;

    // vigneting
    rgb *= 0.25+0.75*clamp(0.60*abs(pixel.x-1.0)*abs(pixel.x+1.0),0.0,1.0);

    gl_FragColor=vec4(rgb,1.0);
}

////

  ]]></raw_data_ps>

</gpu_program>


 
    <script name="init_scene" run_mode="INIT" >
        <raw_data><![CDATA[   

app_dir = gh_utils.get_scripting_libs_dir()         
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
glslsandbox_prog = moon3d.graphics.getGpuProgram("glslsandbox_prog")

moon3d.madshaders.resetBenchmarkData()

        ]]></raw_data>
    </script>

 
    <script name="update_scene" run_mode="FRAME" >
        <raw_data><![CDATA[   

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindPersp()

moon3d.graphics.bindGpuProgram(glslsandbox_prog)
moon3d.madshaders.updateGLSLSandboxCommonParams(glslsandbox_prog, global_time)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("GLSLSandbox/Slisesix", global_time, 1, 1, 1, 1)

moon3d.endFrame()

        ]]></raw_data>
    </script>
   

    <script name="resize_scene" run_mode="SIZE" >
        <raw_data><![CDATA[   

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

        ]]></raw_data>
    </script>
 
</glsl_hacker>


Pages: 1 2 [3] 4 5 ... 157