Elevated shader in Unity3D.

Do you remember famous 4 KB demo called Elevated from 2009 year ?
Now you can, thanks to source code shared from Shader - Shadertoy BETA ,
free flythrough over procedural generated mountains directly in Unity3D !
In Unity3D editor, add quad to Main Camera. Set quad position (0.0;0.0;0.4) and camera position(0,100,0). Bind material with shader to the quad. Add fly script to the camera. Play.
Fly script:
Fly Cam (simple cam script) - Community Showcases - Unity Discussions
Shader source:
Unity3D-CG-programming/elevated.shader at master · przemyslawzaworski/Unity3D-CG-programming · GitHub


//source : https://www.shadertoy.com/view/MdX3Rr

Shader "Elevated"
{
    Subshader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vertex_shader
            #pragma fragment pixel_shader
            #pragma target 4.0

            struct custom_type
            {
                float4 screen_vertex : SV_POSITION;
                float3 world_vertex : TEXCOORD1;
            };

            #define SC (5.0)

            float rand(float2 n)
            {
                return frac(sin(dot(n, float2(12.9898, 4.1414))) * 43758.5453);
            }

            float3 noised(float2 x )
            {
                float2 f = frac(x);
                float2 u = f*f*(3.0-2.0*f);
                float2 p = floor(x);
                float a = rand (p + float2(0.0,0.0));
                float b = rand (p + float2(1.0,0.0));
                float c = rand (p + float2(0.0,1.0));
                float d = rand (p + float2(1.0,1.0));              
                return float3(a+(b-a)*u.x+(c-a)*u.y+(a-b-c+d)*u.x*u.y,
                    6.0*f*(1.0-f)*(float2(b-a,c-a)+(a-b-c+d)*u.yx));
            }

            static const float2x2 m2 = float2x2(0.8,-0.6,0.6,0.8);

            float terrainH( float2 x )
            {
                float2  p = x*0.003/SC;
                float a = 0.0;
                float b = 1.0;
                float2  d = float2(0.0,0.0);
                for( int i=0; i<15; i++ )
                {
                    float3 n = noised(p);
                    d += n.yz;
                    a += b*n.x/(1.0+dot(d,d));
                    b *= 0.5;
                    p = p*2.0;
                    p = mul(p,m2);
                }
                return SC*120.0*a;
            }

            float terrainM( float2 x )
            {
                float2  p = x*0.003/SC;
                float a = 0.0;
                float b = 1.0;
                float2 d = float2(0.0,0.0);
                for( int i=0; i<9; i++ )
                {
                    float3 n = noised(p);
                    d += n.yz;
                    a += b*n.x/(1.0+dot(d,d));
                    b *= 0.5;
                    p = p*2.0;
                    p = mul(p,m2);
                }
                return SC*120.0*a;
            }

            float terrainL( float2 x )
            {
                float2  p = x*0.003/SC;
                float a = 0.0;
                float b = 1.0;
                float2  d = float2(0.0,0.0);
                for( int i=0; i<3; i++ )
                {
                    float3 n = noised(p);
                    d += n.yz;
                    a += b*n.x/(1.0+dot(d,d));
                    b *= 0.5;
                    p = p*2.0;
                    p = mul(p,m2);
                }
                return SC*120.0*a;
            }

            float intersect(float3 ro,float3 rd,float tmin,float tmax )
            {
                float t = tmin;
                for( int i=0; i<256; i++ )
                {
                    float3 pos = ro + t*rd;
                    float h = pos.y - terrainM( pos.xz );
                    if( h<(0.002*t) || t>tmax ) break;
                    t += 0.3*h;
                }
                return t;
            }

            float softShadow(float3 ro,float3 rd )
            {
                float res = 1.0;
                float t = 0.001;
                for( int i=0; i<80; i++ )
                {
                    float3  p = ro + t*rd;
                    float h = p.y - terrainM( p.xz );
                    res = min( res, 16.0*h/t );
                    t += h;
                    if(res<0.001||p.y>(SC*200.0)) break;
                }
                return saturate(res);
            }

            float3 calcNormal(float3 pos, float t )
            {
                float2 eps = float2( 0.002*t, 0.0 );
                return normalize( float3( terrainH(pos.xz-eps.xy) - terrainH(pos.xz+eps.xy),
                    2.0*eps.x,terrainH(pos.xz-eps.yx) - terrainH(pos.xz+eps.yx) ) );
            }

            float fbm( float2 p )
            {
                float f = 0.0;
                f += 0.5000*noised(p).x; p = p*2.02; p = mul(p,m2);
                f += 0.2500*noised(p).x; p = p*2.03; p = mul(p,m2);
                f += 0.1250*noised(p).x; p = p*2.01; p = mul(p,m2);
                f += 0.0625*noised(p).x;
                return f/0.9375;
            }

            static const float kMaxT = 5000.0*SC;

            float4 render( in float3 ro, in float3 rd )
            {
                float3 light1 = normalize(float3(-0.8,0.4,-0.3));
                float tmin = 0.5;
                float tmax = kMaxT;
                float sundot = clamp(dot(rd,light1),0.0,1.0);
                float3 col;
                float t = intersect( ro, rd, tmin, tmax );
                if( t>tmax)
                {  
                    col = float3(0.2,0.5,0.85)*1.1 - rd.y*rd.y*0.5;
                    col = lerp( col, 0.85*float3(0.7,0.75,0.85), pow( 1.0-max(rd.y,0.0), 4.0 ) );
                    col += 0.25*float3(1.0,0.7,0.4)*pow( sundot,5.0 );
                    col += 0.25*float3(1.0,0.8,0.6)*pow( sundot,64.0 );
                    col += 0.2*float3(1.0,0.8,0.6)*pow( sundot,512.0 );
                    float2 sc = ro.xz + rd.xz*(SC*1000.0-ro.y)/rd.y;
                    col = lerp( col, float3(1.0,0.95,1.0), 0.5*smoothstep(0.5,0.8,fbm(0.0005*sc/SC)) );
                    col = lerp( col, 0.68*float3(0.4,0.65,1.0), pow( 1.0-max(rd.y,0.0), 16.0 ) );
                    t = -1.0;
                }
                else
                {
                    float3 pos = ro + t*rd;
                    float3 nor = calcNormal( pos, t );
                    float3 ref = reflect( rd, nor );
                    float fre = clamp( 1.0+dot(rd,nor), 0.0, 1.0 );
                    float r = noised((7.0/SC)*pos.xz/256.0 ).x;
                    col = (r*0.25+0.75)*0.9*lerp( float3(0.08,0.05,0.03), float3(0.10,0.09,0.08),
                        noised(0.00007*float2(pos.x,pos.y*48.0)/SC).x );
                    col = lerp( col, 0.20*float3(0.45,.30,0.15)*(0.50+0.50*r),smoothstep(0.70,0.9,nor.y) );
                    col = lerp( col, 0.15*float3(0.30,.30,0.10)*(0.25+0.75*r),smoothstep(0.95,1.0,nor.y) );
                    float h = smoothstep(55.0,80.0,pos.y/SC + 25.0*fbm(0.01*pos.xz/SC) );
                    float e = smoothstep(1.0-0.5*h,1.0-0.1*h,nor.y);
                    float o = 0.3 + 0.7*smoothstep(0.0,0.1,nor.x+h*h);
                    float s = h*e*o;
                    col = lerp( col, 0.29*float3(0.62,0.65,0.7), smoothstep( 0.1, 0.9, s ) );      
                    float amb = clamp(0.5+0.5*nor.y,0.0,1.0);
                    float dif = clamp( dot( light1, nor ), 0.0, 1.0 );
                    float bac = clamp( 0.2 + 0.8*dot( normalize( float3(-light1.x, 0.0, light1.z ) ), nor ), 0.0, 1.0 );
                    float sh = 1.0; if( dif>=0.0001 ) sh = softShadow(pos+light1*SC*0.05,light1);      
                    float3 lin  = float3(0.0,0.0,0.0);
                    lin += dif*float3(7.00,5.00,3.00)*1.3*float3( sh, sh*sh*0.5+0.5*sh, sh*sh*0.8+0.2*sh );
                    lin += amb*float3(0.40,0.60,0.80)*1.2;
                    lin += bac*float3(0.40,0.50,0.60);
                    col *= lin;      
                    col += s*0.1*pow(fre,4.0)*float3(7.0,5.0,3.0)*sh * pow( clamp(dot(light1,ref), 0.0, 1.0),16.0);
                    col += s*0.1*pow(fre,4.0)*float3(0.4,0.5,0.6)*smoothstep(0.0,0.6,ref.y);
                    float fo = 1.0-exp(-pow(0.001*t/SC,1.5) );
                    float3 fco = 0.65*float3(0.4,0.65,1.0);// + 0.1*float3(1.0,0.8,0.5)*pow( sundot, 4.0 );
                    col = lerp( col, fco, fo );

                }
                col += 0.3*float3(1.0,0.7,0.3)*pow( sundot, 8.0 );
                col = sqrt(col); 
                return float4( col, 1.0 );
            }  
      
            custom_type vertex_shader (float4 vertex : POSITION)
            {
                custom_type vs;
                vs.screen_vertex = UnityObjectToClipPos (vertex);
                vs.world_vertex = mul (unity_ObjectToWorld, vertex);
                return vs;
            }

            float4 pixel_shader (custom_type ps ) : SV_TARGET
            {
                float3 worldPosition = ps.world_vertex;
                float3 viewDirection = normalize(ps.world_vertex - _WorldSpaceCameraPos.xyz);
                return render (worldPosition,viewDirection);
            }

            ENDCG

        }
    }
}
1 Like

