uniform sampler3D ttt3D; uniform float extraNoiseScale = 1.0f; float noise3D(vec3 p) { return texture3D(ttt3D, p).x*2.0f - 1.0f; } float turbulence(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= 0.0f) { // 2D texture diffuseMat = texture2DArray(diffuseTexArray, gl_TexCoord[6].xyz).rgb; //specularMat = texture2DArray(specularTexArray, gl_TexCoord[6].xyz).rgb; // TODO Does not seem to work specularMat = vec3(1.0f); bump = texture2DArray(bumpTexArray, gl_TexCoord[6].xyz).xyz; if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1); emissiveReflectSpecPow = texture2DArray(emissiveReflectSpecPowerTexArray, gl_TexCoord[6].xyz).xyz; } else { // 3D texture diffuseMat = myTexture3D(gl_TexCoord[0].xyz) * vec3(0.5,0.5,0.5);//texture3D(ttt3D, gl_TexCoord[0].xyz); specularMat = vec3(1.0); bump = texture2D(texture, gl_TexCoord[5].xy).xyz; if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1); emissiveReflectSpecPow = vec3(0.0,0.0,0.0); } // apply bump to the normal bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f; bump.xy *= roughnessScale*2; float sc = 1.0f; normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z); vec3 eyeVec = normalize(gl_TexCoord[1].xyz); // apply gamma correction for diffuse textures diffuseMat = pow(diffuseMat, 0.45); float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f; // TODO - fix this specularPower = 10.0f; float emissive = emissiveReflectSpecPow.r*10.0f; float reflectivity = emissiveReflectSpecPow.b; float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower); float specular = 0.0f; vec3 skyNormal = reflect(eyeVec, normal); vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb; vec3 ambientSkyColor = diffuseMat * skyColor; vec3 diffuseColor = vec3(0.0, 0.0, 0.0); if (numShadows >= 1) { vec3 lightColor = hdrScale * vec3(1.0, 0.9, 0.9); vec3 shadowColor = vec3(0.4, 0.4, 0.9); // colored shadow vec3 lvec = normalize(spotLightDir); float ldn = max(0.0f, dot(normal, lvec)); float shadowC = shadowCoeff1(); vec3 irradiance = shadowC * ldn * lightColor; // diffuse irradiance diffuseColor += diffuseMat * irradiance; // add colored shadow diffuseColor += (1.0 - shadowC) * shadowAmbient * shadowColor * diffuseMat; vec3 r = reflect(lvec, normal); specular += pow(max(0.0, dot(r,eyeVec)), specularPower)*shadowC; } // add rim light if (numShadows >= 2) { vec3 lightColor = rimLightIntensity * vec3(1.0, 0.9, 0.9); 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); }