/* * Returns material albedo for given voxel */ vec3 getAlbedo(uint data) { return _Materials[data-1].albedo.rgb; } float getSpecular(uint data) { return _Materials[data-1].specular; } /* point: Hit point view: View vector (camera ray) normal: Normal vector */ vec3 applyLighting(vec3 hitPoint, vec3 view, vec3 normal, uint data) { // Lighting vec3 ambientColor = vec3(0.9, 0.9, 1.0); vec3 ambient = ambientColor * 0.05; vec3 sky = ambientColor * 0.1 * max(normal.y, 0); vec3 sunColor = vec3(1.0, 1.0, 0.9); vec3 diffuse = sunColor * max(1.0-dot(normal, _SunDir), 0.0); vec3 specular = sunColor * getSpecular(data) * pow(max(dot(view, reflect(_SunDir, normal)), 0.0), 32); // Combine colors return (ambient + sky + diffuse + specular) * getAlbedo(data); }