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 ... 3 4 [5] 6 7 ... 157
81
 Introducing The GeForce GTX 980 Ti. Play The Future


The GeForce GTX 980 Ti is primed and ready for 4K, VR and DirectX 12 experiences, and runs at blistering speeds in today’s demanding DirectX 11 games, like Grand Theft Auto V and The Witcher 3: Wild Hunt.

Read more >   

82
English forum / Dawn of the tentacle converted
« on: June 01, 2015, 04:18:19 PM »
Dawn of the tentacle converted to GLSL Hacker format

Copy the code and save as dawn_of_the_tentacle_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Dawn of the tentacle"
          width="1024" height="1024"
          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/Xtf3Rj

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;



//

/*
---------------------------------------------------------------------------------------

 "Dawn of the Tentacle" by Pablo Roman Andrioli (Kali)
 
 Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

---------------------------------------------------------------------------------------
*/


//smooth version by iq
#define smoothversion

//remove if you see a flat shaded tentacle
//(it happens to me in firefox)
#define underwater


// Raymarching
const float zoom=.95;
const float detail=.017;    // distance to stop tracing
const float maxdist=14.;    // scene depth
const int maxsteps=55;      // max ray steps

// Light
const vec3 lightdir=vec3(.6,-1.,0.);
const float diffuse=.7;
const float specular=.7;
const float specularexp=5.;

// Tentacle Shape
const float maxiter=28.;    // Max iterations
const float width=.9;
const float height=0.52;
const float scaling=0.92;       // Scaling factor at each iteration
const vec3 rotvector=vec3(1.,0.,0.); // Base vector for rotation
const float anglevary=.2;    // Angle variation at each iteration

// Animation
const float amplitude=0.55;   
const float speed=0.6;
const float dynscaling=0.9; // Scaling factor for the dynamic fractal animation


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

vec3 dir;
vec2 pix;
vec2 coord;


// Rotation function included in MathUtils.frag of Syntopia's Fragmentarium
mat3 rotationMat(vec3 v, float angle)
{
    float c = cos(angle);
    float s = sin(angle);
   
    return mat3(c + (1.0 - c) * v.x * v.x, (1.0 - c) * v.x * v.y - s * v.z, (1.0 - c) * v.x * v.z + s * v.y,
        (1.0 - c) * v.x * v.y + s * v.z, c + (1.0 - c) * v.y * v.y, (1.0 - c) * v.y * v.z - s * v.x,
        (1.0 - c) * v.x * v.z - s * v.y, (1.0 - c) * v.y * v.z + s * v.x, c + (1.0 - c) * v.z * v.z
        );
}


// Water
float water(vec3 p){
    //p.z-=15.;
    float l=length(p.xz);
    p.x+=l*3.;
    p.x-=iGlobalTime*1.5;
    float h=(sin(p.x)+cos(p.z))*.05;
    p.xz*=vec2(3,2.5);
    p.xz+vec2(1.,2.5);
    h+=(cos(p.x)+sin(p.z))*.05;
    h+=texture2D(iChannel0,p.xz*.2).z*max(0.1,.2-l*l*.01); //texture displacement
    return p.y-h;
}


float smin( float a, float b )
{
float k = 0.1; float h = clamp( 0.5 + 0.5*(b-a)/k, 0.0, 1.0 );
return mix( b, a, h ) - k*h*(1.0-h);
}