Ugly shader, beautiful result. A good thing to note is that this shader renders everything you see here. Including the sky, clouds, sun and fog. Not just the terrain. And it uses no textures. Just over 200 lines of code completely generate that scene.

@jvo3dc
“ugly shader”, what do you mean ? :slight_smile:

I mean ugly code. Very non-descriptive names for the variables.

@Przemyslaw_Zaworski

Firstly thank you for the code
I’m just starting off with shaders
I tried using the code but I’m getting an undeclared identifier UnityObjectToClipPos
Could you help me out with this

Could you tell which version of Unity engine do you use ?

Thanks for getting back,
I am using the Unity 2017.2.1f1 version
I floated a value
inline float4 UnityObjectToClipPos( in float3 pos )
and solved the first issue

now the shader error is
redefinition of float for the line
float rand(float2 n)
{
return frac(sin(dot(n, float2(12.9898, 4.1414))) * 43758.5453);
}

Thank you so much. I like a fool was tring

trying to run the shader on a force-opengl mode. Its working fine now.

Original code from #1 post works great on Unity 2018.2.14f1 (new project with 3D template) in DX11 mode

@Przemyslaw_Zaworski

Sorry to be bothering you often
But could you help me to convert this shader Shader - Shadertoy BETA
Its from the same author and of what I have read something on similar lines.
Would greatly appreciate your help as I’m trying to explore the use of shaderrtoy shaders as 3D game environments

