Browse Source

shiny.lolfx now has a PointLight & a DirectionalLight.

Sorry for all the fine projects that use this shader !
legacy
Benjamin ‘Touky’ Huet touky 12 years ago
parent
commit
7c0134ea12
1 changed files with 16 additions and 13 deletions
  1. +16
    -13
      src/easymesh/shiny.lolfx

+ 16
- 13
src/easymesh/shiny.lolfx View File

@@ -42,8 +42,10 @@ varying vec3 pass_TNormal;
varying vec4 pass_Color;

// FIXME: the light direction should be passed in the code
vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
vec4 in_Light2_Pos = vec4(-100.0, 100.0, -100.0, 1.0);
vec3 in_LightDir = vec3(-0.3, -0.3, -0.7);
vec4 in_Light2_Pos = vec4(0.0, 10.0, 0.0, 1.0);
float in_Light2_Radius = 20.0;
vec3 in_Light2_diffuse = vec3(0.4, 0.4, 1.0);

void main(void)
{
@@ -54,7 +56,7 @@ void main(void)
/* World properties */
float ambient_mul = 0.5;
vec3 ambient_color = vec3(0.0, 0.0, 0.0);
vec3 diffuse_color = vec3(1.0, 1.0, 0.6);
vec3 diffuse_color = vec3(0.4, 0.4, 0.4);
vec3 specular_color = vec3(1.0, 1.0, 0.6);

vec3 ambient = ambient_color;
@@ -65,30 +67,31 @@ void main(void)
vec3 r = vec3(0.0, 0.0, 0.0);
float sdotn = 0.0;

/*
//Light calculation for directional light
s = normalize(in_LightDir);
s = normalize(-in_LightDir);
v = normalize(-pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);
r = reflect(s, pass_TNormal);

sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += diffuse_color * sdotn;
if (sdotn > 0.0)
specular += specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
*/

//Light calculation for point light
s = normalize((in_View * in_Light2_Pos).xyz - pass_Vertex.xyz);
vec3 tmpLightDir = (in_View * in_Light2_Pos).xyz - pass_Vertex.xyz;
float light_radius_mod = max(0.0, 1.0 - (length(tmpLightDir) / in_Light2_Radius));
s = normalize(tmpLightDir);
v = normalize(-pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);

sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += diffuse_color * sdotn;
//if (sdotn > 0.0)
// specular += specular_color * specular_reflect
// * pow(max(dot(r, v), 0.0), specular_power);
diffuse += in_Light2_diffuse * min(sdotn, light_radius_mod);
if (sdotn > 0.0 && light_radius_mod > 0.0)
specular += specular_color * min(specular_reflect, light_radius_mod)
* pow(max(dot(r, v), 0.0), specular_power);

vec3 light = ambient + diffuse + specular;



Loading…
Cancel
Save