// Scene DE
vec2 DE(vec3 pos){

    float angle=0.;
    vec3 p=pos;
    int n = 0;
    float sc=1.;
    float time=iGlobalTime*speed+100.;
    float amp=sin(time/2.)*amplitude;
    float dtent=1e10;
    float dd=1e10;
    float minit=maxiter;
    vec3 minp=pos;
    for (float n=0.; n < maxiter; n++) {
        float d1=length(p)-width*sc;
        float d2=length(p+vec3(width*sc*.75,0.,0.))-width*sc*.4;
        float d=min(d1,d2);
        if (n<1.) dtent=d;
        if (d<=dtent) { //test min distance and save iteration & vector
            dtent=d;
            minit=n;
            minp=p;
        }
        #ifdef smoothversion
        dd=smin(dd,d);
        #endif
       
        p*=rotationMat(normalize(rotvector+vec3(0.,sin(iGlobalTime)*.7,0.)),sin(time)*amp+angle);
        p.y-=height*sc; // go up
        sc*=scaling; // scale size
    //    amp*=dynscaling; // scale amplitude
        time/=dynscaling; // scale time
        angle+=radians(anglevary); // vary rotation
    }
        #ifdef smoothversion
        dtent=dd;
        #endif   
   
    dtent+=length(texture2D(iChannel1,vec2(minp.y*2.,atan(minp.x,minp.z)*.).xyz)*.025;
   
    float dwat=water(pos);
    float de=min(dwat,dtent);
    float col=0.;
    if (de!=dwat) col=minit+1.; // return coloring parameter
    return vec2(de,col);
}


// finite difference normal
vec3 normal(vec3 pos) {
    vec3 e = vec3(0.0,detail,0.0);
   
    return normalize(vec3(
            DE(pos+e.yxx).x-DE(pos-e.yxx).x,
            DE(pos+e.xyx).x-DE(pos-e.xyx).x,
            DE(pos+e.xxy).x-DE(pos-e.xxy).x
            )
        );   
}

// coloring
vec3 color(float obj, vec3 p) {

    if (obj<1.) { //water
        vec3 tex=texture2D(iChannel0,p.xz*.1).xyz;
        return (tex+.2)*vec3(1.7,1.2,1.2);
    }
    else if (obj>0.) {//tentacle
        float g=(maxiter-obj)/maxiter;
        return vec3(.9,g+.2,0.6);
    }
   
}

//lighting
vec3 light(vec3 p) {
vec3 ldir=normalize(lightdir);
vec3 n=normal(p);
float diff=max(0.0,dot(-n, ldir))*diffuse;
vec3 r = reflect(ldir,n);
float spec=max(0.,dot(dir,-r));
return vec3(1.,.8,.5)*(diff+pow(spec,specularexp)*specular);   
}

//raymarching
vec3 raymarch(vec3 from, vec3 dir) {
    vec3 p,p2;
    float totdist=0., totdist2=0.;
    vec3 col;
    vec2 d=vec2(0.);
    float d2=100000.;
    //march
    for (int i=1; i<maxsteps; i++) {
        p=from+totdist*dir;
        d=DE(p);
        if (d.x<detail || totdist>maxdist) break;
        #ifdef smoothversion
            totdist+=max(.1,d.x);
        #else
            totdist+=max(.01,d.x);
        #endif
    }

    //underwater
    if (d.x<detail && d.y<.5) {
        totdist2=totdist+detail*3.;
        for (int i=1; i<maxsteps; i++) {
            p2=from+totdist2*dir;
            d2=length(p2.xz)-width/scaling+p2.y*.2;
            if (d2<detail || totdist2>maxdist) break;
            totdist2+=d2;
        }
    }
   
   
    vec3 back=mix(vec3(1.3,.95,.7),vec3(.52,.5,.56) //background gradient
    *1.25,clamp((dir.y+.13)*2.5,0.,1.35));
    back+=vec3(1.,1.,.5)*(.04+dot(lightdir,-dir)*.4); //dawn
   
    if (d.x<detail) {
        col=color(d.y,p)*light(p-detail*dir*.5); //apply color+light
        col=mix(col,back,smoothstep(0.,2.2,totdist*.17)); //fog
    } else { //background-sky
        col=back+.85*vec3(1.,.85,.7)*texture2D(iChannel1,
        vec2(dir.y*4.+.5,atan(dir.z,dir.x)*1.*.15+vec2(iGlobalTime*.002)).b*(dir.y*.75+.15)
        *vec3(max(0.1,.5-coord.y*2.5))*1.4;
        col-=vec3(max(0.,coord.y*.3));
    }
    #ifdef underwater
    if (d2<detail) {
        vec3 col2=color(1.1,p2)*light(p+p2-detail*dir*.5);
        col=mix(col,col2,.3); //underwater
    }
    #endif
   
    col+=vec3(1.,.7,.5)*max(0.,9.-totdist)*.04; //camlight
    return col;
}

void main()
{
    //Camera
    pix=gl_FragCoord.xy / iResolution.xy;
    float viewangle=-135.+(iMouse.x/iResolution.x)*100.;
    mat3 rotview=rotationMat(vec3(0.,1.,0.),radians(viewangle));
    coord = pix-vec2(.5);
    coord.y*=iResolution.y/iResolution.x;
    vec3 from=vec3(0.,2.85,8.)*rotview*zoom;
    dir=normalize(vec3(coord*1.8,-1.))*rotview;
   
    //Draw scene
    vec3 col=vec3(0.);
    col=raymarch(from,dir);
   
    //adjust levels
    col*=pow(length(col),1.*.41;
    col+=vec3(0.02,-.01,0.05);
    col=mix(col,vec3(length(col))*.6,.3);
   
    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/tex07.jpg")
tex1 = moon3d.image.load2d("./data/tex03.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.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Dawn of the tentacle", 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>


83
English forum / Sakura revisited converted
« on: May 31, 2015, 04:44:48 PM »
Sakura revisited converted to GLSL Hacker format

Copy the code and save as Sakura_revisited_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Sakura revisited"
          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/Xt23Dz

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;



//

#define PI 3.1415926
#define V vec2(0.,1.)

#define t iGlobalTime
#define r iResolution.xy
#define c gl_FragCoord
#define cl(i) clamp(i,0.,1.)

#define MAT_NULL -1.
#define MAT_ANTHER 0.
#define MAT_FILAMENT 1.
#define MAT_PISTIL 2.
#define MAT_PETAL 3.
#define MAT_CALYX 4.
#define MAT_TREE 5.

float hash(vec2 _v)
{
    return fract(sin(dot(_v,vec2(89.44,19.36)))*22189.22);
}

float iHash(vec2 _v,vec2 _r)
{
    float h00 = hash(vec2(floor(_v*_r+V.xx)/_r));
    float h10 = hash(vec2(floor(_v*_r+V.yx)/_r));
    float h01 = hash(vec2(floor(_v*_r+V.xy)/_r));
    float h11 = hash(vec2(floor(_v*_r+V.yy)/_r));
    vec2 ip = vec2(smoothstep(V.xx,V.yy,mod(_v*_r,1.)));
    return (h00*(1.-ip.x)+h10*ip.x)*(1.-ip.y)+(h01*(1.-ip.x)+h11*ip.x)*ip.y;
}

float noise(vec2 _v)
{
    float sum = 0.;
    for(int i=1; i<9; i++)
    {
        sum += iHash(_v+vec2(i),vec2(2.*pow(2.,float(i))))/pow(2.,float(i));
    }
    return sum;
}

mat2 rotate( float _th )
{
    return mat2( cos(_th), -sin(_th), sin(_th), cos(_th) );
}

float pole( vec3 _p, float _r, float _l )
{
    vec2 d = abs( vec2( length( _p.xz ), _p.y ) ) - vec2( _r, _l );
    return min( max( d.x, d.y ), 0. ) + length( max( d, 0. ) );
}

float pole( vec3 _p, float _r )
{
    return length( _p.xz ) - _r;
}

float smin( float _a, float _b, float _k )
{
    float h = cl( 0.5+0.5*( _b-_a )/_k );
    return mix( _b, _a, h ) - _k*h*( 1.-h );
}

vec2 stamen( vec3 _p )
{
    vec2 dist = vec2( 1E2 );
    vec2 distC = dist;
    float phase = floor( atan( _p.z, _p.x )/PI/2.*13.-1. );
    vec3 offset = vec3( .04, -.0, .04 ) * ( 1. + sin( t )*.1 );
    offset.xz *= .6 + hash( vec2( phase*1.9873, 821.122 ) )*.6;
    vec3 p = _p - V.xyx*.01;
    p.xz = rotate( floor( phase )*PI*2./13. ) * p.xz;
    vec3 pa = p + ( sin(p.x*200.)*sin(p.y*200.)*sin(p.z*200.) ) * .003 - offset - V.xyx*.1;
    distC = vec2( length( pa ) - .005, MAT_ANTHER );
    if( distC.x < dist.x ){ dist = distC; }
    pa = p + vec3( sin(p.y*20.), 0., cos(p.y*20.) )*.003 - offset * ( .5+.5*sin( p.y/.1*PI/2. ) );
    distC = vec2( pole( pa-V.xyx*.025,  sin( pa.y/.1*PI )*.001, .075 ), MAT_FILAMENT );
    if( distC.x < dist.x ){ dist = distC; }
    return dist;
}

vec2 pistil( vec3 _p )
{
    vec3 p = _p;
    float pistil = pole( p - V.xyx*.01 + vec3( cos(p.y*50.), 0., sin(p.y*50.) )*.001, .004, .06 );
    pistil = smin( pistil, length( vec2( length( p.xz )-.007, p.y-.07 ) )-.001, .01 );
    return vec2( pistil, MAT_PISTIL );
}

vec2 petals( vec3 _p )
{
    float dist = 1E2;
    vec3 p = _p;
    p.y -= pow( length( p.xz ), .5)*.2-.055;
    p.xz = rotate( floor( atan( p.z, p.x )/PI/2.*5.-2. )*PI*2./5. ) * p.xz;
    p.xy = rotate( -.3 + sin( t )*.1 ) * p.xy;
    p.x += .14;
    p.x *= ( 1. - pow( abs( sin( atan( p.z, p.x ) ) ), .1 )*.3 )*1.4;
    p += ( sin(_p.x*20.)*sin(_p.y*20.)*sin(_p.z*20.) ) * .018;
    dist = min( dist, pole( p, .1, .001 ) );
    return vec2( dist, MAT_PETAL + cl( length( _p.xz ) ) );
}

vec2 calyx( vec3 _p )
{
    float dist = 1E2;
   
    vec3 p = _p;
    p.y -= pow( length( p.xz ), .2)*.2-.13;
    p.xz = rotate( floor( atan( p.z, p.x )/PI/2.*5.-2. )*PI*2./5. ) * p.xz;
    p.xy = rotate( -.3 ) * p.xy;

    vec3 ptemp = p;
    p.x += .04;
    p.x *= max( pow( abs( sin( atan( p.z, p.x ) ) ), .1 ), .6 );
    p += ( sin(_p.x*20.)*sin(_p.y*20.)*sin(_p.z*20.) ) * .018;
    dist = smin( dist, pole( p, .03, .001 ), .02 );

    p = ptemp + V.xyx*.15;
    p.x -= .02;
    p.x *= max( pow( abs( sin( atan( p.z, p.x ) ) ), .1 ), .6 );
    p += ( sin(_p.x*20.)*sin(_p.y*20.)*sin(_p.z*20.) ) * .018;
    dist = smin( dist, pole( p, .01, .001 ), .02 );
   
    dist = smin( dist, pole( _p + vec3( cos(_p.y*20.), 0., sin(_p.y*20.) )*.004 + V.xyx*.15, .01, .09 ), .02 );
   
    return vec2( dist, MAT_CALYX + cl( -_p.y-.05 ) );
}

vec2 blossom( vec3 _p, float _h )
{
    vec2 dist = vec2( 1E2 );
    if( length( _p ) < .28 )
    {
        dist = stamen( _p );
        vec2 distC = pistil( _p );
        if( distC.x < dist.x ){ dist = distC; }
        distC = petals( _p );
        if( distC.x < dist.x ){ dist = distC; }
        distC = calyx( _p );
        if( distC.x < dist.x ){ dist = distC; }
    }
    else
    {
        dist = vec2( length( _p )-.27, MAT_NULL );
    }
    return dist;
}

vec2 branch( vec3 _p )
{
    vec2 dist = vec2( 1E2 );
    vec3 p = _p;
    p.xy = rotate( -1. )*p.xy;
    vec3 pt = p + sin( p.x*10. )*sin( p.y*10. )*sin( p.z*10. ) * .03;
    dist = vec2( pole( pt, .1 ), MAT_TREE );
    p.zx = rotate( floor( p.y*2.+.5 )*.7 - .5 )*p.zx;
    float th = atan( p.z, p.x );
    if( th < 0. ){ p.zx = rotate( PI )*p.zx; }
    p.yz = rotate( PI/2. )*p.yz;
    p.y -= .3;
    p.z = mod( p.z+.25, .5 )-.25;
    vec2 distC = blossom( p, 12.4 );
    if( distC.x < dist.x ){ dist = distC; }
    return dist;
}

vec2 scene( vec3 _p )
{
    vec2 dist = branch( _p );
    return dist;
}

vec3 sceneNormal( vec3 _p )
{
    vec2 d = V*1E-4;
    return normalize( vec3(
        scene( _p + d.yxx ).x - scene( _p - d.yxx ).x,
        scene( _p + d.xyx ).x - scene( _p - d.xyx ).x,
        scene( _p + d.xxy ).x - scene( _p - d.xxy ).x
    ) );
}

void main()
{
    vec2 p = (c*2.-r)/r.x;
   
    vec3 camPos = vec3( .8, 0., 1. );
    vec3 camTar = vec3( sin(t*.72), sin(t*.83), sin(t*.37) )*.01 - vec3( sin( t*.21 )*.2, -.2, .0 );
    vec3 camDir = normalize( camTar - camPos );
    vec3 camAir = V.xyx;
    vec3 camSid = normalize( cross( camDir, camAir ) );
    vec3 camTop = normalize( cross( camSid, camDir ) );
   
    vec3 rayDir = normalize( camSid * p.x + camTop * p.y + camDir );
    vec3 rayPos = camPos;
    float rayLen = 0.;
    vec2 dist = V.xx;
    for( int i=0; i<64; i++ )
    {
        dist = scene( rayPos )*vec2( .6, 1. );
        rayLen += dist.x;
        rayPos = camPos + rayDir * rayLen;
        if( dist.x < 2E-3 || 1E2 < rayLen ){ break; }
    }
   
    vec3 col = V.xxx;
    if( dist.x < 4E-3 )
    {
        vec3 ligPos = vec3( 0., 1., 11. );
        vec3 nor = normalize( sceneNormal( rayPos ) );
        float dif = cl( dot( normalize( rayPos-ligPos ), -nor ) )*.3;
        float amb = .7;
        float speDot = cl( dot( normalize( normalize( rayPos-ligPos ) + normalize( rayPos-camPos ) ), -nor ) );
        float spe = cl( pow( speDot, 10. ) )*.1;
        vec3 matCol = V.xxx;
        if( floor( dist.y ) == MAT_NULL ){ amb = 1.; matCol = vec3( 1. ); }
        else if( floor( dist.y ) == MAT_ANTHER ){ matCol = vec3( .9, .9, .5 ); }
        else if( floor( dist.y ) == MAT_FILAMENT ){ matCol = vec3( .9, .9, .8 ); }
        else if( floor( dist.y ) == MAT_PISTIL ){ matCol = vec3( .8, .9, .6 ); }
        else if( floor( dist.y ) == MAT_PETAL ){ matCol = vec3( .9, .4, .8 ) + vec3( .1, .6, .2 ) * ( 1.-exp( -fract( dist.y )*16. ) ); }
        else if( floor( dist.y ) == MAT_CALYX ){ matCol = vec3( .7, .1, .3 ) + vec3( -.4, .4, -.4 ) * cl( fract( dist.y )*8. ); }
        else if( floor( dist.y ) == MAT_TREE ){
            nor += vec3(
                noise(vec2((rayPos.x+rayPos.z)*8.,rayPos.y*8.+27.1982))-.5,
                noise(vec2((rayPos.x+rayPos.z)*8.,rayPos.y*8.+28.1982))-.5,
                noise(vec2((rayPos.x+rayPos.z)*8.,rayPos.y*8.+29.1982))-.5
            )*2.;
            nor = normalize( nor );
            dif = cl( dot( normalize( rayPos-ligPos ), -nor ) )*.6;
            float speDot = cl( dot( normalize( normalize( rayPos-ligPos ) + normalize( rayPos-camPos ) ), -nor ) );
            float spe = cl( pow( speDot, 10. ) )*.1;
            matCol = vec3( .4, .3, .1 );
        }
           col = ( dif + amb ) * matCol + spe;
    }
    else
    {
        col = vec3( .5, .7, .9 );
        for( float i=12.; i<39.; i+=1. )
        {
            vec2 pos = ( vec2( hash(vec2(i,198.33)), hash(vec2(i,298.33)) ) - .5 )*r/r.x*2.;
            pos += vec2( sin( t*.2*hash(vec2(i,19.233)) ), sin( t*.2*hash(vec2(i,29.233)) ) )*.01;
            col += cl( 12.-length(p-pos)*50. ) * vec3( 1., .7, .9 )*.02;
        }
    }
   
    col -= length( p )*.4;
   
    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/Sakura revisited", 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>



84
English forum / Manta Ray converted
« on: May 31, 2015, 04:41:41 PM »
Manta Ray converted to GLSL Hacker format

Copy the code and save as Manta_Ray_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Manta ray"
          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/4ls3zM

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 iChannel3;



//

// version 1.5 = trying to make the water surface and the sea floor more interesting
// version 1.3 = changed wing primitives and adding front flaps
// version 1.2 = working on improving the shape
// version 1.1 = multiple mantas. Added scattering attributes
// Version 1.0 = creation. Added a background. Single manta swim loop


const vec3 sun = vec3(-0.6, 0.4,-0.3);
float time = iGlobalTime+32.2;
vec3 lightDir = normalize(vec3(.1,.7, .2));
#define csb(f, con, sat, bri) mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), f*bri)), f*bri, sat), con)
#define MATERIAL_SKIN 1.0
#define MATERIAL_NONE 0.0
#define SPACING 4.
#define ISPACING 0.25
#define BBSIZE 2.0
#define MAXDIST 25.

//--------------------------------------------------------------------------------------
// Utilities....
float hash( float n )
{
    return fract(sin(n)*43758.5453123);
}

vec3 Rotate_Y(vec3 v, float angle)
{
    vec3 vo = v; float cosa = cos(angle); float sina = sin(angle);
    v.x = cosa*vo.x - sina*vo.z;
    v.z = sina*vo.x + cosa*vo.z;
    return v;
}

// stolen from IQ.
float softMin(float a, float b)
{
    float k = 0.5;
    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 difference(float a, float b)
{
    return max(a, -b);
}

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

float wings(vec3 p)
{   
    p*=vec3(0.7,3.5,1.2);
    p.z -= p.x*p.x*0.8;
    p.y -= 0.1;
    float d = p.x+p.y*p.y+pow(abs(p.z),1.4);
   
    return d-1.0;
}

float mantabody(vec3 p)
{
    vec3 origP = p;
    // thinner wings
    p*=vec3(2.4,2.6,1.3);
    float d = sphere(p, 1.0);
    d = softMin(d, wings(origP));
   
    // body hole, scale with body
    vec3 holeP = p;
    holeP *= vec3(1.2,1.4,0.;
    holeP += vec3(-0.2,0.13,0.6);
    d = difference(d, length(holeP) - 0.9);
   
    vec3 flapsP = origP;
    flapsP += vec3(-0.3,0.3-origP.x*0.5,0.95-origP.x*1.);
    flapsP *= vec3(6.0,12.0,6.0);
    d = softMin(d, sphere(flapsP,1.0));
   
    return d;
}


//--------------------------------------------------------------------------------------
vec2 Scene(vec3 p)
{
    p.z+= time;
    float mat = MATERIAL_SKIN;
   
   
    // Repeat
    vec3 loopP = p;
    loopP.x = mod(loopP.x+BBSIZE, SPACING)-BBSIZE;
    loopP.z = mod(loopP.z+BBSIZE, SPACING)-BBSIZE;

    //scramble
    float rowId = floor((p.x+2.)*ISPACING);
    float columnId = floor((p.z+2.)*ISPACING);
    //loopP.y += hash(7.*rowId + 11.* columnId)*4.-1.5; // starting height
    float size = 0.6 + 0.6*hash(7.*rowId + 11.* columnId);
    //float size = 1.0;
    float timeloop = time * 2.5 / (size-0.25) + // loop speed
        hash(rowId+3.*columnId) * 10.; // random offset
    loopP.y+= -sin(timeloop-0.5)*.25 * size;
    loopP.y+= sin(time*0.5 + hash(37.*rowId+11.*columnId)*17.) * 2.5;
   
    // Mirror
    loopP.x = abs(loopP.x);
    loopP/=size;
   
    float d = 3.;
   
   
    //////////////////
    // manta body
    //////////////////
    vec3 mantap = loopP;
   
    // tail
    vec3 tailp = loopP;
   
    // animate wings
    float animation = sin(timeloop-3. - 1.3*loopP.z);
    mantap.y += animation * (0.3*loopP.x*loopP.x + 0.10);
    tailp.y += animation* (0.1 + smoothstep(1.,3.,tailp.z)) - 0.1;
   
    d = min(d, mantabody(mantap));
    //d = min(d, sphere(mantap,1.0));
   
   
    float taild = length(tailp.xy)*0.4 +
        smoothstep(0.,1.,-tailp.z) * 2.+
        smoothstep(3.,5.,tailp.z) * 10.;
   
    // soft min?
    d = softMin(d,taild);

    return vec2(d, mat);
}

//--------------------------------------------------------------------------------------
vec4 Trace(vec3 rayOrigin, vec3 rayDirection, out float hit)
{
    const float minStep = 0.005;
    hit = 0.0;
   
    vec2 ret = vec2(0.0, 0.0);
    vec3 pos = rayOrigin;
    float dist = 0.0;
    for(int i=0; i < 200; i++){
        if (hit == 0.0 && dist < MAXDIST && pos.y<10.0 && pos.y > -10.0 )
        {
            pos = rayOrigin + dist * rayDirection;
            ret = Scene(pos);
            // ret.x = distance
            // ret.y = material type
            if (ret.x < 0.01)
                hit = ret.y;

            // increment
            if (ret.y >= 2.0)
                dist += ret.x * 10.0;
            else
                dist += max(ret.x * 0.2, minStep);
        }
       
    }
    return vec4(pos, ret.y);
}

//--------------------------------------------------------------------------------------
vec3 GetNormal(vec3 p)
{
    vec3 eps = vec3(0.01,0.0,0.0);
    return normalize(vec3(Scene(p+eps.xyy).x-Scene(p-eps.xyy).x,
                          Scene(p+eps.yxy).x-Scene(p-eps.yxy).x,
                          Scene(p+eps.yyx).x-Scene(p-eps.yyx).x ));
}

//--------------------------------------------------------------------------------------
vec3 GetColour(vec4 p, vec3 n, vec3 org, vec3 dir)
{
    vec3 localP = vec3(p) + vec3(0.,0.,time);
    vec3 loopP = localP.xyz;
    loopP.x = mod(loopP.x+BBSIZE, SPACING)-BBSIZE;
    loopP.z = mod(loopP.z+BBSIZE, SPACING)-BBSIZE;
   
   
    vec3 colour = vec3(0.0);
    if (p.w < 1.5)
    {
        float v = clamp(-(n.y-.1)*6.2, 0.3, 1.0);
        v+=.35;
        colour = vec3(v*.8, v*.9, v*1.0);
    }
   
    vec2 coord = loopP.xz;
    vec3 colorUp = colour;
    float stainsUp = texture2D(iChannel1, coord).x;
    stainsUp *= stainsUp * 2.;
    stainsUp = 1.-stainsUp;
    stainsUp += smoothstep(2.,-2.,loopP.z);
    stainsUp = clamp(stainsUp, 0., 1.);
    colorUp *= stainsUp;
   
    vec3 colorDown = colour;
    float stainsDown = texture2D(iChannel1, coord*0.4).x;
    stainsDown += smoothstep(0.,-3.,loopP.z);
    stainsDown *= stainsDown;
    stainsDown = clamp(stainsDown, 0., 1.);
    colorDown *= vec3(stainsDown);
   
    colour = mix(colorUp, colorDown, smoothstep(-0.4,0.4,n.y));   
    {
        // Water caustics
        vec2 wat = p.xz*1.;
        wat +=  (texture2D(iChannel0, (wat*5.0+time*.04)*.1, 3.0).z -
             texture2D(iChannel0, wat*.3-time*.03, 2.0).y) * .4;
        float causticLight = texture2D(iChannel0, wat* .04, 0.0).x;
        causticLight = pow(max(0.0, causticLight-.2), 1.0) * 20. * smoothstep(-5.,3.,p.y);
        colour *= vec3(1.0) + vec3(causticLight*.5, causticLight, causticLight)*max(n.y, 0.0);
    }
   
    // shadow
    float diff = dot(n,lightDir);
    // light properties
    vec3 brightLight = vec3(0.7,0.7,0.;
    vec3 shade = vec3(0.12,0.15,0.22);
    colour *= mix(shade,brightLight,max(diff*0.5+0.5,0.0));
   
    return colour;
}


//--------------------------------------------------------------------------------------
void main()
{
    vec3 col;   
    vec2 uv = (gl_FragCoord.xy / iResolution.xy) - vec2(.5);
    uv.x*=iResolution.x/iResolution.y;
    vec3 dir = normalize(vec3(uv, -1.0));
   
    //vec3 pos = vec3(1.3, sin(time+4.3)*.18-.05, sin(-time*.15)*5.0-1.35);
    vec3 pos = (sin(time*0.14)*2.+4.5)*vec3(sin(time*.5), 0.0, cos(time*.5));
    pos.z -= time;
    pos.y += 0.7 * sin(time * 0.2);
    float rot = -time*0.5;
    dir = Rotate_Y(dir, rot);

    // Sun...
    float i = max(0.0, 1./(length(sun-dir)+1.0));
    col = vec3(pow(i, 1.9), pow(i, 1.0), pow(i, .) * 1.3;
   
    // Water depth colour...
    col = mix(col, vec3(0.0, .25, .45), ((1.0-uv.y)*.45) * 1.;
   
    float d;
    if (uv.y >= 0.0)
    {
        // Add water ripples...
        d = (3.0-pos.y) / -uv.y;
       
        vec2 wat = (dir * d).xz-pos.xz;
        d += 1.*sin(wat.x + time);
        wat = (dir * d).xz-pos.xz;
        wat = wat * 0.1 + 0.2* texture2D(iChannel0, wat, 0.0).xy;
       
        i = texture2D(iChannel3, wat, 0.0).x;
       
        col += vec3(i) * max(2./-d, 0.0);
    }
    else       
    {
        // Do floor stuff...
        d = (-3.0-pos.y) / uv.y;
        vec2 coord = pos.xz+(dir.xz * d);
        vec3 sand = texture2D(iChannel3, coord* .1).rgb * 1.5  +
                    texture2D(iChannel3, coord* .23).rgb;
        sand *= 0.5;
       
        float f = ((-uv.y-0.3 +sin(time*0.1)*0.2)*2.45) * .4;
        f = clamp(f, 0.0, 1.0);
       
        col = mix(col, sand, f);
    }

    float hit = 0.0;
    vec4 loc = Trace(pos, dir, hit);
    if (hit > 0.0)
    {
        vec3 norm = GetNormal(loc.xyz);
        vec3 foundColor = GetColour(loc, norm, pos, dir);
        vec3 backgroundColor = col;
   
        // total water reflection
        float facing = -dot(norm,dir);
        float upfacing = clamp(norm.y, 0.,1.);
        float fresnel = 1.0-facing;
        fresnel = clamp(pow(fresnel, 1.0), 0.0,1.0);
        foundColor = mix(foundColor, backgroundColor*2.0, 0.5 * (0.5 + upfacing*upfacing) * fresnel);
       
        // atmos
        float dis = length(pos-loc.xyz);
        float fogAmount = clamp(max((dis-.5),0.0)/MAXDIST, 0.0, 1.0);
       
        col = mix(foundColor, backgroundColor, fogAmount );
    }
   
    // Contrast, saturation and brightness...
    col = csb(col, 1.1, 1.05, 1.22);
   
    // Fade in...
    //col *= smoothstep( 0.0, 2.5, iGlobalTime );
    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/tex03.jpg")
tex3 = moon3d.image.load2d("./data/tex02.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, tex3, 3)

moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/Manta Ray", 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>



85
English forum / Heartwing Angel converted
« on: May 31, 2015, 02:22:33 PM »
Heartwing Angel converted to GLSL Hacker format

Copy the code and save as Heartwing_Angel_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Heartwing Angel"
          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/4l23zc

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;



//

// @christinacoffin
// 2015-05-07: 1st version, need to optim and do some proper AA

vec3 JuliaFractal(vec2 c, vec2 c2, float animparam, float anim2 ) {   
    vec2 z = c;
   
    float ci = 0.0;
    float mean = 0.0;
   
    for(int i = 0;i < 64; i++)
    {
        vec2 a = vec2(z.x,abs(z.y));
       
        float b = atan(a.y*(0.99+animparam*9.0), a.x+.110765432+animparam);
       
        if(b > 0.0) b -= 6.303431307+(animparam*3.1513);
       
        z = vec2(log(length(a*(0.98899-(animparam*2.70*anim2)))),b) + c2;

        if (i>0) mean+=length(z/a*b);

        mean+=a.x-(b*77.0/length(a*b));

        mean = clamp(mean, 111.0, 99999.0);
    }
   
    mean/=131.21;
    ci =  1.0 - fract(log2(.5*log2(mean/(0.57891895-abs(animparam*141.0)))));

    return vec3( .5+.5*cos(6.*ci+0.0),.5+.75*cos(6.*ci + 0.14),.5+.5*cos(6.*ci +0.7) );
}


void main()
{
    float animWings = 0.004 * cos(iGlobalTime*0.5);
    float animFlap = 0.011 * sin(iGlobalTime*1.0);   
    float timeVal = 56.48-20.1601;
    vec2 uv = gl_FragCoord.xy - iResolution.xy*.5;
    uv /= iResolution.x*1.5113*abs(sin(timeVal));
    uv.y -= animWings*5.0;
    vec2 tuv = uv*125.0;
    float rot=3.141592654*0.5;
 
    uv.x = tuv.x*cos(rot)-tuv.y*sin(rot);
    uv.y =1.05* tuv.x*sin(rot)+tuv.y*cos(rot);
    float juliax = tan(timeVal) * 0.011 + 0.02/(gl_FragCoord.y*0.19531*(1.0-animFlap));
    float juliay = cos(timeVal * 0.213) * (0.022+animFlap) + 5.66752-(juliax*1.5101);//+(gl_FragCoord.y*0.0001);// or 5.7
   
 
    float tapU = (1.0/ float(iResolution.x))*25.5;//*cos(animFlap);
    float tapV = (1.0/ float(iResolution.y))*25.5;//*cos(animFlap);
   
 
    gl_FragColor = vec4( JuliaFractal(uv+vec2(0.0,0.0), vec2(juliax, juliay), animWings, animFlap ) ,1.0);
   
    gl_FragColor += vec4( JuliaFractal(uv+vec2(tapU,tapV), vec2(juliax, juliay), animWings, animFlap ) ,1.0);
//    gl_FragColor += vec4( JuliaFractal(uv+vec2(tapU,-tapV), vec2(juliax, juliay), animWings, animFlap ) ,1.0);
//    gl_FragColor += vec4( JuliaFractal(uv+vec2(-tapU,tapV), vec2(juliax, juliay), animWings, animFlap ) ,1.0);
    gl_FragColor += vec4( JuliaFractal(uv+vec2(-tapU,-tapV), vec2(juliax, juliay), animWings, animFlap ) ,1.0); 
    gl_FragColor *= 0.3333;
   
    gl_FragColor.xyz = gl_FragColor.zyx;
    gl_FragColor.xyz = vec3(1)-gl_FragColor.xyz;

}

//

]]></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/Heartwing Angel", 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>



86
English forum / Physically based rendering test converted
« on: May 31, 2015, 02:09:41 PM »
Physically based rendering test converted to GLSL Hacker format

Copy the code and save as pbr_test_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Physically based rendering test"
          width="800" height="600"
          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/MlB3DV

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;



//

/*
* References :
*
* http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b_notes.pdf
*
* http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
*
* http://graphicrants.blogspot.fr/2013/08/specular-brdf-reference.html
*
* http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
*
* http://blog.selfshadow.com/publications/s2013-shading-course/#course_content
*
*    Ray marching code from iq
*/


#define NB_LIGHTS 3

// Metals values in linear space
#define GOLD vec3(1.0, 0.71, 0.29)
#define COPPER vec3(0.95, 0.64, 0.54)
#define IRON vec3(0.56, 0.57, 0.58)
#define ALUMINIUM vec3(0.91, 0.92, 0.92)
#define SILVER vec3(0.95, 0.93, 0.88)

float time = 0.25*iGlobalTime;

float fPlane( vec3 p, vec4 n )
{
  // n must be normalized
  return dot(p,n.xyz) + n.w;
}

float fSphere( vec3 p, float s )
{
    return length(p)-s;
}
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;
}
// ---- Scene definition
vec2 fScene(vec3 p) {
   
    vec3 pSphere = p/*opRep(p, vec3( 2.0, 0.0, 2.0))*/;
   
     vec2 sphere0 = vec2(fSphere(p, 1.0), 0.5);     
    vec2 sphere1 = vec2(fSphere(p+vec3(2.1, 0.0, 2.0), 1.0), 2.5);
    vec2 sphere2 = vec2(fSphere(p+vec3(-2.1, 0.0, 2.0), 1.0), 3.5);
    vec2 sphere3 = vec2(fSphere(p+vec3(2.1, 0.0, -2.0), 1.0), 4.5);
    vec2 sphere4 = vec2(fSphere(p+vec3(-2.1, 0.0, -2.0), 1.0), 5.5);
   


    vec2 plane = vec2(fPlane(p, vec4(0, 1, 0, 1.0)), 1.5);
   
    return opU(opU(opU(opU(opU(plane, sphere0), sphere1), sphere2), sphere3), sphere4);
}
// -----

vec2 castRay( in vec3 ro, in vec3 rd )
{
    float tmin = 1.0;
    float tmax = 100.0;
   
   
    float precis = 0.00001;
    float t = tmin;
    float m = -1.0;
    for( int i=0; i<50; i++ )
    {
        vec2 res = fScene( 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 = fScene( 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(
        fScene(pos+eps.xyy).x - fScene(pos-eps.xyy).x,
        fScene(pos+eps.yxy).x - fScene(pos-eps.yxy).x,
        fScene(pos+eps.yyx).x - fScene(pos-eps.yyx).x );
    return normalize(nor);
}


struct Light {
     vec3 pos;
    vec3 color;
};
Light lights[NB_LIGHTS];


float G1V ( float dotNV, float k ) {
    return 1.0 / (dotNV*(1.0 - k) + k);
}

vec3 computePBRLighting ( in Light light, in vec3 position, in vec3 N, in vec3 V, in vec3 albedo, in float roughness, in vec3 F0 ) {

    float alpha = roughness*roughness;
    vec3 L = normalize(light.pos.xyz - position);
    vec3 H = normalize (V + L);

    float dotNL = clamp (dot (N, L), 0.0, 1.0);
    float dotNV = clamp (dot (N, V), 0.0, 1.0);
    float dotNH = clamp (dot (N, H), 0.0, 1.0);
    float dotLH = clamp (dot (L, H), 0.0, 1.0);

    float D, vis;
    vec3 F;

    // NDF : GGX
    float alphaSqr = alpha*alpha;
    float pi = 3.1415926535;
    float denom = dotNH * dotNH *(alphaSqr - 1.0) + 1.0;
    D = alphaSqr / (pi * denom * denom);

    // Fresnel (Schlick)
    float dotLH5 = pow (1.0 - dotLH, 5.0);
    F = F0 + (1.0 - F0)*(dotLH5);

    // Visibility term (G) : Smith with Schlick's approximation
    float k = alpha / 2.0;
    vis = G1V (dotNL, k) * G1V (dotNV, k);

    vec3 specular = /*dotNL **/ D * F * vis;

    vec3 ambient = vec3(.01);

    float invPi = 0.31830988618;
    vec3 diffuse = (albedo /** invPi*/);


    return ambient + (diffuse + specular) * light.color.xyz * dotNL ;
}

vec3 addPBR( in vec3 position, in vec3 N, in vec3 V, in vec3 baseColor, in float metalMask, in float smoothness, in float reflectance) {
    vec3 color = vec3(0.0);

    float roughness = 1.0 - smoothness*smoothness;
    vec3 F0 = 0.16*reflectance*reflectance * (1.0-metalMask) + baseColor*metalMask;
    vec3 albedo = baseColor;
   
    float s = 0.0;
   
   
    for ( int i = 0; i < NB_LIGHTS; ++i ) {
        vec3 col = computePBRLighting ( lights[i], position, N, V, albedo, roughness, F0);
        color += col;   
        s += softshadow( position, normalize(lights[i].pos.xyz - position), 0.02, 2.5 );
    }

    return color*s;
}

vec3 render( in vec3 ro, in vec3 rd )
{
    vec3 col = vec3(0.8, 0.9, 1.0)*8.0; // Sky color
   
    vec2 res = castRay( ro, rd );
    float t = res.x;
    float m = res.y;
    vec3 p = ro + t*rd;
   
    if(m>-0.5) { // Intersection found
        if( m < 1.0 ) {
           // float f = mod( floor( 5.0*p.z ) + floor( 5.0*p.x ), 2.0 );
            vec3 sur = vec3(1.0,1.0,1.0)*smoothstep(-1.0,-0.6,sin(16.0*p.x));
            col = addPBR( p, calcNormal( p ), -rd, GOLD*sur, sur.x, 0.3+0.6*sur.x, 0.5 );
        }
        else if( m < 2.0 ) {
            float f = mod( floor( 5.0*p.z ) + floor( 5.0*p.x ), 2.0 );
            col = addPBR(p, calcNormal( p ), -rd, vec3(0.5), 0.0, 0.3+0.6*f, 0.5 );
        }
        else if( m < 3.0 ) {
            vec3 sur = vec3(1.0,1.0,1.0)*smoothstep(-1.0,-0.4,sin(18.0*p.x));
            col = addPBR( p, calcNormal( p ), -rd, COPPER*sur, sur.x, 0.3+0.6*sur.x, 0.5 );
        }
        else if( m < 4.0 ) {
            vec3 sur = vec3(1.0,1.0,1.0)*smoothstep(-1.0,-0.0995,sin(106.0*p.x))*smoothstep(-1.0,-0.9,sin(47.0*p.z));
            col = addPBR( p, calcNormal( p ), -rd, vec3(0.2), 1.0-sur.x, 0.9*sur.x, 0.5 );
        }
        else if( m < 5.0 ) {
            vec3 sur = vec3(1.0)*smoothstep(-1.0,-0.765,sin(24.0*p.x))*smoothstep(-1.0,-0.4,sin(70.9*p.z));
            col = addPBR( p, calcNormal( p ), -rd, GOLD*(1.0-sur), sur.x, 0.3+0.6*sur.x, 0.5 );
        }
        else if( m < 6.0 ) {
            vec3 sur = vec3(1.0,1.0,1.0)*smoothstep(-1.0,-0.4,sin(18.0*p.x));
            col = addPBR( p, calcNormal( p ), -rd, ALUMINIUM*sur, sur.x, 0.3+0.6*sur.x, 0.5 );
        }
    }
   
    return col;
}

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 );
}

vec4 hejlToneMapping (in vec4 color) {
     vec4 x = max(vec4(0.0), color-vec4(0.004));
    return (x * ((6.2*x)+vec4(0.5))) / max(x * ((6.2*x)+vec4(1.7))+vec4(0.06), vec4(1e-8));
}

void main()
{
   
   
    lights[0] = Light(vec3(0.0, 5.0, .0), vec3(1.0));   
    lights[1] = Light(vec3(12.0*sin(iGlobalTime), 8.0, 12.0*cos(iGlobalTime)), vec3(1.0));       
    lights[2] = Light(vec3(-12.0*cos(-iGlobalTime), 8.0, 12.0*sin(-iGlobalTime)), vec3(.05));   

   

    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;
         
   

    // camera   
    vec3 ro = vec3( 7.0*sin(time), 3.6 , -7.0*cos(time) );
    vec3 ta = vec3( 0.0 );
   
    // 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 );

    #if 0
        col = pow( col, vec3(0.4545) );
        gl_FragColor=vec4( col, 1.0 );
    #else
        float exposure = 0.032 + 0.023*sin(time-3.14);
           gl_FragColor = hejlToneMapping(vec4(col, 1.0) * exposure) ;
    #endif
}

//

]]></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/Physically based rendering test", 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>


87
English forum / Hyper dodecahedron converted
« on: May 31, 2015, 02:02:26 PM »
Hyper dodecahedron converted to GLSL Hacker format.

Looks best in a square window.

Copy the code and save as Hyper_dodecahedron_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Hyper dodecahedron"
          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/4lS3DK

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;



//

//---------------------------------------------------------
// Shader:   HyperDodecahedron.glsl 
// original: 'Famous solid' by nimitz (@stormoid)
//           https://www.shadertoy.com/view/ltlGWM
// modified: use mouse to select different shape types now
// tags:     hyperbolic, dodecahedron, kaleidoscope, raymarcher
//---------------------------------------------------------
/*
    Quick laydown of what's going on:
        -knighty's folding technique to get dodecahedron distance (see: https://www.shadertoy.com/view/XlX3zB)
        -Linear extrapolation of sphere to "hyberbolize" the dodecahedron
        -Fold symmetries are used to displace, shade and color
        -Cheap analytic curvature for shading (see: https://www.shadertoy.com/view/Xts3WM)
        -Wave noise for bump mapping (generalized triangle noise: https://www.shadertoy.com/view/XtX3DH)
        -eiffie's auto-overstep raymarching method: https://www.shadertoy.com/view/ldSSDV
        -Lighting mostly from iq
*/

#define ROTATE true
#define ITR 120
#define FAR 7.
#define time iGlobalTime
#define TYPES 5.

int solidType = 2;   // use 0 to 4 for starting shape.

mat2 mm2(in float a){float c = cos(a), s = sin(a);return mat2(c,-s,s,c);}

vec3 fold(in vec3 p)
{
    const vec3 nc = vec3(-0.5,-0.809017,0.309017);
    for(int i=0;i<5;i++)
    {
        p.xy = abs(p.xy);
        float t = 2.*min(0.,dot(p,nc));
        p -= t*nc;
    }
    return p;
}

float smax(float a, float b)
{
    const float k = 2.;
    float h = 1.-clamp(.5 + .5*(b-a)/k, 0., 1.);
    return mix(b, a, h) - k*h*(1.0-h);
}

float tri(in float x){return abs(fract(x)-0.5)*2.;}

float map(in vec3 p)
{
    vec3 fp = fold(p) - vec3(0.,0.,1.275);
    float d = mix(dot(fp,vec3(.618,0,1.)), length(p)-1.15,-3.6);
   
    if (solidType == 1)
    {
      d += tri(fp.x*8.+fp.z*3.)*0.05+tri(fp.x*fp.y*40.+time*0.2)*0.07-0.17;
      d += tri(fp.y*5.)*0.04;
      d *= 0.9;
    }
    else if (solidType == 2)
    {
      d *= 0.7;
      d += sin(time+fp.z*5.+sin(fp.x*20.*fp.y*8.)+1.1)*0.05-0.08;
      d += sin(fp.x*20.*sin(fp.z*8.+time*0.2))*0.05;
      d += sin(fp.x*20.*sin(fp.z*8.-time*0.3)*sin(fp.y*10.))*0.05;
    }
    else if (solidType == 3)
    {
      d = smax(d+.5, -(d+sin(fp.y*20.+time+fp.z*10.)+1.5)*0.3)*.55;
      d += sin(max(fp.x*1.3,max(fp.z*.5,fp.y*1.))*35.+time)*0.03;
    }
    else if (solidType == 4)
      d = smax(d+.5, -(d+sin(fp.z*10.+sin(fp.x*20.*fp.y*9.)+1.1)*0.3-0.3))*.5;
    else
    {
      d = smax(d+.2, -(d+cos(fp.z*13.+cos(fp.x*18.*fp.y*2.)+2.1)*0.5-0.5))*.8;
      d += tri(fp.x*3.+fp.z*6.)*0.1+tri(fp.x*fp.y*4.+time*0.2)*0.1-0.17;
      d *= 0.5;
    }
   
    return d*0.25;
}

float march(in vec3 ro, in vec3 rd)
{
    float t=0.,stp=0.0,os=0.0,pd=10.0, d =0.;
    for(int i=0;i<ITR;i++)
    {
        t+=stp;
        d=map(ro+rd*t);
        if (t>FAR || abs(d) <0.0005)break;
        if(d>=os)
        {       
            os=.9*d*d/pd;
            stp=d+os;
            pd=d;
        }
        else
        {
            stp=-os;
            pd=1.;
            os=.001;
        }
    }
    return t;
}

vec3 normal(in vec3 p)

    vec2 e = vec2(-1., 1.)*0.0001;
    return normalize(e.yxx*map(p + e.yxx) + e.xxy*map(p + e.xxy) +
                     e.xyx*map(p + e.xyx) + e.yyy*map(p + e.yyy) );   
}

//Cheap analytic curvature: https://www.shadertoy.com/view/Xts3WM
float curv(in vec3 p)
{
    vec2 e = vec2(-1., 1.)*0.03;
   
    float t1 = map(p + e.yxx), t2 = map(p + e.xxy);
    float t3 = map(p + e.xyx), t4 = map(p + e.yyy);
   
    return .15/(e.x*e.x) *(t1 + t2 + t3 + t4 - 4. * map(p));
}

float wav(in float x){return sin(x*6.283)*0.25+0.25;}
vec2 wav2(in vec2 p){return vec2(wav(p.x+wav(p.y*1.5)),wav(p.y+wav(p.x*1.5)));}

float wavenoise(in vec2 p)
{
    float z=2.;
    float z2=1.;
    float rz = 0.;
    vec2 bp = p;
    rz+= (wav(-time*0.5+p.x*(sin(-time)*0.3+.9)+wav(p.y-time*0.2)))*.7/z;
    for (float i=0.; i<=3.; i++ )
    {
        vec2 dg = wav2(bp*2.)*.8;
        dg *= mm2(time*.2);
        p += dg/z2;

        bp *= 2.4;
        z2 *= 1.05;
        z *= 2.4;
        p *= 1.4;
       
        rz+= (wav(p.x+wav(p.y)))/z;
    }
    return rz;
}

vec3 tex(in vec3 p)
{   
    float rz;
    vec3 col;
    if (solidType == 1)
    {
        rz= p.y*15.+p.x*30.+p.z*5.;
        col = (sin(vec3(.7,2.,.1-rz*0.2)+rz*.1+0.45))*0.5+0.5;
    }
    else if (solidType == 2)
    {
        rz= (sin(p.x*0.+p.z*20.)-p.y*20.);
        col = (sin(vec3(2.1,.7,.1)+rz*.09+4.15))*0.5+0.5;
    }
    else if (solidType == 3)   
    {
        rz= sin(p.z*3.+p.x*6.)*0.5+0.5;
        col = mix(vec3(.7,0.1,0.),vec3(1,.5,0.4),rz)*0.5+0.05;
    }
    else if (solidType == 4)
    {
        rz= p.z*13.+p.x*30.;
        col = (sin(vec3(2.2,.7,.1)+rz*.1+4.2))*1.3+1.3;
    }
    else
    {
        rz= sin(p.z*13.) + p.x*23.;
        col = (sin(vec3(0.2,.9,.5)+rz*0.4+2.2))*1.1+1.1;
    }
    return col;
}

//Bump mapping
float bumptex(in vec3 p)
{
    if      (solidType == 1) return wavenoise(mix(p.zy,p.yx,1.)*0.55);
    else if (solidType == 2) return wavenoise(mix(p.yz,p.xy,.5)*0.55);
    else if (solidType == 3) return wavenoise(mix(p.zy,p.xy,.5)*0.44);
    else if (solidType == 4) return wavenoise(mix(p.zy,p.xy,.1)*0.55);
    else                     return wavenoise(mix(p.zy,p.xy,.2)*0.50);
}

vec3 bump(in vec3 p, in vec3 n)
{
    vec2 e = vec2(.01,0);
    float n0 = bumptex(p);
    vec3 d = vec3(bumptex(p+e.xyy)-n0, bumptex(p+e.yxy)-n0, bumptex(p+e.yyx)-n0)/e.x;
    n = normalize(n-d*.3);
    return n;
}

float shadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
{
    float res = 1.0;
    float t = mint;
    for( int i=0; i<15; i++ )
    {
        float h = map(ro + rd*t);
        res = min( res, 4.*h/t );
        t += clamp( h, 0.01, .1 );
        if(h<0.001 || t>tmax) break;
    }
    return clamp( res, 0.0, 1.0 );
}

float ao( 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 );
        occ += -(dd-hr)*sca;
        sca *= .95;
    }
    return clamp( 1.0 - 3.0*occ, 0.0, 1.0 );   
}

vec3 rotx(vec3 p, float a)
{
    float s = sin(a), c = cos(a);
    return vec3(p.x, c*p.y - s*p.z, s*p.y + c*p.z);
}
vec3 roty(vec3 p, float a)
{
    float s = sin(a), c = cos(a);
    return vec3(c*p.x + s*p.z, p.y, -s*p.x + c*p.z);
}

void main()
{   
    vec2 q = gl_FragCoord.xy / iResolution.xy;
    vec2 p = q-0.5;
    float ratio = iResolution.x / iResolution.y;
    p.x *= ratio;
    vec2 mo = iMouse.xy / iResolution.xy*1.5 -.75;
    mo.x *= ratio;
    if (ROTATE)
        mo += vec2(time*0.03, time*0.004);
    solidType = int( iMouse.x / iResolution.x * TYPES);
   
    vec3 ro = vec3(.0,0.0,-6.5);
    vec3 rd = vec3(p,1.2);
    ro = rotx(ro, -mo.y*3.0);ro = roty(ro, mo.x*3.0);
    rd = rotx(rd, -mo.y*3.0);rd = roty(rd ,mo.x*3.0);
   
    float rz = march(ro,rd);
    vec3 col = vec3(0.9);
   
    if ( rz < FAR )
    {
        //setup
        vec3 pos = ro+rz*rd;
        float crv= curv(pos);
        vec3 nor = normal(pos);
           vec3 fpos = fold(pos);
        vec3 lgt = normalize(vec3(.0, 1., 0.9));
        float shd = shadow( pos, lgt, 0.02, 3.0 );
        nor = bump(fpos, nor);
       
        //components
        float dif = max(dot(nor,lgt),0.0)*shd;
        float bac = max(0.2 + 0.8*dot(nor,vec3(-lgt.x,lgt.y,-lgt.z)),0.0);
        float fre = clamp(pow(1.0+dot(nor,rd),3.),0.,10.)*shd;
        vec3 haf = normalize(lgt - rd);
        float spe = pow(clamp(dot(nor,haf),0.0,1.0),50.0)*shd;
        float occ= crv*0.25+0.75;
       
        //compose
        col  = 0.2*occ + dif*vec3(1.0,0.8,0.6)
            + 0.4*bac*vec3(1.0)*occ;
        col *= 0.5*pow(tex(fpos),vec3(.5));
        col += .4*fre*vec3(1.0) + .35*spe*vec3(1.0);
        col *= ao(pos,nor);
        col = pow(col,vec3(.75))*1.3;
    }
   
    //vignetting from iq
    col *= pow( 16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y), 0.12 )*0.8+0.4;
   
    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/Hyper dodecahedron", 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>


88
English forum / Anti menger sphere sponge converted
« on: May 31, 2015, 01:51:31 PM »
Anti menger sphere sponge converted to GLSL Hacker format

I changed iResolution a bit.

Move mouse to lower right corner if you see only the checker board.

Copy the code and save as Anti_menger_sphere_sponge_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Anti menger sphere sponge"
          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/MtBGWK

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;



//


//---------------------------------------------------------
// Shader:   RayMarchingPrimitivesV2.glsl
// original: https://www.shadertoy.com/view/Xds3zN   colored
//           http://glslsandbox.com/e#20839          gray scaled
// 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 (animated), 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
//---------------------------------------------------------

#ifdef GL_ES
precision highp float;
#endif

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

#define ANIMATE true
#define ROTATE true
#define flag true

float aTime = 0.0;
float sinTime = 0.0;
//---------------------------------------------------------
vec3 rotateX(vec3 p, float a)
{
  float sa = sin(a);
  float ca = cos(a);
  return vec3(p.x, ca * p.y - sa * p.z, sa * p.y + ca * p.z);
}
vec3 rotateY(vec3 p, float a)
{
  float sa = sin(a);
  float ca = cos(a);
  return vec3(ca * p.x + sa * p.z, p.y, -sa * p.x + ca * p.z);
}
vec3 rotateZ(vec3 p, float a)
{
  float sa = sin(a);
  float ca = cos(a);
  return vec3(ca * p.x - sa * p.y, sa * p.x + ca * p.y, p.z);
}

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

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

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

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

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

float sdWaveSphere(vec3 p, float radius, int waves, float waveSize)
{
  // deformation of radius
  float d = waveSize*(radius-length(p.y));
//  float d = waveSize*(radius*radius-(p.y*p.y));
  radius += d * cos(atan(p.x,p.z) * float(waves));
  return length(p) - radius;
}

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;
}

// t.x = torus radius,  t.y = ring radius
float sdTorus( vec3 p, vec2 t )
{
  return length(vec2(length(p.xz)-t.x, p.y)) - t.y;
}

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 sdBlob (in vec3 pos, in float r)
{
  vec3 v1 = pos * 6.0;
  return 0.05*(r + 0.5* (length(dot(v1, v1)) -0.51*(cos(4.*v1.x) +cos(4.*v1.y) +cos(4.*v1.z))));
}

// Capsule:  a,b = end points, r = cylinder radius
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;
}

// Triangle prism:
float sdTriPrism( vec3 p, float radius, float height )
{
  vec3 q = abs(p);
  #ifdef flag
    return max(q.z-height, max(q.x*0.866025 +p.y*0.5, -p.y) - radius*0.5);
  #else
    float d1 = q.z-height;
    float d2 = max(q.x*0.866025+p.y*0.5, -p.y) - radius*0.5;
    return length(max(vec2(d1, d2), 0.0)) + min(max(d1, d2), 0.0);
  #endif
}

// hexagonal prism:r
float sdHexPrism( vec3 p, float radius, float height)
{
  vec3 q = abs(p);
  #ifdef flag
    return max(q.z-height, max((q.x*0.866025 +q.y*0.5), q.y) - radius);
  #else
    float d1 = q.z-heighty;
    float d2 = max((q.x*0.866025 +q.y*0.5), q.y)-radius;
    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 sdCylinder( vec3 p, vec3 h )
{
  return length(p.xz - h.xy) - h.z;
}
// h.xy = base rectangle size,  h.z = height
float sdCylinder6( vec3 p, vec3 h )
{
  return max( length6(p.xz) - h.x, abs(p.y) - h.z );
}

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
}

//----------------------------------------------------------------------
// distance operations
//----------------------------------------------------------------------

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

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

//----------------------------------------------------------------------
// domain operations
//----------------------------------------------------------------------

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

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

//----------------------------------------------------------------------
// sphere cutted out from a rounded box
//----------------------------------------------------------------------
float sdBoxMinusSphere( in vec3 pos, in float radius )
{
  return opS( udRoundBox( pos, vec3(0.15), 0.05)
            , sdSphere(   pos, radius - 0.012 + 0.02*sinTime));
}
//----------------------------------------------------------------------
// rack-wheel with holes
//----------------------------------------------------------------------
float sdRackWheel( in vec3 pos)
{
  return 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 + 0.1*aTime,
                                     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)
                       )
            );
}
//----------------------------------------------------------------------
float sdBallyBall( in vec3 pos)
{
  return 0.7 * sdSphere(pos, 0.2 )
         + 0.03*sin(50.0*pos.x)*sin(50.0*pos.y+8.0*aTime)*sin(50.0*pos.z);
}
//----------------------------------------------------------------------
float sdTwistedTorus( in vec3 pos, float angle)
{
  return 0.5*sdTorus( opTwist(pos,angle), vec2(0.20, 0.05));
}
//----------------------------------------------------------------------
// animated fractal Anti sphere sponge
float AntiSphereSponge(vec3 w)
{
  const int ITER = 10;
  float sphereHoles = 8.0 + 5.*sin(0.4123*aTime);
  float sphereScale = 1.5 + 0.2*sin(0.345*aTime);
  float scale = 1.5;
  float k = scale*.5;
  float d = 10000.0;
  float r, d1;
  float sph=length(w * vec3(0.8, 0.8, 0.5)) - 0.6 ;
 
  if ( sph < .1)
  for (int i = 0; i < ITER; i++)
  {
    vec3 zz = mod(w * k, sphereHoles) - vec3(0.5 * sphereHoles);
    r = length(zz);
    d1 = -(sphereScale - r) / k;
    k *= scale;
    d = min(d, d1);
  }
    else d = 0.;
  d = max(d,sph);
  return d;
}
//----------------------------------------------------------------------
vec2 map( in vec3 pos )
{
  vec3 r1, r2;
  float sphy = 0.35 + 0.1 * sinTime;
  vec3 sp = pos - vec3( 1.0, sphy, 0.0);
  vec2 res = vec2( sdPlane( pos), 1.0 );
  float color = 46.9 + 40.0 * cos(0.2 * iGlobalTime);
  res = opU(res,vec2(AntiSphereSponge(pos - vec3(0.0, 0.7, 0.0)), color));
  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<14; 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 )
{
  aTime = ANIMATE ? iGlobalTime : 0.0;
  sinTime = sin(aTime);
  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.005*t*t ) );
  }
  return vec3( clamp(col, 0.0, 1.0) );
}


