float calcNoise(vec3 uvw) { float baseScale = 1.0; float n = 0.0; n += snoise(uvw * baseScale); n += 0.5 * snoise(uvw * baseScale*2.0); //n += 0.25 * snoise(uvw * baseScale*4.0); //n += 0.125 * snoise(uvw * baseScale*8.0); /* n += 0.0625 * snoise(uvw * baseScale*16.0); n += 0.03125 * snoise(uvw * baseScale*32.0); n += 0.015625 * snoise(uvw * baseScale*64.0); n += 0.0078125 * snoise(uvw * baseScale*128.0); */ //n = (n + 1.0)/2.0; //n = clamp(n*1.3,0.0,1.0); //n = pow(n,4.0); return n; }
void main(void) { mat3 matColor = mat3(colorR, colorG, colorB); vec3 uv = v_texCoord3D * 50.0; float w = 1.0; float h = 1.0; float r = mul.r * zero_one(snoise(vec3(uv.x * w * freqR.x, uv.y * h * freqR.y, speed.r * time)) + add.r); float g = mul.g * zero_one(snoise(vec3(uv.x * w * freqG.x, uv.y * h * freqG.y, speed.g * time)) + add.g); float b = mul.b * zero_one(snoise(vec3(uv.x * w * freqB.x, uv.y * h * freqB.y, speed.b * time)) + add.b); vec3 rgb = vec3(r, g, b); gl_FragColor = vec4((matColor * rgb), alpha); }
void main(){ //input line coordinates vec2 p0 = gl_PositionIn[0].xy; vec2 p1 = gl_PositionIn[1].xy; //generate 50 lines and distort with perlin noise for (int i = 0; i < 50; i++){ float x0 = snoise(vec4(p0 *3.0, time * 0.5 + 12.4, i)); float y0 = snoise( vec4( p0 * 3.0, time * 0.5 + 304.2, i ) ); float x1 = snoise( vec4( p1 * 3.0, time * 0.5 + 20.1, i ) ); float y1 = snoise( vec4( p1 * 3.0, time * 0.5 + 43.6, i ) ); vec2 q0 = p0 + vec2( x0, y0 ) * 25.0; vec2 q1 = p1 + vec2( x1, y1 ) * 25.0; //calculate color vec4 color = vec4(0.0); vec2 delta = q1 - q0; float len = distance( delta, vec2( 0.0 ) ); if ( len > 0 ) { int n = int( len ) + 1; delta /= n; for (int i=0; i<n; i++) { color += texture2DRect( texture, q0 + delta * i ); } color /= n; } color.a *= 0.4; //Making output color transparent //output line gl_Position = gl_ModelViewProjectionMatrix * vec4(q0, 0.0, 1.0); gl_FrontColor = color; //0 - left color, 1 - right color EmitVertex(); gl_Position = gl_ModelViewProjectionMatrix * vec4(q1, 0.0, 1.0); gl_FrontColor = color; //0 - left color, 1 - right color EmitVertex(); EndPrimitive(); } }
/*---------------------------------------------------------------------- Turbulence (as described in Advanced RenderMan) ----------------------------------------------------------------------*/ double turbulence(double x, double y, double z, int octaves, double lacunarity, double gain) { double res=0.0; double amp=1.0; for(int i=0; i<octaves; i+=1) { res += amp*fabs(snoise(x,y,z)); amp *= gain; x *= lacunarity; y *= lacunarity; z *= lacunarity; } return 0.5*(res+1.0); }
// Result is in [0,1] double noise(double x, double y, double z) { return 0.5 * (1.0 + snoise(x, y, z)); }
int generator(float i,float j,float w,float h,int t, int layer, int* refl){ float r=0.0; float b=0.0; float g=0.0; float c=1.0,o; float bmul=1.0; float x,y; float d=0.0; float s=2.0*snoise(0.19*(i)/4.0,1.1*(j)/3.0)+0.5*4.6*snoise(0.19*(i/5.0),1.1*(j/5.0)); float s2=0.2*snoise(0.19*(i)/4.0,1.1*(i)/2.0)+0.2*2.3*snoise(0.19*(i/5.0),1.1*(0.6+j/5.0)); *refl=0; if(j<0.6*h){ *refl=0xff00; float x0y=1.6*bfnoise(0.25*(i+1000*t),0.25*(1000*t+j-32)); float x1y=1.6*bfnoise(0.25*(i+1000*t),0.25*(1000*t+j+32)); float y0x=0.3*bfnoise(0.25*(i+1000*t-32),0.25*(1000*t+j)); float y1x=0.3*bfnoise(0.25*(i+1000*t+32),0.25*(1000*t+j)); y0x+=0.25*t*bfnoise(0.05*(i+1000*t-32),0.25*(1000*t+j)); y1x+=0.25*bfnoise(0.05*(i+1000*t+32),0.25*(1000*t+j)); y0x+=1.2*bfnoise(0.15*(i+1000*t-32),0.25*(1000*t+j)); y1x+=1.2*bfnoise(0.15*(i+1000*t+32),0.25*(1000*t+j)); float curl=(y1x-y0x-x1y+x0y)/64.0; float v=sqrt(1-curl*curl); i=i-(232/j)*v*cos(0.3*t); j=j-(132)*curl; s=2.0*bfnoise(0.19*(i)/4.0,1.1*(j)/3.0)+0.5*4.6*snoise(0.19*(i/5.0),1.1*(j/5.0)); d=1; s2=0.2*bfnoise(0.19*(i)/4.0,1.1*(i)/2.0)+0.2*2.3*snoise(0.19*(i/5.0),1.1*(0.6+j/5.0)); c=0.1; o=0.9; for(int m=1; m<3; ++m){ float s3=2.0*snoise(0.19*(i)/4.0,1.1*(j+m)/3.0)+0.5*4.6*snoise(0.19*(i/5.0),1.1*((j+m)/5.0)); o=s3*o+0.1; c+=s3*s3*s*(1.0/(m+1.1))*o/17.0; } if( (float)(j)/h<0.6){ d=j*60.0-s*20.0; r=snoise(0.1*i,i)+0.3*snoise(0.4,(int)(0.1*i)); x=floor(i); y=floor(j); int n=1; if(((float)(j))/h<0.03*s+0.55){ float d1=exp(-abs(0.6+0.06*s-0.1-(float)(j)/h)); float d2=exp(-abs(0.65-0.1-(float)(j)/h)); float d3= min(1.0,1.0-2.0*d2)*min(1.0,1.0-2.0*d1)*exp(-0.3*abs(0.65-0.1-(float)(j)/h)); x=sin(s-0.09*(int)(s*i/8.0)); y=sin(s-0.09*(int)(s*j/8.0)); s2=6.0*s*(int)(snoise(x,y)*6.0); float r1,g1,b1,r2,g2,b2,r3,g3,b3; r1=0.1+2.3*(h-j)/(float)(h)*(0.1+s)-0.12*(int)(s*1.1*s)/(s+3.0)+0.3+(1-1.2*s)*exp(-1.9*s); g1=0.1+2.3*(h-j)/(float)(h)*(0.1+s)-0.13*(int)(s*1.1*s)/(s+3.0)+0.2+(1-1.1*s)*exp(-1.9*s); b1=0.8; r2=s*0.8; g2=(s*0.2+0.5); b2=(s+0.3); r3=0.1; g3=0.11; b3=0.1; r=0.77+0.12*(r1*d1+r2*min(1.0-2.0*d1,1.0)*d2+r3*d3); g=0.65+0.12*(g1*d1+g2*min(1.0,1.0-2.0*d1)*d2+g3*d3); b=0.978+0.12*(b1*d1+b2*min(1.0,1.0-2.0*d1)*d2+b3*d3); i=i+s*4.0; float s4=0.2*snoise(0.19*(i)/4.0,1.1*(i)/2.0)+0.2*2.3*snoise(0.19*(i/5.0),1.1*(0.6+j/5.0)); i=i-s*4.0; r=(1-lerp(s2,1.0,1.0-j/(h*2.0))); } else{ r=0.2; g=0.3; b=0.5; } if( 0.6-(float)(0.5*j)/h>6.0*s2){ r=0.5; g=0.24; b=0.6; } r=r*(j)/h+0.2; g=g*(j)/h+0.1; b=0.3; } } else if( j<0.64*h+2.0*snoise(0.4,i)){ g=r=0.2; b=0.6; d=12000.0; } else if(snoise(i*0.001,1.0)<0.5 && j+0.6<56.0*snoise(0.4,(int)(0.1*i))+0.65*h){ d=12000.0+590.0; r=snoise(0.1*i,i)+0.3*snoise(0.4,(int)(0.1*i)); x=(int)(i); y=(int)(j); int n=1; for (int m=0; m<5; ++m){ if(((int)x)%3==1 && ((int)(y))%3==1) { b=1.0; n=0; break; } x /= 1+snoise(i,j); y /= 1+snoise(i,j); } if( n) g*=0.5; else{ for(int m=0; m<5; ++m){ x=(int)(i+6); y=(int)(j+6); int n=1; int nc=0; while((x>0 || y>0) && nc<3){ ++nc; if(((int)x)%3==1 && ((int)y)%3==1) { b=1.0; n=0; break; } } x /= 1+snoise(i,j); y /= 1+snoise(i,j); if (n) g=1.5; } } } else if( j+0.6<56.0*snoise(i,0.3*i)+0.65*h){ d=20000; r=s2; } else if((float)(j)<0.78*h+0.2*sin(0.1*j)){ d=20000.0; r=0.04; g=0.0; b=0.02; } else{ d=20000.0; i*=0.008; j*=0.9; x=i*0.1; y=j*0.1; r=snoise(0.3*i,0.2*j-snoise(x,y))+snoise(0.3*i,0.2*j); g=0.3+0.5/(1.0-r*0.5+0.14); b=1.0-0.3/(1.0-0.2); r=1.0+0.4/(1.0-r); g*=0.3; b*=0.2+0.1*snoise(i,j+i); r*=0.1+0.2*snoise(i,j+i); } if( snoise(i,j+i)*h+0.6*h<1.0*j) b=b+0.1; int br=(int)(255.0*(c+0.1)*r); int bg=(int)(255.0*(c+0.1)*g); int bb=(int)(255.0*(c+0.24)*(b+0.3)*bmul); return br*256+bg*65536+bb*256*256*256+255; }
btScalar duWater::getWaterLevel(btScalar pos_x, btScalar pos_z, int wrapperNum) { // get water wrapper by index duWater::WaterWrapper *wWrapper = wrapperByInd(wrapperNum); if (!wWrapper) return btScalar(0.0); if (!wWrapper->wavesHeight) return wWrapper->waterLevel; float time = m_time; ////////// DISTANT WAVES ////////// // first component float noise_coords[2]; duWaterDynInfo* dynInfo = wWrapper->dynamicsInfo; noise_coords[0] = dynInfo->dst_noise_scale0 * (pos_x + dynInfo->dst_noise_freq0 * time); noise_coords[1] = dynInfo->dst_noise_scale0 * (pos_z + dynInfo->dst_noise_freq0 * time); float noise1 = snoise(noise_coords); // second component noise_coords[0] = dynInfo->dst_noise_scale1 * (pos_z - dynInfo->dst_noise_freq1 * time); noise_coords[1] = dynInfo->dst_noise_scale1 * (pos_x - dynInfo->dst_noise_freq1 * time); float noise2 = snoise(noise_coords); float dist_waves = wWrapper->wavesHeight * noise1 * noise2; float wave_height; if (wWrapper->wDistArray) { ////////// SHORE WAVES ////////// // get coordinates in texture pixels double x = (pos_x - wWrapper->shoreMapCenterX) / wWrapper->shoreMapSizeX; double z = (wWrapper->shoreMapCenterZ + pos_z) / wWrapper->shoreMapSizeZ; x += 0.5f; z += 0.5f; // if position is out of boundings, consider that shore dist = 1 if (x > 1.f || x < 0.f || z > 1.f || z < 0.f) wave_height = dist_waves; else { // get coordinates in pixels int array_width = wWrapper->shoreMapTexSize; x *= array_width - .5f; z *= array_width - .5f; double floor_px; double floor_py; float fract_px = modf(x, &floor_px); float fract_py = modf(z, &floor_py); int px = static_cast<int>(floor_px); int py = static_cast<int>(floor_py); btScalar *distArray = wWrapper->wDistArray; int up_lim = array_width - 1; float dist00 = distArray[py * array_width + px]; float dist10 = distArray[py * array_width + btMin(px + 1, up_lim)]; float dist01 = distArray[btMin(py + 1, up_lim) * array_width + px]; float dist11 = distArray[btMin(py + 1, up_lim) * array_width + btMin(px + 1, up_lim)]; // distance on bottom, top edge float dist0010 = dist00 * (1.f - fract_px) + dist10 * fract_px; float dist0111 = dist01 * (1.f - fract_px) + dist11 * fract_px; float shore_dist = dist0010 * (1.f - fract_py) + dist0111 * fract_py; float shore_waves_length = wWrapper->wavesLength / float(wWrapper->maxShoreDist) / M_PI; float waves_coords[2] = {dynInfo->dir_noise_scale * (pos_x + dynInfo->dir_noise_freq * time), dynInfo->dir_noise_scale * (pos_z + dynInfo->dir_noise_freq * time)}; float dist_fact = sqrt(shore_dist); float shore_dir_waves = wWrapper->wavesHeight * fmax(shore_dist, dynInfo->dir_min_shore_fac) * sinf((dist_fact / shore_waves_length + dynInfo->dir_freq * time)) * fmax(snoise(waves_coords), dynInfo->dir_min_noise_fac); // mix two types of waves basing on distance to the shore float mix_rate = btMax(dist_fact, dynInfo->dst_min_fac); wave_height = shore_dir_waves * (1 - mix_rate) + dist_waves * mix_rate; } } else wave_height = dist_waves; btScalar cur_water_level = wWrapper->waterLevel + wave_height; return cur_water_level; }