Yes, I can translate Rainforest with seamless integration to Unity Engine.
But first, visit this thread:

and see post #5 and post #7.

I really appreciate your help, thanks. I will look through the files, see the code and see how you have converted each of them. That is an impressive list of shaders you have there. If I still cant do it then I shall consult with you. Thanks once again.

@Przemyslaw_Zaworski

Hello, I have tried my best to convert the GLSL code these past few months but haven’t been successful. I looked at all the tutorials too but I guess my very limited knowledge is evident. This shader Shader - Shadertoy BETA by the same author has the same GLSL code as the one you converted(Elevated) but the results are so different. Would you please help me convert it and understand the process?

This is multipass, so converting it may be not easy. But we can, in first try, remove motion blur and convert shader to single pass form, like this:

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

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

    float a = textureLod( iChannel0, x.xy/256.0 + (p.z+0.0)*120.7123, 0.0 ).x;
    float b = textureLod( iChannel0, x.xy/256.0 + (p.z+1.0)*120.7123, 0.0 ).x;
    return mix( a, b, f.z );
}


const mat3 m = mat3( 0.00,  0.80,  0.60,
                    -0.80,  0.36, -0.48,
                    -0.60, -0.48,  0.64 );

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

float envelope( vec3 p )
{
    float isLake = 1.0-smoothstep( 0.62, 0.72, textureLod( iChannel0, 0.001*p.zx, 0.0).x );
    return 0.1 + isLake*0.9*textureLod( iChannel1, 0.01*p.xz, 0.0 ).x;
}