void main()
{
    vec2 p = 1.2*(gl_FragCoord.xy / iResolution.xy) - 0.6;
  p.x *= 0.5 * iResolution.x / iResolution.y;

  // camera 
  float angle = ROTATE ? 0.02*iGlobalTime : 0.0;
  float rx = 0.5 + 3.0*cos(angle + 6.0*iMouse.x);
  float rz = 0.5 + 3.0*sin(angle + 6.0*iMouse.x);
  vec3 ro = vec3( rx, 1.0 + 1.0*iMouse.y, rz );
  vec3 ta = vec3( 0.0, 0.5, 0.0 );

  // camera tx
  vec3 cw = normalize( ta-ro );
  vec3 cp = vec3( 0.0, 1.0, 0.0 );
  vec3 cu = normalize( cross(cw, cp) );
  vec3 cv = normalize( cross(cu, cw) );
  vec3 rd = normalize( p.x*cu + p.y*cv + 3.0*cw );

  // pixel color
  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/Anti menger sphere sponge", 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>


89
3D-Tech News Around The Web / (DemoScene) Decrunch 2015
« on: May 30, 2015, 09:14:15 PM »
Decrunch 2015 at pouet and demozoo

All about Amiga and C64 - invitation in JS


90
English forum / AncientMars converted
« on: May 30, 2015, 09:07:56 PM »
AncientMars converted to GLSL Hacker format

Copy the code and save as AncientMars_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/AncientMars"
          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/Mtj3DG

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;



//

// Ancient Ruins
// Scene from Karla Quintero's modern dance performance "If Mars"
//
// Mashup of heavy RMF, Kali's fractal (and stars I believe) and Nimitz's fog trick.
// Added IQ's noise for posting on shadertoy.
// Apologies for the brute force detail and hence slowness.
//
// @rianflo


float smin(float a, float b, float k)
{
    return -(log(exp(k*-a)+exp(k*-b))/k);
}

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

#if 1
float noise( in vec3 x )
{
    vec3 p = floor(x);
    vec3 f = fract(x);
    f = f*f*(3.0-2.0*f);
   
    vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;
    vec2 rg = texture2D( iChannel0, (uv+ 0.5)/256.0, -100.0 ).yx;
    return mix( rg.x, rg.y, f.z );
}
#else
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;
    return 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);
}
#endif
mat3 rotationMatrix(vec3 axis, float angle)
{
    axis = normalize(axis);
    float s = sin(angle);
    float c = cos(angle);
    float oc = 1.0 - c;
   
    return mat3(oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,
                oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,
                oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c);
}


