uniform float Time; uniform sampler2D NoiseMap; uniform float NoiseWidth; uniform float NoiseHeight; vec4 gNoise( vec2 idata ) { vec4 iNoise = texture2D( NoiseMap, idata ); vec4 tNoise = texture2D( NoiseMap, iNoise.xy + floor(idata)/3.2456 ); return tNoise; } vec4 gNoise( vec3 idata ) { vec4 iNoise = texture2D( NoiseMap, idata.xy ); vec4 iNoiseB = texture2D( NoiseMap, vec2(idata.z,idata.z) ); vec4 tNoise = texture2D( NoiseMap, iNoise.xy + iNoiseB.xy + vec2( floor(idata.xy)/3.2456 ) + vec2( floor(idata.z) )/3.52456 ); return tNoise; } vec4 gNoise( vec4 idata ) { vec4 iNoise = texture2D( NoiseMap, idata.xy ); vec4 iNoiseB = texture2D( NoiseMap, idata.zw ); vec4 tNoise = texture2D( NoiseMap, iNoise.xy + iNoiseB.xy + vec2( floor(idata.xy)/3.2456 ) + vec2( floor(idata.zw) )/3.52456 ); return tNoise; } vec4 bNoise( vec2 PLoc ) { vec2 MixDist = (PLoc*NoiseWidth - floor( PLoc*NoiseWidth )); return mix( mix( gNoise( PLoc ), gNoise( PLoc + vec2( 1.0/NoiseWidth, 0.0 ) ), MixDist.x ), mix( gNoise( PLoc + vec2( 0.0, 1.0/NoiseHeight ) ), gNoise( PLoc + vec2( 1.0/NoiseWidth, 1.0/NoiseHeight ) ), MixDist.x ), MixDist.y ); } float pNoise( vec2 PLoc ) { vec2 MixDist = (PLoc*NoiseWidth - floor( PLoc*NoiseWidth )); vec2 iMixDist = -(1.0 - MixDist); //Original Perlin Noise vec2 FnMix = 3.0 * MixDist*MixDist - 2.0 * MixDist * MixDist * MixDist; //Improved Perlin Noise // vec2 MDSquared = MixDist*MixDist; // vec2 MDCubed = MDSquared*MixDist; // vec2 FnMix = 6.0 * MDCubed*MDSquared - 15.0 * MDSquared * MDSquared + 10. * MDCubed; vec4 Upper = vec4( gNoise( PLoc ).xy, gNoise( PLoc + vec2( 1.0/NoiseWidth, 0.0 ) ).xy ); vec4 Lower = vec4( gNoise( PLoc + vec2( 0.0, 1.0/NoiseHeight ) ).xy, gNoise( PLoc + vec2( 1.0/NoiseWidth, 1.0/NoiseHeight ) ).xy ); vec4 US = (floor( Upper * 2.0 ) - 0.5)*2.0; vec4 LS = (floor( Lower * 2.0 ) - 0.5)*2.0; vec4 Mix = vec4( dot( US.xy, vec2( MixDist.x, MixDist.y) ), dot( US.zw, vec2( iMixDist.x, MixDist.y) ), dot( LS.xy, vec2( MixDist.x, iMixDist.y) ), dot( LS.zw, vec2( iMixDist.x, iMixDist.y) ) ); return mix( mix( Mix.x, Mix.y, FnMix.x ), mix( Mix.z, Mix.w, FnMix.x ), FnMix.y ); } float pNoise( vec3 PLoc ) { vec3 MixDist = (PLoc*NoiseWidth - floor( PLoc*NoiseWidth )); vec3 iMixDist = -(1.0 - MixDist); //Original Perlin Noise vec3 FnMix = 3.0 * MixDist*MixDist - 2.0 * MixDist * MixDist * MixDist; //Improved Perlin Noise // vec2 MDSquared = MixDist*MixDist; // vec2 MDCubed = MDSquared*MixDist; // vec2 FnMix = 6.0 * MDCubed*MDSquared - 15.0 * MDSquared * MDSquared + 10. * MDCubed; vec3 UL = gNoise( PLoc ).xyz; vec3 UR = gNoise( PLoc + vec3( 1.0/NoiseWidth, 0.0, 0.0 ) ).xyz; vec3 LL = gNoise( PLoc + vec3( 0.0, 1.0/NoiseHeight, 0.0 ) ).xyz; vec3 LR = gNoise( PLoc + vec3( 1.0/NoiseWidth, 1.0/NoiseHeight,0.0 ) ).xyz; vec3 ULS = (floor( UL * 2.0 ) - 0.5)*2.0; vec3 URS = (floor( UR * 2.0 ) - 0.5)*2.0; vec3 LLS = (floor( LL * 2.0 ) - 0.5)*2.0; vec3 LRS = (floor( LR * 2.0 ) - 0.5)*2.0; vec4 MixA = vec4( dot( ULS.xyz, vec3( MixDist.x, MixDist.y, MixDist.z) ), dot( URS.xyz, vec3( iMixDist.x, MixDist.y, MixDist.z) ), dot( LLS.xyz, vec3( MixDist.x, iMixDist.y, MixDist.z) ), dot( LRS.xyz, vec3( iMixDist.x, iMixDist.y, MixDist.z) ) ); UL = gNoise( PLoc + vec3( 0.0, 0.0, 1.0/NoiseHeight ) ).xyz; UR = gNoise( PLoc + vec3( 1.0/NoiseWidth, 0.0, 1.0/NoiseHeight ) ).xyz; LL = gNoise( PLoc + vec3( 0.0, 1.0/NoiseHeight, 1.0/NoiseHeight ) ).xyz; LR = gNoise( PLoc + vec3( 1.0/NoiseWidth, 1.0/NoiseHeight, 1.0/NoiseHeight ) ).xyz; ULS = (floor( UL * 2.0 ) - 0.5)*2.0; URS = (floor( UR * 2.0 ) - 0.5)*2.0; LLS = (floor( LL * 2.0 ) - 0.5)*2.0; LRS = (floor( LR * 2.0 ) - 0.5)*2.0; vec4 MixB = vec4( dot( ULS.xyz, vec3( MixDist.x, MixDist.y, iMixDist.z) ), dot( URS.xyz, vec3( iMixDist.x, MixDist.y, iMixDist.z) ), dot( LLS.xyz, vec3( MixDist.x, iMixDist.y, iMixDist.z) ), dot( LRS.xyz, vec3( iMixDist.x, iMixDist.y, iMixDist.z) ) ); return mix( mix( mix( MixA.x, MixA.y, FnMix.x ), mix( MixA.z, MixA.w, FnMix.x ), FnMix.y ), mix( mix( MixB.x, MixB.y, FnMix.x ), mix( MixB.z, MixB.w, FnMix.x ), FnMix.y ), FnMix.z ); } vec4 GenMixFor4DNoise( vec4 PLoc, vec4 MixDist, vec4 iMixDist, vec4 transadd, vec4 MDZW ) { vec4 UL = gNoise( PLoc + vec4( 0.0, 0.0, 0.0, 0.0 ) + transadd ) ; vec4 UR = gNoise( PLoc + vec4( 1.0/NoiseWidth, 0.0, 0.0, 0.0 ) + transadd ); vec4 LL = gNoise( PLoc + vec4( 0.0, 1.0/NoiseHeight, 0.0, 0.0 ) + transadd ); vec4 LR = gNoise( PLoc + vec4( 1.0/NoiseWidth, 1.0/NoiseHeight,0.0, 0.0 ) + transadd ); vec4 ULS = (floor( UL * 2.0 ) - 0.5)*2.0; vec4 URS = (floor( UR * 2.0 ) - 0.5)*2.0; vec4 LLS = (floor( LL * 2.0 ) - 0.5)*2.0; vec4 LRS = (floor( LR * 2.0 ) - 0.5)*2.0; return vec4( dot( ULS.xyzw, vec4( MixDist.x, MixDist.y, 0.0, 0.0) ), dot( URS.xyzw, vec4( iMixDist.x, MixDist.y, 0.0, 0.0) ), dot( LLS.xyzw, vec4( MixDist.x, iMixDist.y, 0.0, 0.0) ), dot( LRS.xyzw, vec4( iMixDist.x, iMixDist.y, 0.0, 0.0) ) ); } float pNoise( vec4 PLoc ) { vec4 MixDist = (PLoc*NoiseWidth - floor( PLoc*NoiseWidth )); vec4 iMixDist = -(1.0 - MixDist); //Original Perlin Noise // vec4 FnMix = 3.0 * MixDist*MixDist - 2.0 * MixDist * MixDist * MixDist; //Improved Perlin Noise vec4 MDSquared = MixDist*MixDist; vec4 MDCubed = MDSquared*MixDist; vec4 FnMix = 6.0 * MDCubed*MDSquared - 15.0 * MDSquared * MDSquared + 10. * MDCubed; vec4 MixA = GenMixFor4DNoise( PLoc, MixDist, iMixDist, vec4( 0.0, 0.0, 0.0, 0.0 ), vec4( 0.0, 0.0, MixDist.z, MixDist.w ) ); vec4 MixB = GenMixFor4DNoise( PLoc, MixDist, iMixDist, vec4( 0.0, 0.0, 1.0/NoiseHeight, 0.0 ), vec4( 0.0, 0.0, iMixDist.z, MixDist.w ) ); vec4 MixC = GenMixFor4DNoise( PLoc, MixDist, iMixDist, vec4( 0.0, 0.0, 0.0, 1.0/NoiseHeight ), vec4( 0.0, 0.0, MixDist.z, iMixDist.w ) ); vec4 MixD = GenMixFor4DNoise( PLoc, MixDist, iMixDist, vec4( 0.0, 0.0, 1.0/NoiseHeight, 1.0/NoiseHeight ), vec4( 0.0, 0.0, iMixDist.z, iMixDist.w ) ); return mix( mix( mix( mix( MixA.x, MixA.y, FnMix.x ), mix( MixA.z, MixA.w, FnMix.x ), FnMix.y ), mix( mix( MixB.x, MixB.y, FnMix.x ), mix( MixB.z, MixB.w, FnMix.x ), FnMix.y ), FnMix.z ), mix( mix( mix( MixC.x, MixC.y, FnMix.x ), mix( MixC.z, MixC.w, FnMix.x ), FnMix.y ), mix( mix( MixD.x, MixD.y, FnMix.x ), mix( MixD.z, MixD.w, FnMix.x ), FnMix.y ), FnMix.z ), FnMix.w ); } void main() { // if( gl_Color.a > 0.5 ) discard; gl_FragColor= vec4( gl_Color.xww, 0 ); return; float Detail = min((abs(dFdx( gl_TexCoord[0].x)) + abs(dFdy(gl_TexCoord[0].y)) + abs(dFdy( gl_TexCoord[0].x)) + abs(dFdx(gl_TexCoord[0].y)))*4.0,1.0); /* //Straight noise float fNoise = pNoise( vec3( gl_TexCoord[0].xyz*1.0) ); fNoise = mix( fNoise, 0.0, sqrt(Detail) ); vec4 Noise = vec4( fNoise + 0.5,0.0, 0.0, 0.0); gl_FragColor = vec4( Noise.xyz, 1.0 ); */ //Wood Shader float fNoise = pNoise( vec2( gl_TexCoord[0].xy*0.2 ) ); float fCoreDist = length( gl_TexCoord[0].xy + vec2( gl_TexCoord[0].z * 0.5-1.0, 0.0 ) ) * 3.0; fCoreDist += fNoise*0.4; fCoreDist = mod( fCoreDist, 0.8 ); fCoreDist = mix( fCoreDist, 0.5, pow(Detail,0.5) ); vec4 Noise = vec4( fCoreDist + 0.2 ); Noise = Noise * vec4( 0.7, 0.5, 0.0, 0.0 ) + vec4( 0.4, 0.2, 0.0, 0.0 ); gl_FragColor = vec4( Noise.xyz, 1.0 ); /* //Turbulent noise float fNoise = pNoise( vec3( gl_TexCoord[0].xyz*0.2) ); fNoise *= fNoise; vec4 Noise = vec4( fNoise*4.0+0.0,0.0, 0.0, 0.0); gl_FragColor = vec4( Noise.xyz, 1.0 ); */ /* float fNoise = pNoise( vec4( gl_TexCoord[0].xyz*0.2, Time) ); fNoise *= fNoise; vec4 Noise = vec4( fNoise*4.0); gl_FragColor = vec4( Noise.xyz, 1.0 ); */ }