float mapTerrain( in vec3 pos )
{
    return pos.y - envelope(pos);
}

float raymarchTerrain( in vec3 ro, in vec3 rd )
{
    float maxd = 50.0;
    float precis = 0.001;
    float h = 1.0;
    float t = 0.0;
    for( int i=0; i<80; i++ )
    {
        if( abs(h)<precis||t>maxd ) break;
        t += h;
        h = mapTerrain( ro+rd*t );
    }

    if( t>maxd ) t=-1.0;
    return t;
}

vec3 lig = normalize( vec3(0.7,0.4,0.2) );

vec3 calcNormal( in vec3 pos )
{
    vec3 eps = vec3(0.02,0.0,0.0);
    return normalize( vec3(
           mapTerrain(pos+eps.xyy) - mapTerrain(pos-eps.xyy),
           0.5*2.0*eps.x,
           mapTerrain(pos+eps.yyx) - mapTerrain(pos-eps.yyx) ) );

}

vec4 mapTrees( in vec3 pos, in vec3 rd )
{
    vec3  col = vec3(0.0);   
    float den = 1.0;

    float kklake = textureLod( iChannel0, 0.001*pos.zx, 0.0).x;
    float isLake = smoothstep( 0.7, 0.71, kklake );
   
    if( pos.y>1.0 || pos.y<0.0 )
    {
        den = 0.0;
    }
    else
    {
       
        float h = pos.y;
        float e = envelope( pos );
        float r = clamp(h/e,0.0,1.0);
       
        den = smoothstep( r, 1.0, textureLod(iChannel0, pos.xz*0.15, 0.0).x );
       
        den *= 1.0-0.95*clamp( (r-0.75)/(1.0-0.75) ,0.0,1.0);
       
        float id = textureLod( iChannel0, pos.xz, 0.0).x;
        float oc = pow( r, 2.0 );

        vec3  nor = calcNormal( pos );
        vec3  dif = vec3(1.0)*clamp( dot( nor, lig ), 0.0, 1.0 );
        float amb = 0.5 + 0.5*nor.y;
       
        float w = (2.8-pos.y)/lig.y;
        float c = fbm( (pos+w*lig)*0.35 );
        c = smoothstep( 0.38, 0.6, c );
        dif *= pow( vec3(c), vec3(0.8, 1.0, 1.5 ) );
           
        vec3  brdf = 1.7*vec3(1.5,1.0,0.8)*dif*(0.1+0.9*oc) + 1.3*amb*vec3(0.1,0.15,0.2)*oc;

        vec3 mate = 0.6*vec3(0.5,0.5,0.1);
        mate += 0.3*textureLod( iChannel1, 0.1*pos.xz, 0.0 ).zyx;
       
        col = brdf * mate;

        den *= 1.0-isLake;
    }

    return vec4( col, den );
}


vec4 raymarchTrees( in vec3 ro, in vec3 rd, float tmax, vec3 bgcol, out float resT )
{
    vec4 sum = vec4(0.0);
    float t = tmax;
    for( int i=0; i<512; i++ )
    {
        vec3 pos = ro + t*rd;
        if( sum.a>0.99 || pos.y<0.0  || t>20.0 ) break;
       
        vec4 col = mapTrees( pos, rd );

        col.xyz = mix( col.xyz, bgcol, 1.0-exp(-0.0018*t*t) );
       
        col.rgb *= col.a;

        sum = sum + col*(1.0 - sum.a);   
       
        t += 0.0035*t;
    }
   
    resT = t;

    return clamp( sum, 0.0, 1.0 );
}

vec4 mapClouds( in vec3 p )
{
    float d = 1.0-0.3*abs(2.8 - p.y);
    d -= 1.6 * fbm( p*0.35 );

    d = clamp( d, 0.0, 1.0 );
   
    vec4 res = vec4( d );

    res.xyz = mix( 0.8*vec3(1.0,0.95,0.8), 0.2*vec3(0.6,0.6,0.6), res.x );
    res.xyz *= 0.65;
   
    return res;
}