const float PI = 3.1415926535897932384626433832795;


// ----------------------------------------------------------EDIT ME----------------------------------------------------------------------
float rmf(vec3 p)
{
    float signal = 0.0;
    float value  = 0.0;
    float weight = 1.0;
    float h = 1.0;
    float f = 1.0;

    for (int curOctave=0; curOctave < 11; curOctave++)
    {
        signal = noise(p)*2.0-0.4;
        signal = pow(1.0 - abs(signal), 2.0) * weight;
        weight = clamp(0.0, 1.0, signal * 16.0);
        value += (signal * pow(f, -1.0));
        f *= 2.0;
        p *= 2.0;
    }
   
    return (value * 1.25) - 1.0;
}

const int Iterations=15;

const float Scale=2.1;

float de(vec3 pos)
{
    vec3 p=pos;
    p.y +=4.76-iGlobalTime*0.005;
    p.xz=abs(.5-mod(pos.xz,1.))+.01;
    float DEfactor=1.;
    float ot=1000.;
    for (int i=0; i<Iterations; i++)
    {
        p = abs(p)-vec3(0.,2.,0.); 
        float r2 = dot(p, p);
        ot = min(ot,abs(length(p)));
        float sc=Scale/clamp(r2,0.4,1.);
        p*=sc;
        DEfactor*=sc;
        p = p - vec3(0.5,1.,0.5);
    }
    float rr=length(pos+vec3(0.,-3.03,1.85))-.017;
    float d=length(p)/DEfactor-.0005;
   
    return d;
}

