Changeset 1840


Ignore:
Timestamp:
Aug 30, 2012, 8:17:04 PM (7 years ago)
Author:
sam
Message:

tutorial: use a better value noise function that does not suffer from the
same discontinuity issues as the sin() approach.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tutorial/03_noise.lolfx

    r1830 r1840  
    1616uniform float u_Time;
    1717
     18vec3 mod289(vec3 x)
     19{
     20    return x - floor(x * (1.0 / 289.0)) * 289.0;
     21}
     22
     23vec3 perm(vec3 x)
     24{
     25    return mod289(((x * 34.0) + 1.0) * x);
     26}
     27
    1828vec4 noise3d(vec3 p1, vec3 p2, vec3 p3, vec3 p4)
    1929{
    20     vec3 q = vec3(12.3453, -54.3353432, 34.3490432);
    21     vec4 s = vec4(dot(p1, q), dot(p2, q), dot(p3, q), dot(p4, q));
    22     return fract(sin(54.343909 + s) * 8433.235443);
     30    p1 = perm(perm(perm(p1) + p1.zxy) + p1.yzx);
     31    p2 = perm(perm(perm(p2) + p2.zxy) + p2.yzx);
     32    p3 = perm(perm(perm(p3) + p3.zxy) + p3.yzx);
     33    p4 = perm(perm(perm(p4) + p4.zxy) + p4.yzx);
     34    return fract(vec4(p1.x, p2.x, p3.x, p4.x) / 41.0);
    2335}
    2436
     
    8597-- HLSL.Frag --
    8698
     99float3 mod289(float3 x)
     100{
     101    return x - floor(x * (1.0 / 289.0)) * 289.0;
     102}
     103
     104float3 perm(float3 x)
     105{
     106    return mod289(((x * 34.0) + 1.0) * x);
     107}
     108
    87109float4 noise3d(float3 p1, float3 p2, float3 p3, float3 p4)
    88110{
    89     float3 q = float3(12.3453, -54.3353432, 34.3490432);
    90     float4 s = float4(dot(p1, q), dot(p2, q), dot(p3, q), dot(p4, q));
    91     return frac(sin(54.343909 + s) * 8433.235443);
     111    p1 = perm(perm(perm(p1) + p1.zxy) + p1.yzx);
     112    p2 = perm(perm(perm(p2) + p2.zxy) + p2.yzx);
     113    p3 = perm(perm(perm(p3) + p3.zxy) + p3.yzx);
     114    p4 = perm(perm(perm(p4) + p4.zxy) + p4.yzx);
     115    return frac(float4(p1.x, p2.x, p3.x, p4.x) / 41.0);
    92116}
    93117
Note: See TracChangeset for help on using the changeset viewer.