vec4 raymarchClouds( in vec3 ro, in vec3 rd, in vec3 bcol, float tmax, out float rays, ivec2 px )
{
    vec4 sum = vec4(0, 0, 0, 0);
    rays = 0.0;
   
    float sun = clamp( dot(rd,lig), 0.0, 1.0 );
    float t = 0.1*texelFetch( iChannel0, px&ivec2(255), 0 ).x;
    for(int i=0; i<64; i++)
    {
        if( sum.w>0.99 || t>tmax ) break;
        vec3 pos = ro + t*rd;
        vec4 col = mapClouds( pos );

        float dt = max(0.1,0.05*t);
        float h = (2.8-pos.y)/lig.y;
        float c = fbm( (pos + lig*h)*0.35 );
        //kk += 0.05*dt*(smoothstep( 0.38, 0.6, c ))*(1.0-col.a);
        rays += 0.02*(smoothstep( 0.38, 0.6, c ))*(1.0-col.a)*(1.0-smoothstep(2.75,2.8,pos.y));
   
       
        col.xyz *= vec3(0.4,0.52,0.6);
       
        col.xyz += vec3(1.0,0.7,0.4)*0.4*pow( sun, 6.0 )*(1.0-col.w);
       
        col.xyz = mix( col.xyz, bcol, 1.0-exp(-0.0018*t*t) );
       
        col.a *= 0.5;
        col.rgb *= col.a;

        sum = sum + col*(1.0 - sum.a);   

        t += dt;//max(0.1,0.05*t);
    }
    rays = clamp( rays, 0.0, 1.0 );

    return clamp( sum, 0.0, 1.0 );
}

vec3 path( float time )
{
    return vec3( 32.0*cos(0.2+0.75*.1*time*1.5), 1.2, 32.0*sin(0.1+0.75*0.11*time*1.5) );
}

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