float sdf(vec3 p)
{
    float sd = p.y;
   
   
    sd = smin(sd, de(p), 60.0);
    //sd = min(sd, length(p)-1.0-rmf(p+time*0.01, 8.0, 1.8, coneR)*0.06);
    sd -= rmf(p*8.0+2.0)*0.015;       // ceiling
   
    return sd;
}

vec4 getColorAndRoughness(vec3 p, vec3 N, float ambo)
{
    return vec4(1.0);
}

vec3 grad(vec3 p, float coneR)
{
    coneR*=3.0;
    vec3 f = vec3(sdf(p));
    vec3 g = vec3(sdf(p+vec3(coneR, 0.0, 0.0)),
                  sdf(p+vec3(0.0, coneR, 0.0)),
                  sdf(p+vec3(0.0, 0.0, coneR)));
    return (g-f) / coneR;
}

vec3 setupRayDirection(float camFov)
{
    vec2 coord = vec2(gl_FragCoord.xy);
    vec2 v = vec2(coord / iResolution.xy) * 2.0 - 1.0;
    float camAspect = iResolution.x/iResolution.y;
    float fov_y_scale = tan(camFov/2.0);
    vec3 raydir = vec3(v.x*fov_y_scale*camAspect, v.y*fov_y_scale, -1.0);
    return normalize(raydir);
}

float ambientOcclusion( in vec3 pos, in vec3 nor, float coneR )
{
  float occ = 0.0;
  float sca = 1.1;
  for ( int i=0; i<5; i++ )
  {
    float hr = 0.02 + 0.11*float(i) / 4.0;
    vec3 aopos =  nor * hr + pos;
    float dd = sdf(aopos);
    occ += -(dd-hr)*sca;
    sca *= 0.95;
  }
  return clamp( 1.0 - 1.5*occ, 0.0, 1.0 );
}


