uniform sampler3D ttt3D; uniform float extraNoiseScale = 1.0f; uniform float noiseScale = 0.03f; float noise(float p) { return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, 0.5, 0.5)).x; } float noise(float p, float q) { return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, q*noiseScale*extraNoiseScale, 0.5)).x; } float snoise(float p) { return noise(p)*2.0f - 1.0f; } float snoise(float p, float q) { return noise(p, q)*2.0f - 1.0f; } float boxstep(float a, float b, float x) { return (clamp(((x)-(a)) / ((b)-(a)), 0, 1)); } uniform float Ka = 1; uniform float Kd = 0.75; uniform float Ks = 0.15; uniform float roughness = 0.025; uniform vec3 specularcolor = vec3(1, 1, 1); uniform float ringscale = 0; uniform float grainscale = 0; uniform float txtscale = 1; uniform float plankspertile = 4; uniform vec3 lightwood = vec3(0.57, 0.292, 0.125); uniform vec3 darkwood = vec3(0.275, 0.15, 0.06); uniform vec3 groovecolor = vec3(.05, .04, .015); //uniform float plankwidth = .05; uniform float plankwidth = .2; uniform float groovewidth = 0.001; uniform float plankvary = 0.8; uniform float grainy = 1; uniform float wavy = 0.08; uniform float MINFILTERWIDTH = 1.0e-7; vec3 myTexture3D_0(vec3 p) { float r; float r2; float whichrow; float whichplank; float swidth; float twidth; float fwidth; float ss; float tt; float w; float h; float fade; float ttt; vec3 Ct; vec3 woodcolor; float groovy; float PGWIDTH; float PGHEIGHT; float GWF; float GHF; float tilewidth; float whichtile; float tmp; float planklength; PGWIDTH = plankwidth + groovewidth; planklength = PGWIDTH * plankspertile - groovewidth; PGHEIGHT = planklength + groovewidth; GWF = groovewidth*0.5 / PGWIDTH; GHF = groovewidth*0.5 / PGHEIGHT; // Determine how wide in s-t space one pixel projects to float s = p.x; float t = p.y; float du = 1.0; float dv = 1.0; swidth = (max(abs(dFdx(s)*du) + abs(dFdy(s)*dv), MINFILTERWIDTH) / PGWIDTH) * txtscale; twidth = (max(abs(dFdx(t)*du) + abs(dFdy(t)*dv), MINFILTERWIDTH) / PGHEIGHT) * txtscale; fwidth = max(swidth, twidth); ss = (txtscale * s) / PGWIDTH; whichrow = floor(ss); tt = (txtscale * t) / PGHEIGHT; whichplank = floor(tt); if (mod(whichrow / plankspertile + whichplank, 2) >= 1) { ss = txtscale * t / PGWIDTH; whichrow = floor(ss); tt = txtscale * s / PGHEIGHT; whichplank = floor(tt); tmp = swidth; swidth = twidth; twidth = tmp; } ss -= whichrow; tt -= whichplank; whichplank += 20 * (whichrow + 10); if (swidth >= 1) w = 1 - 2 * GWF; else w = clamp(boxstep(GWF - swidth, GWF, ss), max(1 - GWF / swidth, 0), 1) - clamp(boxstep(1 - GWF - swidth, 1 - GWF, ss), 0, 2 * GWF / swidth); if (twidth >= 1) h = 1 - 2 * GHF; else h = clamp(boxstep(GHF - twidth, GHF, tt), max(1 - GHF / twidth, 0), 1) - clamp(boxstep(1 - GHF - twidth, 1 - GHF, tt), 0, 2 * GHF / twidth); // This would be the non-antialiased version: //w = step (GWF,ss) - step(1-GWF,ss); //h = step (GHF,tt) - step(1-GHF,tt); groovy = w*h; // Add the ring patterns fade = smoothstep(1 / ringscale, 8 / ringscale, fwidth); if (fade < 0.999) { ttt = tt / 4 + whichplank / 28.38 + wavy * noise(8 * ss, tt / 4); r = ringscale * noise(ss - whichplank, ttt); r -= floor(r); r = 0.3 + 0.7*smoothstep(0.2, 0.55, r)*(1 - smoothstep(0.75, 0.8, r)); r = (1 - fade)*r + 0.65*fade; // Multiply the ring pattern by the fine grain fade = smoothstep(2 / grainscale, 8 / grainscale, fwidth); if (fade < 0.999) { r2 = 1.3 - noise(ss*grainscale, (tt*grainscale / 4)); r2 = grainy * r2*r2 + (1 - grainy); r *= (1 - fade)*r2 + (0.75*fade); } else r *= 0.75; } else r = 0.4875; // Mix the light and dark wood according to the grain pattern woodcolor = lerp(lightwood, darkwood, r); // Add plank-to-plank variation in overall color woodcolor *= (1 - plankvary / 2 + plankvary * noise(whichplank + 0.5)); Ct = lerp(groovecolor, woodcolor, groovy); return Ct; } float noise3D_1(vec3 p) { return texture3D(ttt3D, p).x*2.0f - 1.0f; } float turbulence_1(vec3 p, int octaves, float lacunarity, float gain) { float freq = 1.0f; float amp = 0.8f; float sum = 0.0f; for (int i = 0; i= 1) { vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0); vec3 shadowColor = vec3(0.4, 0.4, 0.7); // colored shadow //vec3 lvec = normalize(spotLightDir); vec3 lvec = normalize(spotLightPos - gl_TexCoord[1].xyz); float ldn = max(0.0f, dot(normal, lvec)); float cosine = dot(lvec, spotLightDir); float intensity = smoothstep(spotLightCosineDecayBegin, spotLightCosineDecayEnd, cosine); float bscale = 1;//1.0f-ldn; float shadowC = shadowCoeff1(bscale); //gl_FragColor = vec4(shadowC,shadowC,shadowC,1.0f); //return; vec3 irradiance = shadowC * ldn * lightColor; // diffuse irradiance diffuseColor += diffuseMat * irradiance*intensity; // add colored shadow diffuseColor += (1.0 - shadowC*ldn) * shadowAmbient * shadowColor * diffuseMat*intensity; vec3 r = reflect(lvec, normal); specular += pow(max(0.0, dot(r, eyeVec)), specularPower)*shadowC*intensity; } // add rim light if (numShadows >= 2) { vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0); vec3 lvec = normalize(spotLightDir2); float ldn = max(0.0f, dot(normal, lvec)); vec3 irradiance = ldn * lightColor; // diffuse irradiance diffuseColor += diffuseMat * irradiance; } vec3 color = vec3(0.0, 0.0, 0.0); color += diffuseColor; color += ambientSkyColor; color += specular*specularMat; color += hdrScale * emissive * diffuseMat; //vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb; //color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color; color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color; gl_FragColor.rgb = color; gl_FragColor.w = gl_Color.w; float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0); vec4 fogCol = gl_Fog.color; gl_FragColor = mix(fogCol, gl_FragColor, fog); }