void moveCamera( float time, out vec3 oRo, out vec3 oTa, out float oCr, out float oFl )
{
    // camera   
    oRo = path( time );
    oTa = path( time+1.0 );
    oTa.y *= 0.2;
    oCr = 0.3*cos(0.07*time);
    oFl = 1.75;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 q = fragCoord.xy / iResolution.xy;
    vec2 p = -1.0 + 2.0*q;
    p.x *= iResolution.x / iResolution.y;
   
    float time = 23.5+iTime;
   
    // camera   
    vec3 ro, ta;
    float roll, fl;
    moveCamera( time, ro, ta, roll, fl );
       
    // camera tx
    mat3 cam = setCamera( ro, ta, roll );

    // ray direction
    vec3 rd = normalize( cam * vec3(p.xy,fl) );

    // sky    
    vec3 col = vec3(0.84,0.95,1.0)*0.77 - rd.y*0.6;
    col *= 0.75;
    float sun = clamp( dot(rd,lig), 0.0, 1.0 );
    col += vec3(1.0,0.7,0.3)*0.3*pow( sun, 6.0 );
    vec3 bcol = col;

    // lakes
    float gt = (0.0-ro.y)/rd.y;
    if( gt>0.0 )
    {
        vec3 pos = ro + rd*gt;

        vec3 nor = vec3(0.0,1.0,0.0);
        nor.xz  = 0.10*(-1.0 + 2.0*texture( iChannel3, 1.5*pos.xz ).xz);
        nor.xz += 0.15*(-1.0 + 2.0*texture( iChannel3, 3.2*pos.xz ).xz);
        nor.xz += 0.20*(-1.0 + 2.0*texture( iChannel3, 6.0*pos.xz ).xz);
    nor = normalize(nor);

        vec3 ref = reflect( rd, nor );
        vec3 sref = reflect( rd, vec3(0.0,1.0,0.0) );
        float sunr = clamp( dot(ref,lig), 0.0, 1.0 );

        float kklake = texture( iChannel0, 0.001*pos.zx).x;
        col = vec3(0.1,0.1,0.0);
        vec3 lcol = vec3(0.2,0.5,0.7);
        col = mix( lcol, 1.1*vec3(0.2,0.6,0.7), 1.0-smoothstep(0.7,0.81,kklake) );
       
        col *= 0.12;

        float fre = 1.0 - max(sref.y,0.0);
        col += 0.8*vec3(1.0,0.9,0.8)*pow( sunr, 64.0 )*pow(fre,1.0);
        col += 0.5*vec3(1.0,0.9,0.8)*pow( fre, 10.0 );

        float h = (2.8-pos.y)/lig.y;
        float c = fbm( (pos+h*lig)*0.35 );
        col *= 0.4 + 0.6*smoothstep( 0.38, 0.6, c );

        col *= smoothstep(0.7,0.701,kklake);

        col.xyz = mix( col.xyz, bcol, 1.0-exp(-0.0018*gt*gt) );
    }


    // terrain   
    float t = raymarchTerrain(ro, rd);
    if( t>0.0 )
    {
        // trees       
        float ot;
        vec4 res = raymarchTrees( ro, rd, t, bcol, ot );
        t = ot;
        col = col*(1.0-res.w) + res.xyz;
    }

    // sun glow
    col += vec3(1.0,0.5,0.2)*0.35*pow( sun, 3.0 );

    float rays = 0.0;
    // clouds   
    {
    if( t<0.0 ) t=600.0;
    vec4 res = raymarchClouds( ro, rd, bcol, t, rays, ivec2(fragCoord) );
    col = col*(1.0-res.w) + res.xyz;
    }

    col += (1.0-0.8*col)*rays*rays*rays*0.4*vec3(1.0,0.8,0.7);
    col = clamp( col, 0.0, 1.0 );

   
    // gamma   
    col = pow( col, vec3(0.45) );

    // contrast, desat, tint and vignetting   
    col = col*0.1 + 0.9*col*col*(3.0-2.0*col);
    col = mix( col, vec3(col.x+col.y+col.z)*0.33, 0.2 );
    col *= vec3(1.06,1.05,1.0);

    //-------------------------------------
    // velocity vectors (through depth reprojection)
    //-------------------------------------
    float vel = 0.0;
    if( t<0.0 )
    {
        vel = -1.0;
    }
    else
    {

        // old camera position
        float oldTime = time - 1.0/30.0; // 1/30 of a second blur
        vec3 oldRo, oldTa; float oldCr, oldFl;
        moveCamera( oldTime, oldRo, oldTa, oldCr, oldFl );
        mat3 oldCam = setCamera( oldRo, oldTa, oldCr );

        // world space
        vec3 wpos = ro + rd*t;
        // camera space
        vec3 cpos = vec3( dot( wpos - oldRo, oldCam[0] ),
                          dot( wpos - oldRo, oldCam[1] ),
                          dot( wpos - oldRo, oldCam[2] ) );
        // ndc space
        vec2 npos = oldFl * cpos.xy / cpos.z;
        // screen space
        vec2 spos = 0.5 + 0.5*npos*vec2(iResolution.y/iResolution.x,1.0);


        // compress velocity vector in a single float
        vec2 uv = fragCoord/iResolution.xy;
        spos = clamp( 0.5 + 0.5*(spos - uv)/0.25, 0.0, 1.0 );
        vel = floor(spos.x*255.0) + floor(spos.y*255.0)*256.0;
    }
   
    fragColor = vec4( col, vel );
}

, screen:

select Gray Noise Medium texture and set Filter “mipmap” and wrap “repeat”.
In Unity, you should try to translate code and you should generate own noise texture, to imitate Gray Noise Medium.

I remember, I tried to make this kind of texture in Unity, but I had artifacts. But successfully I made this one in C language, for volumetric smoke effect.

Here is complete C file, and look for SetTexture function:

// cl smoke.c opengl32.lib user32.lib gdi32.lib
// Przemyslaw Zaworski 11.12.2018

#include <windows.h>
#include <GL/gl.h>
#include <math.h>