vec3 shade(vec3 ro, vec3 rd, float t, float coneR, vec3 ld)
{
    vec3 g = grad(ro+rd*t, coneR);
    vec3 N = normalize(g);
    float ambo = ambientOcclusion(ro+rd*t, N, coneR);
    float ndl = clamp(dot(N, ld), 0.0, 1.0);
    vec3 color = mix(vec3(0.782, 0.569, 0.45), vec3(0.8, 0.678, 0.569), clamp(1.5-length(g), 0.0, 1.0));
    return vec3(mix(ambo*color, ambo*color*ndl, 0.5));
}

float fogmap(in vec3 p, in float d)
{
    vec3 q = p;
    q.z-=0.0;
    p.x -= iGlobalTime*0.05;
    vec3 turb = vec3(noise(80.0*p.xyz+iGlobalTime*0.51)*0.5, noise(160.0*p.xzy+iGlobalTime*0.2)*0.3, noise(60.0*p.zyx+iGlobalTime*0.1)*0.2);
    p += turb;
    float fog = (max(noise(p*64.0+0.1)-0.1, 0.0)*noise(p*16.0))*0.03;
   
    return fog;
}


#define iterations 14
#define formuparam 0.530

#define volsteps 3
#define stepsize 0.2

#define zoom   1.20
#define tile   0.850
#define speed  0.1

#define brightness 0.0015
#define darkmatter 0.400
#define distfading 0.160
#define saturation 0.400

vec3 space(vec2 uv)
{
    vec3 v=vec3(0.4);
    vec3 dir=vec3(uv*zoom,1.);
   
    //float a2=2.0;
    float a1=4.0;//+time*0.001;
    mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));
    mat2 rot2=rot1;//mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
    dir.xz*=rot1;
    dir.xy*=rot2;
   
    //from.x-=time;
    //mouse movement
    vec3 from=vec3(170.0, 170.2,0.01);
    from+=vec3(0.0,0.0,-2.);
   
    //from.x-=iMouse.x;
    //from.y-=iMouse.y;
   
    from.xz*=rot1;
    from.xy*=rot2;
   
    //volumetric rendering
    float s=.4,fade=.2;
   
   
    for (int r=0; r<volsteps; r++)
    {
        vec3 q = vec3(0.3, 0.5, -3.0)+s*dir;
       
        vec3 p=from+s*dir*.5;
        p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold
        float pa,a=pa=0.;
        for (int i=0; i<iterations; i++)
        {
            p=abs(p)/dot(p,p)-formuparam; // the magic formula
            a+=abs(length(p)-pa); // absolute sum of average change
            pa=length(p);
        }
       
        float dm=max(0.,darkmatter-a*a*.001); //dark matter
        a*=a*a*2.; // add contrast
        if (r>3) fade*=1.-dm; // dark matter, don't render near
        //v+=vec3(dm,dm*.5,0.);
        v+=fade;
        v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
        fade*=distfading; // distance fading
        s+=stepsize;

    }
    v=mix(vec3(length(v)),v,saturation); //color adjust
    return v;
}

