X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fphong.glsl;h=7c555e75208344559195a68c1b9ad741bd884d24;hb=HEAD;hp=f9d8d1e72b971827401575a567fc7ba38f3943a9;hpb=6dcf74922f46b086ad394c19fd6ce083a635b290;p=libs%2Fgl.git diff --git a/shaderlib/phong.glsl b/shaderlib/phong.glsl index f9d8d1e7..7c555e75 100644 --- a/shaderlib/phong.glsl +++ b/shaderlib/phong.glsl @@ -1,6 +1,29 @@ import msp_interface; import common; +import lighting; import shadow; +import environment; + +struct BasicMaterialParameters +{ + vec4 diffuse; + vec4 specular; + vec4 emission; + float shininess; + float reflectivity; +}; + +layout(set=1) uniform BasicMaterial +{ + BasicMaterialParameters basic_material; + AlphaCutoffParams alpha_cutoff; +}; + +layout(set=1) uniform sampler2D diffuse_map; +layout(set=1) uniform sampler2D specular_map; +layout(set=1) uniform sampler2D shininess_map; +layout(set=1) uniform sampler2D emission_map; +layout(set=1) uniform sampler2D reflectivity_map; layout(constant_id=auto) const bool use_diffuse_map = false; layout(constant_id=auto) const bool use_specular = false; @@ -10,8 +33,6 @@ layout(constant_id=auto) const bool use_emission = false; layout(constant_id=auto) const bool use_emission_map = false; layout(constant_id=auto) const bool use_reflectivity = false; layout(constant_id=auto) const bool use_reflectivity_map = false; -layout(constant_id=auto) const bool use_sky = false; -layout(constant_id=auto) const bool use_fog = false; #pragma MSP stage(fragment) virtual vec4 get_diffuse_color() @@ -59,32 +80,29 @@ vec3 phong_ambient(vec3 surface_diffuse) return ambient_color.rgb*surface_diffuse; } -vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 surface_diffuse, vec3 surface_specular, float shininess) +vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess) { float diffuse_intensity = max(dot(light, normal), 0.0); - vec3 color = light_color*surface_diffuse*diffuse_intensity; + vec3 color = surface_diffuse*diffuse_intensity; if(use_specular) { - /* The light vector points towards the light, so reflected will point - towards the surface - but so does the look vector. */ - vec3 reflected = reflect(light, normal); - float specular_intensity = pow(max(dot(reflected, look), 0.0), shininess); - color += light_color*surface_specular*specular_intensity; + vec3 reflected = reflect(look, normal); + float specular_intensity = pow(max(dot(reflected, light), 0.0), shininess); + color += surface_specular*specular_intensity; } return color; } vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess) { - vec3 light; - if(use_normal_map) - light = normalize(tbn_light_dir); - else - light = normalize(eye_light_dir); - vec3 color = phong_ambient(surface_diffuse); - float shadow = get_shadow_factor(0); - color += phong_one_light(light, normal, look, light_sources[0].diffuse.rgb, surface_diffuse, surface_specular, shininess)*shadow; + for(int i=0; i