typedef int(__stdcall *PFNWGLSWAPINTERVALEXTPROC)(int i);
typedef GLuint(__stdcall *PFNGLCREATEPROGRAMPROC)();
typedef GLuint(__stdcall *PFNGLCREATESHADERPROC)(GLenum t);
typedef void(__stdcall *PFNGLSHADERSOURCEPROC)(GLuint s, GLsizei c, const char *const *n, const GLint *i);
typedef void(__stdcall *PFNGLCOMPILESHADERPROC)(GLuint s);
typedef void(__stdcall *PFNGLATTACHSHADERPROC)(GLuint p, GLuint s);
typedef void(__stdcall *PFNGLLINKPROGRAMPROC)(GLuint p);
typedef void(__stdcall *PFNGLUSEPROGRAMPROC)(GLuint p);
typedef GLint(__stdcall *PFNGLGETUNIFORMLOCATIONPROC) (GLuint p, const char *n);
typedef void (__stdcall *PFNGLUNIFORM1FVPROC) (GLint k, GLsizei c, const GLfloat *v);
typedef void(__stdcall *PFNGLBINDVERTEXARRAYPROC) (GLuint a);
typedef void(__stdcall *PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint i);
typedef void(__stdcall *PFNGLVERTEXATTRIBPOINTERPROC) (GLuint i, GLint s, GLenum t, GLboolean n, GLsizei k, const void *p);
typedef void(__stdcall *PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint i);
typedef void(__stdcall *PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *a);
typedef void(__stdcall *PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *b);
typedef void(__stdcall *PFNGLBINDBUFFERPROC) (GLenum t, GLuint b);
typedef void(__stdcall *PFNGLBUFFERDATAPROC) (GLenum t, ptrdiff_t s, const GLvoid *d, GLenum u);
typedef void(__stdcall *PFNGLACTIVETEXTUREPROC) (GLenum t);
typedef void(__stdcall *PFNGLUNIFORM1IPROC) (GLint l, GLint v);

static const GLfloat vertices[] = {-1.0f,-1.0f,0.0f,1.0f,-1.0f,0.0f,-1.0f,1.0f,0.0f,1.0f,-1.0f,0.0f,1.0f,1.0f,0.0f,-1.0f,1.0f,0.0f};

static const char* FragmentShader = \
    "#version 430 \n"
    "layout (location=0) out vec4 color;"
    "uniform float time;"
    "uniform sampler2D hash;"
    "mat3 rotationX(float x)"
    "{"
        "return mat3(1.0,0.0,0.0,0.0,cos(x),sin(x),0.0,-sin(x),cos(x));"
    "}"
    "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 = textureLod( hash, (uv+ 0.5)/256.0, 0.0 ).yx;"
        "return mix( rg.x, rg.y, f.z );"
    "}"
    "vec4 map( vec3 p )"
    "{"
        "float d = 0.2 - p.y;"   
        "vec3 q = p  - vec3(0.0,1.0,0.0)*time;"
        "float f  = 0.50000*noise( q ); q = q*2.02 - vec3(0.0,1.0,0.0)*time;"
        "f += 0.25000*noise( q ); q = q*2.03 - vec3(0.0,1.0,0.0)*time;"
        "f += 0.12500*noise( q ); q = q*2.01 - vec3(0.0,1.0,0.0)*time;"
        "f += 0.06250*noise( q ); q = q*2.02 - vec3(0.0,1.0,0.0)*time;"
        "f += 0.03125*noise( q );"
        "d = clamp( d + 4.5*f, 0.0, 1.0 );"
        "vec3 col = mix( vec3(1.0,0.9,0.8), vec3(0.4,0.1,0.1), d ) + 0.05*sin(p);"
        "return vec4( col, d );"
    "}"
    "vec3 raymarch( vec3 ro, vec3 rd )"
    "{"
        "vec4 s = vec4( 0,0,0,0 );"
        "float t = 0.0;"   
        "for( int i=0; i<128; i++ )"
        "{"
            "if( s.a > 0.99 ) break;"
            "vec3 p = ro + t*rd;"
            "vec4 k = map( p );"
            "k.rgb *= mix( vec3(3.0,1.5,0.15), vec3(0.5,0.5,0.5), clamp( (p.y-0.2)/2.0, 0.0, 1.0 ) );"
            "k.a *= 0.5;"
            "k.rgb *= k.a;"
            "s = s + k*(1.0-s.a);"   
            "t += 0.05;"
        "}"
        "return clamp( s.xyz, 0.0, 1.0 );"
    "}"
    "void main()"
    "{"
        "vec3 ro = vec3(0.0,4.9,-40.);"
        "vec3 rd = normalize(vec3((2.0*gl_FragCoord.xy-vec2(1280,720))/720,2.0)) * rotationX(5.2);"
        "vec3 volume = raymarch( ro, rd );"
        "volume = volume*0.5 + 0.5*volume*volume*(3.0-2.0*volume);"
        "color = vec4( volume, 1.0 );"
    "}";