void main()
{
    vec2 p = (-iResolution.xy + 2.0 * gl_FragCoord.xy) / iResolution.y;
   
    vec3 lightDir = normalize(vec3(0.0, 0.4, -0.3));
    //float v = mouse.y;
    vec3 rayOrigin = vec3(0.0, 0.01, 0.7);
    mat3 rm = rotationMatrix(vec3(0.0, 0.8, -0.15), -2.1);
    vec3 rayDir = rm*setupRayDirection(radians(60.0));
   

    float travel = 0.0;
   
    vec3 sp = vec3(0.0);
    float coneR;
    vec3 col = space(p)*0.01;
    float fog = 0.0;
   
    for (int i=0; i<256; i++)
    {
       
        coneR = travel * tan(0.5*radians(60.0)/iResolution.y);
        float sd = sdf(rayOrigin+rayDir*travel);
       
        if (sd < coneR)
        {
           
            col = shade(rayOrigin, rayDir, travel, coneR, lightDir);
            col = mix(col, vec3(0.4, 0.4, 0.5), smoothstep(3.0, 4.0, travel));
            break;
        }
       
        fog += fogmap(rayOrigin+rayDir*travel, travel);
        if (travel > 4.0 )
        {
            col = mix(col, vec3(0.4, 0.4, 0.5), smoothstep(1.0, 0.0, p.y));
            break;
        }
       
        travel += min(sd + travel * .001, 8.0);
       
       
    }
   
    fog = min(fog, 1.0);
   
   
   
    col = mix(col, vec3(0.97, .95, .9), fog);
    col = pow(col, vec3(1.2));
   
    vec2 q = gl_FragCoord.xy/iResolution.xy;
    col *= pow(16.0*q.x*q.y*(1.0-q.x)*(1.0-q.y),0.1);
   
    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_0002_256x256.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/AncientMars", 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>



91
English forum / MachineRoom converted
« on: May 30, 2015, 08:55:12 PM »
MachineRoom converted to GLSL Hacker format

Copy the code and save as MachineRoom_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/MachineRoom"
          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/4lB3W3

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;



//

const float pi = 3.14159;

mat3 xrot(float t)
{
    return mat3(1.0, 0.0, 0.0,
                0.0, cos(t), -sin(t),
                0.0, sin(t), cos(t));
}

mat3 yrot(float t)
{
    return mat3(cos(t), 0.0, -sin(t),
                0.0, 1.0, 0.0,
                sin(t), 0.0, cos(t));
}

mat3 zrot(float t)
{
    return mat3(cos(t), -sin(t), 0.0,
                sin(t), cos(t), 0.0,
                0.0, 0.0, 1.0);
}

vec3 paxis(vec3 p)
{ /* thanks to eiffie */
    vec3 a=abs(p),r = vec3(1.0,0.0,0.0);
    if(a.z>=max(a.x,a.y))r=r.yzx;
    else if(a.y>=a.x)r=r.zxy;
    return r*sign(p);
}

float udBox( vec3 p, vec3 b )
{ /* thanks to iq */
  return length(max(abs(p)-b,0.0));
}

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

float sdCylinderInfinite(vec3 p, float r)
{
    return length(p.xz) - r;
}

vec3 func(vec3 p, float s)
{
    vec3 off = paxis(p) * s * 1.5;
    p -= off;
    p -= sign(p) * s * 2.75;
    return p;
}

vec2 map(vec3 p)
{
    p.x += sin(p.z);
   
    vec3 op = p;
   
    float k = 16.0;
    p.z = (fract(p.z/k) * 2.0 - 1.0) * k * 0.5;
   
    vec3 ip = p;
   
    float bs = 1.0;
    float r = 0.0;
    float d = 1000.0;

    for (int i = 0; i < 5; ++i) {
       
        ip = func(ip, bs);

        float fd = udBox(ip, vec3(bs));
        if (fd < d) {
            d = fd;
            r = float(i);
        }
       
        bs *= 0.5;
    }
   
    d = max(d, -sdBoxInfinite(p,vec3(1.0)));
   
    float ck = 8.0;
    vec3 pc = vec3(p.x, p.y, (fract(op.z/ck)*2.0-1.0)*ck*0.5);
    d = max(d, -sdCylinderInfinite(pc, 2.0));
   
    float ground = p.y + 0.9;
    if (ground < d) {
        d = ground;
        r = 6.0;
    }

    return vec2(d,r);
}

vec3 normal(vec3 p)
{
    vec3 o = vec3(0.01, 0.0, 0.0);
    return normalize(vec3(map(p+o.xyy).x - map(p-o.xyy).x,
                          map(p+o.yxy).x - map(p-o.yxy).x,
                          map(p+o.yyx).x - map(p-o.yyx).x));
}

float trace(vec3 o, vec3 r)
{
     float t = 0.0;
    for (int i = 0; i < 32; ++i) {
        vec3 p = o + r * t;
        float d = map(p).x;
        t += d * 0.5;
    }
    return t;
}

vec3 texture(vec3 p)
{
    vec3 ta = texture2D(iChannel0, vec2(p.y,p.z)).xyz;
    vec3 tb = texture2D(iChannel0, vec2(p.x,p.z)).xyz;
    vec3 tc = texture2D(iChannel0, vec2(p.x,p.y)).xyz;
    return (ta + tb + tc) / 3.0;
}

float aoc(vec3 origin, vec3 ray) {
    float delta = 0.1;
    const int samples = 6;
    float r = 0.0;
    for (int i = 1; i <= samples; ++i) {
        float t = delta * float(i);
         vec3 pos = origin + ray * t;
        float dist = map(pos).x;
        float len = abs(t - dist);
        r += len * pow(2.0, -float(i));
    }
    return r;
}

void main()
{
    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    uv = uv * 2.0 - 1.0;
    uv.x *= iResolution.x / iResolution.y;
   
    vec3 o = vec3(0.0, 0.0, 0.0);
    o.z += iGlobalTime * 0.5;
    o.x = sin(-o.z);
    vec3 r = normalize(vec3(uv, 1.3));
    r *= yrot(o.x);
   
    float t = trace(o, r);
    vec3 w = o + r * t;
    vec2 mp = map(w);
    float fd = mp.x;
    float it = mp.y;
    vec3 sn = normal(w);

    float fog = 1.0 / (1.0 + t * t * 0.1 + fd * 100.0);
   
    vec3 diff = texture(w);
   
    if (it == 3.0) {
        diff *= 0.5;
    } else if (it == 2.0) {
        diff = diff.xxx * 1.5;
    } else if (it == 1.0) {
        diff *= vec3(1.0, 1.0, 0.0);
    }
   
    float sz = w.x + sin(w.z);
   
    if (it == 6.0) {
        float m = 0.5+0.5*sign(fract(w.z*10.0+abs(sz)*10.0)-0.5);
        float k = 0.5+0.5*sign(abs(sz)-0.;
        float ik = 0.5+0.5*sign(abs(sz)-0.9);
        float cm = k*(1.0-ik);
        vec3 tape = vec2(m*k,0.0).xxy;
        diff = mix(diff*0.5, tape, cm);
    }
   
    vec3 lighting = vec3(0.6);
    for (int i = -2; i <= 2; ++i) {
        float lz = floor(w.z+float(i)+0.5);
        vec3 lpos = vec3(-sin(lz), 0.0, lz);
        vec3 lcol = vec3(1.0);
        float lmod = mod(lz,3.0);
        if (lmod == 0.0) {
            lcol = vec3(0.0,0.0,1.0) * (0.5+0.5*sin(iGlobalTime));
            lpos.y = 1.0;
        } else if (lmod == 2.0) {
            lcol = vec3(0.0, 1.0, 0.0);
            lpos.y = 0.25;
            lpos.x += cos(lz);
        } else {
             lcol = vec3(1.0, 0.0, 0.0);
            lpos.y = -0.25;
            lpos.x -= cos(lz);
        }
        vec3 ldel = lpos - w;
        float ldist = length(ldel);
        ldel /= ldist;
        float lprod = max(dot(sn,ldel),0.0);
        float latten = 1.0 / (1.0 + ldist * ldist);
        lighting += lprod * latten * lcol;
    }
   
    diff *= lighting * fog;

    gl_FragColor = vec4(diff,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/tex02.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.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/MachineRoom", 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>


92
English forum / raymarching is so awesome - converted
« on: May 30, 2015, 08:15:21 PM »
raymarching is so awesome converted to GLSL Hacker format

Copy the code and save as raymarching_is_so_awesome _gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/raymarching is so awesome"
          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/4lB3WK
// copy canvas.png for iChannel0 into /data/folder

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;



//

#define FOV_SCALE 1.
#define EPSILON .008
const vec3 ne = vec3(.0004435,0.,0.);
vec3 repeat = vec3(20.,0.,20.);
vec3 repeat2 = repeat/2.;

float df(in vec3 p) {
    vec3 ap = abs(p);
    vec3 r = mod(ap,repeat)-repeat2;
    float d = min(1.+p.y,
                  length(max(abs(r)-vec3(2.,40.,2.),0.)));
   
    float dp = cos(ap.x+ap.z)*.5+.5;
    ap.y += dp;
    d = max(-(length(mod(ap,vec3(5.))-vec3(2.5))-2.), d);

    return d;
}
vec3 nrm(in vec3 p) {
    return normalize(vec3(df(p+ne)-df(p-ne),
                     df(p+ne.yxz)-df(p-ne.yxz),
                     df(p+ne.yzx)-df(p-ne.yzx)));
}

void main()
{
    vec2 uv = gl_FragCoord.xy / iResolution.xy - vec2(.5);
    uv.y *= iResolution.y/iResolution.x;
   
    vec3 ld = normalize(vec3(500.,100.,200.));
    float ct = iGlobalTime*10.;
    vec3 rp = vec3(0.,20.,ct);
    vec3 rd = normalize(vec3(0.,-2.,10.));
    vec3 srd = rd;
    vec3 rr = cross(vec3(0.,1.,0.),rd);
    rd = normalize(rd*FOV_SCALE + uv.x*rr + uv.y*cross(rd,rr));
    //rr = vec3(0.,0.,0.)*.001;
   
    float d,s = 0.;
    for (int i = 0; i < 256; i++) {
        d = df(rp);
        if (d < EPSILON) break;
       
        rp += d*rd;
        s += d*.04;
        //rd = normalize(rd+d*rr);
        rr = cross(vec3(sin(s),cos(s),0.)+.5,rd);
        rd = normalize(srd*FOV_SCALE + uv.x*rr + uv.y*cross(rd,rr));
    }
   
    vec3 c;
    if (d < EPSILON) {
        vec3 n = nrm(rp);
        c = texture2D(iChannel0,(rp.xy+rp.zx*.5)*.1).xyz;
       
        rd = n;
        rp -= rd*d;
        for (int i = 0; i < 4; i++) {
            d = df(rp);
            if (d < EPSILON) break;
        }
       
        c = .14*c +
            max(0.,dot(ld,n))*c;
    } else {
        c = vec3(.9);
    }
   
    gl_FragColor = vec4(pow(c,vec3(1.2,1.2,1.3)),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/tex06.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.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/raymarching is so awesome", 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>




93
English forum / Magnetismic converted
« on: May 30, 2015, 08:11:13 PM »
Magnetismic converted to GLSL Hacker format

Note: i stretched iResolution.y

Copy the code and save as Magnetismic _gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/Magnetismic"
          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/XlB3zV

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;



//

//Magnetismic by nimitz (twitter: @stormoid)

//Getting 60fps here at high quality
#define HIGH_QUALITY

#ifdef HIGH_QUALITY
#define STEPS 100
#define ALPHA_WEIGHT 0.025
#define BASE_STEP 0.05
#else
#define STEPS 50
#define ALPHA_WEIGHT 0.05
#define BASE_STEP 0.1
#endif

#define time iGlobalTime
vec2 mo;
vec2 rot(in vec2 p, in float a){float c = cos(a), s = sin(a);return p*mat2(c,s,-s,c);}
float hash21(in vec2 n){ return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); }
float noise(in vec3 p) //iq's ubiquitous 3d noise
{
    vec3 ip = floor(p), f = fract(p);
    #ifdef HIGH_QUALITY
    f = f*f*f*(f*(f*6. - 15.) + 10.); //Quintic smoothing
    #else
    f = f*f*(3.0-2.0*f); //Cubic smoothing
    #endif
    vec2 uv = (ip.xy+vec2(37.0,17.0)*ip.z) + f.xy;
    vec2 rg = texture2D( iChannel0, (uv+ 0.5)/256.0, -100.0 ).yx;
    return mix(rg.x, rg.y, f.z);
}

float fbm(in vec3 p, in float sr)
{
    p *= 3.5;
    float rz = 0., z = 1.;
    for(int i=0;i<4;i++)
    {
        float n = noise(p-time*.6);
        rz += (sin(n*4.4)-.45)*z;
        z *= .47;
        p *= 3.5;
    }
    return rz;
}

vec4 map(in vec3 p)
{
    float dtp = dot(p,p);
    p = .5*p/(dtp + .2);
    p.xz = rot(p.xz, p.y*2.5);
    p.xy = rot(p.xz, p.y*2.);
   
    float dtp2 = dot(p, p);
    p = (mo.y + .6)*3.*p/(dtp2 - 5.);
    float r = clamp(fbm(p, dtp*0.1)*1.5-dtp*(.35-sin(time*0.3)*0.15), 0. ,1.);
    vec4 col = vec4(.5,1.7,.5,.96)*r;
   
    float grd = clamp((dtp+.7)*0.4,0.,1.);
    col.b += grd*.6;
    col.r -= grd*.5;   
    vec3 lv = mix(p,vec3(0.3),2.);
    grd = clamp((col.w - fbm(p+lv*.05,1.))*2., 0.01, 1.5 );
    col.rgb *= vec3(.5, 0.4, .6)*grd + vec3(4.,0.,.4);
    col.a *= clamp(dtp*2.-1.,0.,1.)*0.07+0.93;
   
    return col;
}

vec4 vmarch(in vec3 ro, in vec3 rd)
{
    vec4 rz = vec4(0);
    float t = 2.5;
    t += 0.03*hash21(gl_FragCoord.xy);
    for(int i=0; i<STEPS; i++)
    {
        if(rz.a > 0.99 || t > 6.)break;
        vec3 pos = ro + t*rd;
        vec4 col = map(pos);
        float den = col.a;
        col.a *= ALPHA_WEIGHT;
        col.rgb *= col.a*1.7;
        rz += col*(1. - rz.a);
        t += BASE_STEP - den*(BASE_STEP-BASE_STEP*0.015);
    }
    return rz;
}

void main()
{
    vec2 p = gl_FragCoord.xy/iResolution.xy*2. - 1.;
    p.x *= iResolution.x/iResolution.y*.3;  // y stretched
    mo = 2.0*iMouse.xy/iResolution.xy;
    mo = (mo==vec2(.0))?mo=vec2(0.5,1.):mo;
   
    vec3 ro = 4.*normalize(vec3(cos(2.75-2.0*(mo.x+time*0.05)), sin(time*0.22)*0.2, sin(2.75-2.0*(mo.x+time*0.05))));
    vec3 eye = normalize(vec3(0) - ro);
    vec3 rgt = normalize(cross(vec3(0,1,0), eye));
    vec3 up = cross(eye,rgt);
    vec3 rd = normalize(p.x*rgt + p.y*up + (3.3-sin(time*0.3)*.7)*eye);
   
    vec4 col = vmarch(ro, rd);
    gl_FragColor = vec4(col.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)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")

tex0 = moon3d.image.load2d("./data/noise_texture_0002_256x256.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/Magnetismic", 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>


94
English forum / 38911 BASIC BYTES FREE converted
« on: May 30, 2015, 02:37:12 PM »
38911 BASIC Bytes free converted to GLSL Hacker format

The original resolution of the C64 was 320x200, but that looks too crappy nowadays.

Copy the code and save as 38911_basic_bytes_free_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/38911 BASIC Bytes free"
          width="640" 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/MljGWG

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 vec3      iResolution;     // viewport resolution (in pixels)



//

//-------------------------------------------------------------------------
// general utilities

float dtoa(float d, float amount)
{
    return clamp(1.0 / (clamp(d, 1.0/amount, 1.0)*amount), 0.,1.);
}

// returns 0.0 or 1.0
float extractBit(float fv, float bitIndex)
{
    fv = floor(fv / pow(2., bitIndex));// shift right bitIndex and remove unwanted bits to the right
    fv /= 2.;// shift one more to put our value into decimal portion
    fv = fract(fv);// our value is now isolated. fv is now exactly 0.0 or approx.0.5
    return sign(fv);
}

// not exactly perfectly perfect, but darn close
float pointRectDist(vec2 p, vec2 rectTL, vec2 rectBR)
{
  float dx = max(max(rectTL.x - p.x, 0.), p.x - rectBR.x);
  float dy = max(max(rectTL.y - p.y, 0.), p.y - rectBR.y);
  return max(dx, dy);
}


// warps (0,0)-(1,1) coords
vec2 tvWarp(vec2 uv) {
    uv = (uv - 0.5) * 2.0;// uv is now -1 to 1
    uv *= 1.1;
    uv.x *= 1.0 + pow((abs(uv.y) / 4.0), 2.5);
    uv.y *= 1.0 + pow((abs(uv.x) / 3.5), 2.5);
    uv = (uv / 2.0) + 0.5;// back to 0-1 coords
    uv = uv * 0.92 + 0.04;
    return uv;
}

vec2 getuv(vec2 gl_FragCoord, vec2 newTL, vec2 newSize, out float distanceToVisibleArea, out float vignetteAmt)
{
    vec2 ret = vec2(gl_FragCoord.x / iResolution.x, (iResolution.y - gl_FragCoord.y) / iResolution.y);// ret is now 0-1 in both dimensions
   
    // warp
    ret = tvWarp(ret / 2.) * 2.;// scale it by 2.
    distanceToVisibleArea = pointRectDist(ret, vec2(0.0), vec2(1.));

    // vignette
    vec2 vignetteCenter = vec2(0.5, 0.7);
    vignetteAmt = 1.0 - distance(ret, vignetteCenter);
    vignetteAmt = pow(vignetteAmt, 0.4);// strength
   
    ret *= newSize;// scale up to new dimensions
    float aspect = iResolution.x / iResolution.y;
    ret.x *= aspect;// orig aspect ratio
    float newWidth = newSize.x * aspect;
    return ret + vec2(newTL.x - (newWidth - newSize.x) / 2.0, newTL.y);
}



//-------------------------------------------------------------------------
// font drawing code ...

const int g_glyphCount = 38;
void getGlyphAtIndex(int gi, out vec4 scan0123, out vec4 scan4567)
{
    if(gi==0){scan0123=vec4(0x18,0x3C,0x66,0x7E);scan4567=vec4(0x66,0x66,0x66,0x00);return;}
    if(gi==1){scan0123=vec4(0x7C,0x66,0x66,0x7C);scan4567=vec4(0x66,0x66,0x7C,0x00);return;}
    if(gi==2){scan0123=vec4(0x3C,0x66,0x60,0x60);scan4567=vec4(0x60,0x66,0x3C,0x00);return;}
    if(gi==3){scan0123=vec4(0x78,0x6C,0x66,0x66);scan4567=vec4(0x66,0x6C,0x78,0x00);return;}
    if(gi==4){scan0123=vec4(0x7E,0x60,0x60,0x78);scan4567=vec4(0x60,0x60,0x7E,0x00);return;}
    if(gi==5){scan0123=vec4(0x7E,0x60,0x60,0x78);scan4567=vec4(0x60,0x60,0x60,0x00);return;}
    if(gi==6){scan0123=vec4(0x3C,0x66,0x60,0x6E);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==7){scan0123=vec4(0x66,0x66,0x66,0x7E);scan4567=vec4(0x66,0x66,0x66,0x00);return;}
    if(gi==8){scan0123=vec4(0x3C,0x18,0x18,0x18);scan4567=vec4(0x18,0x18,0x3C,0x00);return;}
    if(gi==9){scan0123=vec4(0x1E,0x0C,0x0C,0x0C);scan4567=vec4(0x0C,0x6C,0x38,0x00);return;}
    if(gi==10){scan0123=vec4(0x66,0x6C,0x78,0x70);scan4567=vec4(0x78,0x6C,0x66,0x00);return;}
    if(gi==11){scan0123=vec4(0x60,0x60,0x60,0x60);scan4567=vec4(0x60,0x60,0x7E,0x00);return;}
    if(gi==12){scan0123=vec4(0x63,0x77,0x7F,0x6B);scan4567=vec4(0x63,0x63,0x63,0x00);return;}
    if(gi==13){scan0123=vec4(0x66,0x76,0x7E,0x6E);scan4567=vec4(0x66,0x66,0x66,0x00);return;}
    if(gi==14){scan0123=vec4(0x3C,0x66,0x66,0x66);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==15){scan0123=vec4(0x7C,0x66,0x66,0x66);scan4567=vec4(0x7C,0x60,0x60,0x00);return;}
    if(gi==16){scan0123=vec4(0x3C,0x66,0x66,0x66);scan4567=vec4(0x66,0x3C,0x0E,0x00);return;}
    if(gi==17){scan0123=vec4(0x7C,0x66,0x66,0x7C);scan4567=vec4(0x78,0x6C,0x66,0x00);return;}
    if(gi==18){scan0123=vec4(0x3C,0x66,0x60,0x3C);scan4567=vec4(0x06,0x66,0x3C,0x00);return;}
    if(gi==19){scan0123=vec4(0x7E,0x18,0x18,0x18);scan4567=vec4(0x18,0x18,0x18,0x00);return;}
    if(gi==20){scan0123=vec4(0x66,0x66,0x66,0x66);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==21){scan0123=vec4(0x66,0x66,0x66,0x66);scan4567=vec4(0x66,0x3C,0x18,0x00);return;}
    if(gi==22){scan0123=vec4(0x63,0x63,0x63,0x6B);scan4567=vec4(0x7F,0x77,0x63,0x00);return;}
    if(gi==23){scan0123=vec4(0x66,0x66,0x3C,0x18);scan4567=vec4(0x3C,0x66,0x66,0x00);return;}
    if(gi==24){scan0123=vec4(0x66,0x66,0x66,0x3C);scan4567=vec4(0x18,0x18,0x18,0x00);return;}
    if(gi==25){scan0123=vec4(0x7E,0x06,0x0C,0x18);scan4567=vec4(0x30,0x60,0x7E,0x00);return;}
    if(gi==26){scan0123=vec4(0x3C,0x66,0x6E,0x76);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==27){scan0123=vec4(0x18,0x18,0x38,0x18);scan4567=vec4(0x18,0x18,0x7E,0x00);return;}
    if(gi==28){scan0123=vec4(0x3C,0x66,0x06,0x0C);scan4567=vec4(0x30,0x60,0x7E,0x00);return;}
    if(gi==29){scan0123=vec4(0x3C,0x66,0x06,0x1C);scan4567=vec4(0x06,0x66,0x3C,0x00);return;}
    if(gi==30){scan0123=vec4(0x06,0x0E,0x1E,0x66);scan4567=vec4(0x7F,0x06,0x06,0x00);return;}
    if(gi==31){scan0123=vec4(0x7E,0x60,0x7C,0x06);scan4567=vec4(0x06,0x66,0x3C,0x00);return;}
    if(gi==32){scan0123=vec4(0x3C,0x66,0x60,0x7C);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==33){scan0123=vec4(0x7E,0x66,0x0C,0x18);scan4567=vec4(0x18,0x18,0x18,0x00);return;}
    if(gi==34){scan0123=vec4(0x3C,0x66,0x66,0x3C);scan4567=vec4(0x66,0x66,0x3C,0x00);return;}
    if(gi==35){scan0123=vec4(0x3C,0x66,0x66,0x3E);scan4567=vec4(0x06,0x66,0x3C,0x00);return;}
    if(gi==36){scan0123=vec4(0x00,0x00,0x00,0x00);scan4567=vec4(0x00,0x18,0x18,0x00);return;}
    if(gi==37){scan0123=vec4(0x00,0x66,0x3C,0xFF);scan4567=vec4(0x3C,0x66,0x00,0x00);return;}   
    scan0123 = vec4(0.);scan4567 = vec4(0.);
}

// stringIndex lets you use the same pos for a string of chars, just incrementing stringIndex.
// this is pretty fast, but is binary. a prettier version might return a distance function but will suffer perf problems because of the complex geometry.
vec4 drawCharacter(vec4 inpColor, vec4 glyphColor, vec2 uv, vec2 pos, vec2 charSize, float stringIndex, int glyphIndex)
{
    vec2 element = floor(((uv - pos) / (charSize / 8.)));// convert uv to pixel indices
    element.x -= stringIndex * 8.0;
    element.x = floor(7.0 - element.x);// flip X. maybe my encoding method is wrong?
    // bounds check; most of the time uv will not land on the character so important to optimize this.
    if(element.y < 0. || element.y > 7.) return inpColor;
    if(element.x < 0. || element.x > 7.) return inpColor;

    vec4 scan0123;
    vec4 scan4567;
    getGlyphAtIndex(glyphIndex, scan0123, scan4567);
   
    int scanLineI = int(element.y);
    float scanLine;
   
    if(scanLineI == 0) scanLine = scan0123[0];
    else if(scanLineI == 1) scanLine = scan0123[1];
    else if(scanLineI == 2) scanLine = scan0123[2];
    else if(scanLineI == 3) scanLine = scan0123[3];
    else if(scanLineI == 4) scanLine = scan4567[0];
    else if(scanLineI == 5) scanLine = scan4567[1];
    else if(scanLineI == 6) scanLine = scan4567[2];
    else if(scanLineI == 7) scanLine = scan4567[3];

    float a = extractBit(scanLine, element.x);
    return vec4(mix(inpColor.rgb, glyphColor.rgb, a * glyphColor.a), inpColor.a);
}




//-------------------------------------------------------------------------
vec4 hardRect(vec4 inpColor, vec4 rectColor, vec2 uv, vec2 tl, vec2 br)
{
    if(uv.x < tl.x)
        return inpColor;
    if(uv.x > br.x)
        return inpColor;
    if(uv.y < tl.y)
        return inpColor;
    if(uv.y > br.y)
        return inpColor;
    return rectColor;
}


float nsin(float x)
{
    return (sin(x) + 1.0) / 2.;
}


void main()
{
    float distanceToVisibleArea;
    float vignetteAmt;
    vec2 uv = getuv(gl_FragCoord, vec2(1.08,-0.1), vec2(2.6), distanceToVisibleArea, vignetteAmt);

    vec4 darkBlue = vec4(0.21,0.16,0.47,1.0);
    vec4 lightBlue = vec4(0.42,0.37,0.71,1.0);

    // main background
    gl_FragColor = darkBlue;
   
    // border
    vec2 charAreaTL = vec2(0.6, 0.3);
    if(uv.x < charAreaTL.x)
        gl_FragColor = lightBlue;
    if(uv.y < charAreaTL.y)
        gl_FragColor = lightBlue;

    // ready.
    vec4 charColor = lightBlue;
    vec2 charSize = vec2(0.2);
    charSize.x *= 0.936;// c64 aspect ratio
    vec2 stringPos = charAreaTL + vec2(0, 1.0 * charSize.y);// line 1
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 4., 37);// *
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 5., 37);// *
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 6., 37);// *
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 7., 37);// *

    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 9., 2);// C
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 10., 14);// O
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 11., 12);// M
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 12., 12);// M
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 13., 14);// O
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 14., 3);// D
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 15., 14);// O
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 16., 17);// R
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 17., 4);// E

    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 19., 32);// 6
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 20., 30);// 4
   
    stringPos = charAreaTL + vec2(0, 3.0 * charSize.y);// line 3
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 1., 32);// 6
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 2., 30);// 4
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 3., 10);// K
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 5., 17);// R
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 6., 0);// A
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 7., 12);// M

    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 9., 18);// S
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 10., 24);// Y
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 11., 18);// S
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 12., 19);// T
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 13., 4);// E
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 14., 12);// M
   
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 17., 29);// 3
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 18., 34);// 8
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 19., 35);// 9
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 20., 27);// 1
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 21., 27);// 1
   
    stringPos = charAreaTL + vec2(0, 5.0 * charSize.y);// line 5
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 0., 17);// R
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 1., 4);// E
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 2., 0);// A
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 3., 3);// D
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 4., 24);// Y
    gl_FragColor = drawCharacter(gl_FragColor, charColor, uv, stringPos, charSize, 5., 36);// .
   
    if(mod(iGlobalTime, 1.) < 0.5)
    {
        vec2 tl = vec2(stringPos.x, stringPos.y + charSize.y);
        gl_FragColor = hardRect(gl_FragColor, charColor, uv, tl, tl + charSize);
    }

   
    // black out warped area
    gl_FragColor = vec4(mix(vec3(0.), gl_FragColor.rgb, dtoa(distanceToVisibleArea, 200.)), 1.0);
       
    gl_FragColor.rgb *= vignetteAmt;

    //Draws the horizontal scan lines across the screen
    float scanLineFX = nsin(uv.y * 500.);
    scanLineFX = clamp(pow(scanLineFX, 4.0), 0.3, 1.0);
    gl_FragColor.rgb *= 1.0 + scanLineFX;
    gl_FragColor.rgb = clamp(gl_FragColor.rgb, 0.0, 1.0);

    //gl_FragColor = gridOverlay(gl_FragColor, uv);
}