void SetTexture (int shader, const char *name)
{
    unsigned char Texels [256][256][4];
    for (int i = 0; i < 256; i++)
    {
        for (int j = 0; j < 256; j++)
        {
            float h = (float)fmod(sin(j*12.9898 + i*4.1413)*43758.5453f, 1.0);
            float k = (float)fmod(cos(i*19.6534 + j*7.9813)*51364.8733f, 1.0);
            Texels[j][i][0] = (unsigned char)(h * 255);
            Texels[j][i][2] = (unsigned char)(k * 255);
        }
    }
    for (int i = 0; i < 256; i++)
    {
        for (int j = 0; j < 256; j++)
        {
            int x2 = (j - 17) & 255;
            int y2 = (i - 37) & 255;
            Texels[j][i][1] = Texels[x2][y2][0];
            Texels[j][i][3] = Texels[x2][y2][2];
        }
    }
    ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"))(0x84C0);
    glBindTexture(0x806F, 0);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,Texels);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    int loc = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"))(shader, name);
    ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"))(loc, 0);   
}

static LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    if( uMsg==WM_SYSCOMMAND && (wParam==SC_SCREENSAVE || wParam==SC_MONITORPOWER) )
        return 0;
    if( uMsg==WM_CLOSE || uMsg==WM_DESTROY || (uMsg==WM_KEYDOWN && wParam==VK_ESCAPE) )
    {
        PostQuitMessage(0);
        return 0;
    }
    if( uMsg==WM_SIZE )
    {
        glViewport( 0, 0, lParam&65535, lParam>>16 );
    }
    if( uMsg==WM_CHAR || uMsg==WM_KEYDOWN)
    {
        if( wParam==VK_ESCAPE )
        {
            PostQuitMessage(0);
            return 0;
        }
    }
    return(DefWindowProc(hWnd,uMsg,wParam,lParam));
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    MSG msg;
    int exit = 0;
    unsigned int VertexBuffer, VertexArrayID;
    PIXELFORMATDESCRIPTOR pfd = { 0,0,PFD_DOUBLEBUFFER };
    WNDCLASS win;
    ZeroMemory( &win, sizeof(WNDCLASS) );
    win.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
    win.lpfnWndProc = WindowProc;
    win.hInstance = 0;
    win.lpszClassName = "smoke";
    win.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
    RegisterClass(&win);
    HDC hdc = GetDC(CreateWindowEx(0, win.lpszClassName, "Volumetric Smoke", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0, 0, 1280, 720, 0, 0, 0, 0));
    SetPixelFormat(hdc,ChoosePixelFormat(hdc,&pfd),&pfd);
    wglMakeCurrent(hdc,wglCreateContext(hdc));
    ((PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT")) (0);
    ((PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays")) (1, &VertexArrayID);
    ((PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray")) (VertexArrayID);
    ((PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers"))(1, &VertexBuffer);
    ((PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer"))(0x8892, VertexBuffer);
    ((PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData"))(0x8892, sizeof(vertices), vertices, 0x88E4);
    int p = ((PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram"))();
    int s = ((PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader"))(0x8B30);
    ((PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource"))(s, 1, &FragmentShader, 0);
    ((PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader"))(s);
    ((PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader"))(p, s);
    ((PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram"))(p);
    SetTexture (p, "hash");   
    ((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(p);
    GLint location = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"))(p,"time");
    DWORD S = GetTickCount();
    while( !exit )
    {
        while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
        {
            if( msg.message==WM_QUIT ) exit = 1;
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        float t = (GetTickCount()-S)*0.001f;
        ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"))(location, 1, &t);
        ((PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray"))(0);
        ((PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer"))(0x8892, VertexBuffer);
        ((PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer"))(0,3, GL_FLOAT, GL_FALSE, 0,(void*)0 );
        glDrawArrays(GL_TRIANGLES, 0, 2*3);
        ((PFNGLDISABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glDisableVertexAttribArray"))(0);
        wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
    }
    return 0;
}

Thank you so much for your help and time. I will do as you have suggested. I will let you know if I run into problems.

Done.