//

]]></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/38911 BASIC Bytes free", 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>



95
English forum / Old conversion topics merged
« on: May 30, 2015, 01:55:38 PM »
EvilSeed @ Shadertoy converted to GLSL Hacker format

My first try with conversion and for no reason a big screenshot :P

Copy the code and save as evilseed_gl2.xml

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

<glsl_hacker>
   
  <window name="win3d01" title="MadShaders - Shadertoy/EvilSeed"
          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/llBGRd

 
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 vec3 iChannelResolution0;



const float pi = 3.14159;

mat3 xrot(float t)
{
    return mat3(1.0, 0.0, 0.0,
                0.0, cos(t), -sin(t),
                0.0, sin(t), cos(t));
}

mat3 yrot(float t)
{
    return mat3(cos(t), 0.0, -sin(t),
                0.0, 1.0, 0.0,
                sin(t), 0.0, cos(t));
}

mat3 zrot(float t)
{
    return mat3(cos(t), -sin(t), 0.0,
                sin(t), cos(t), 0.0,
                0.0, 0.0, 1.0);
}

float btime = 1.0;
float bspeed = 10.0;

float map(vec3 pos)
{
    float dir = 1.0;
    vec3 id = floor(pos);
    pos.y += sin(iGlobalTime+id.x*10.0+id.z*10.0);
    pos = fract(pos) * 2.0 - 1.0;
    pos *= yrot(iGlobalTime*btime*4.0*dir);
    float s = length(pos.xz);
    float k = atan(pos.z, pos.x);
    float mr = 0.9;
    float r = mix(0.8, 1.0, 0.5 + 0.5 * sin(s/mr*dir*bspeed+k*10.0));
    float p = mr * r;
    float e = 1.0 - s/p;
    vec3 c = vec3(pos.x, clamp(pos.y,-0.02*e, 0.02*e), pos.z);
    return min(max(length(c-pos), s-p), s-0.1);
}

vec3 normal(vec3 p)
{
    vec3 o = vec3(0.01, 0.0, 0.0);
    return normalize(vec3(map(p+o.xyy) - map(p-o.xyy),
                          map(p+o.yxy) - map(p-o.yxy),
                          map(p+o.yyx) - map(p-o.yyx)));
}

float trace(vec3 o, vec3 r)
{
     float t = 0.0;
    for (int i = 0; i < 16; ++i) {
         vec3 p = o + r * t;
        float d = map(p);
        t += d * 0.5;
    }
    return t;
}

float pshade(vec3 p)
{
    vec3 id = floor(p);
    p.y += sin(iGlobalTime+id.x*10.0+id.z*10.0);
    p = fract(p) * 2.0 - 1.0;
    p *= yrot(iGlobalTime*btime*4.0+length(p.xz)*4.0);
    p += id;
    float ac = texture2D(iChannel0, vec2(p.y,p.z)).x;
    float bc = texture2D(iChannel0, vec2(p.x,p.z)).x;
    float cc = texture2D(iChannel0, vec2(p.x,p.y)).x;
    float s = ((ac + bc + cc) / 3.0) * 2.0 - 1.0;
    return s;
}

vec4 surf(vec3 r, vec3 w, vec3 sn, float t)
{
    float prod = max(dot(sn,-r), 0.0);
    float off = 0.5 + 0.5 * sin(pshade(w)*pi*5.0);
    float ao = map(w) * 20.0;
    float fog = prod / (1.0 + t * t + off + ao);
    return vec4(vec3(fog),off);
}

vec3 shade(vec3 r, float time)
{
    r *= xrot(iGlobalTime) * zrot(time);
   
    vec3 o = vec3(0.0, 0.0, 0.0);
    o.z += time;
   
    float t = trace(o, r);
    vec3 w = o + r * t;
    vec3 sn = normal(w);
   
    vec4 ac = surf(r, w, sn, t);
   
    vec3 from = vec3(0.8, 0.2, 0.1);
    vec3 to = vec3(1.0, 1.0, 1.0);
   
    float fx = 1.0 - ac.w;
   
    vec3 mixed = ac.xyz * mix(from, to, fx);
   
    return mixed;
}

void main()
{
    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    uv = uv * 2.0 - 1.0;
    uv.x *= iResolution.x / iResolution.y;
   
    vec3 r = normalize(vec3(uv, 1.0 - dot(uv,uv) * 0.33));

    btime = 2.0;
    bspeed = 10.0;
    vec3 sa = shade(r, iGlobalTime);
   
    float of = 0.01;
   
    btime = 4.0;
    bspeed = 20.0;
    vec3 sb = shade(r, iGlobalTime+of);

    btime = 6.0;
    bspeed = 20.0;
    vec3 sc = shade(r, iGlobalTime+of*2.0);
   
    vec3 f = sa * 0.2 + sb * 0.5 + sc * 0.3;
   
    gl_FragColor = vec4(f,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/EvilSeed", 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>


96
The Android M release:  improving the fundamentals

For the M release, we focused on improving the core user experience of Android, from fixing thousands of bugs, to making some big changes to the fundamentals of the platform
...
The M Developer Preview includes an updated SDK with tools, system images for testing on the official Android emulator, and system images for testing on Nexus 5, Nexus 6, Nexus 9, and Nexus Player devices. We are excited to expand the program and give you more time to ensure your apps support M when it launches this fall. 


97
3D-Tech News Around The Web / (WebGL) Star Wars BB8 Droid
« on: May 28, 2015, 06:36:08 PM »
Great use of WebGL to show just how the real Star Wars BB8 Droid works

[via]

Quote
BB-8 is an astromech droid that appears on Star Wars Episode VII - The Force Awakens. It has a ball shaped body and a domed head that resembles that of the R2 series droids, whose most popular unit is R2-D2. BB-8's body rolls independently from the head, which always stays near the vertical axis of the droid.

98
3D-Tech News Around The Web / NVIDIA AndroidWorks 1R1
« on: May 28, 2015, 06:30:52 PM »
NVIDIA AndroidWorks installs all software tools required to develop for Android and reduces the complex process of configuring an Android development system down to a single click. With a full suite of developer tools, AndroidWorks is a professional grade solution designed to provide the best development platform for all Android devices - not only Tegra powered devices.

AndroidWorks 1R1 supports your 32-bit and 64-bit Android application development needs, including the latest Android SDK (24.2.0), NDK (r10d), and NVIDIA Nsight Tegra, Visual Studio Edition 3.0. This latest Nsight Tegra release allows for seamless GDB and JDB remote debugging to all Android devices capable of native application debugging, supporting all Android ABIs – ARM v7, ARM v8, x86. In addition, this release prepares you for development for the latest NVIDIA® SHIELD™ tablet OTA 3.0 and the all-new NVIDIA® SHIELD™ Android TV powered by NVIDIA® Tegra® X1 processor. Full NVIDIA SHIELD support requires latest software updates to enable debugging support. Install the latest Android OTA system updates prior to using the device with AndroidWorks 1R1.

For important information about this release, see the AndroidWorks 1R1 Release Notes.
Archived versions available here.   

 More Information

99
3D-Tech News Around The Web / Catzilla 1.4 released
« on: May 27, 2015, 08:13:38 PM »
Quote
Catzilla 1.4   

Created on 2015-05-26,

 Application:
  • Correct detection of the latest graphics cards and processors:
- NVIDIA GeForce GTX 870 and 880 (GM204)
 - AMD Radeon R9 285
 - NVIDIA GeForce GTX 970 and GTX 980
 - NVIDIA GeForce GTX 960 and GM206
 - NVIDIA GeForce GTX TITAN X
  • Fixed reporting of memory clock on Haswell-E/EN/EP/EX
  • Improved DDR4 support
  • Enhanced support of CPUs with more than 256 logical cores
  • Enhanced reporting of memory timings and other features for Skylake
  • Many more games for "Check Game" option

100
3D-Tech News Around The Web / TechPowerUp GPU-Z v0.8.3
« on: May 27, 2015, 07:07:53 PM »
GPU-Z is a lightweight utility designed to provide you with all information about your graphics card and GPU. 

 Version History 0.8.3
  • Added VGA BIOS UEFI support indicator
  • Added support for NVIDIA GTX 980 Ti, GTX 965M, GTX 950M, NVS315, GT 750 (GK106)
  • Added support for AMD Fiji, Radeon R2/R3 Graphics (Mullins APU)
  • Added support for various Intel Broadwell SKUs
  • Fixed missing NVIDIA PerfCap sensor in some cases
  • Added support for HBM memory
  • Fixed GT200B die size
  • Fixed some NV42 specs
  • Improved OpenCl detection code

30b.png

Pages: 1 ... 3 4 [5] 6 7 ... 157