[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10842] branches/soc-2007-maike/source/ blender/src: GLSL light, material and program structure creation

Miguel Torres Lima torreslima at gmail.com
Fri Jun 1 18:37:30 CEST 2007


Revision: 10842
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10842
Author:   maike
Date:     2007-06-01 18:37:30 +0200 (Fri, 01 Jun 2007)

Log Message:
-----------
GLSL light, material and program structure creation

Added Paths:
-----------
    branches/soc-2007-maike/source/blender/src/glsl_diffuse.c
    branches/soc-2007-maike/source/blender/src/glsl_light.c
    branches/soc-2007-maike/source/blender/src/glsl_material.c
    branches/soc-2007-maike/source/blender/src/glsl_program.c
    branches/soc-2007-maike/source/blender/src/glsl_specular.c
    branches/soc-2007-maike/source/blender/src/glsl_util.c

Added: branches/soc-2007-maike/source/blender/src/glsl_diffuse.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_diffuse.c	                        (rev 0)
+++ branches/soc-2007-maike/source/blender/src/glsl_diffuse.c	2007-06-01 16:37:30 UTC (rev 10842)
@@ -0,0 +1,235 @@
+#include "DNA_lamp_types.h"
+
+#include "BIF_glsl_diffuse.h"
+
+
+char *glsl_lambert(short lamp)
+{  
+  if(lamp == LA_HEMI){
+    char *lambert = {
+      "\nvec4 lambert_hemi(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  return((0.5 * dot(lightVec, norm) + 0.5) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"      
+    };
+
+    return lambert;
+  }
+  else if(lamp == LA_SUN){
+    char *lambert = {
+      "\nvec4 lambert_sun(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  return(max(dot(lightVec, norm) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy, 0.0));"
+      "}\n"      
+    };
+
+    return lambert;
+  }
+  else{
+    char *lambert = {
+      "\nvec4 lambert(light l){"
+      "  vec3 lightVec = normalize(l.loc - pos);"
+      "  return(max(dot(lightVec, norm) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy, 0.0));"
+      "}\n"      
+    };
+
+    return lambert;
+  }
+}
+
+
+char *glsl_orennayar(short lamp)
+{
+  if(lamp == LA_HEMI){
+    char *orennayar = {
+      "\nvec4 orennayar_hemi(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  return((0.5 * dot(lightVec, norm) + 0.5) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return orennayar;
+  }
+  else if(lamp == LA_SUN){
+    char *orennayar = {
+      "\nvec4 orennayar_sun(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  vec3 view = normalize(eye - pos);"
+      "  vec3 h = normalize(view + lightVec);"
+      "  float nh = max(dot(norm, h), 0.0);"
+      "  float nv = max(dot(norm, view), 0.0);"
+      "  float nl = max(dot(norm, lightVec), 0.0);"      
+      "  float vh = max(dot(view, h), 0.0);"
+      "  float lit_A = acos(clamp(nl, -1.0, 1.0));"
+      "  float view_A = acos(clamp(nv, -1.0, 1.0));"
+      "  vec3 lit_B = normalize(lightVec - (nl * norm));"
+      "  vec3 view_B = normalize(view - (nv * norm));"
+      "  float t = max(dot(lit_B, view_B), 0.0);"
+      "  float A = 1.0 - (0.5 * ((roughness * roughness) / ((roughness * roughness) + 0.33)));"
+      "  float B = 0.45 * ((roughness * roughness) / ((roughness * roughness) + 0.09));"
+      "  b = b * 0.95;"
+      "  float res = nl * (A + (B * t * sin(max(lit_A, view_A)) * tan(min(lit_A, view_A))));"
+      "  return(ref * res * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);\n"
+      "}\n"
+    };
+
+    return orennayar;
+  }
+  else{
+    char *orennayar = {
+      "\nvec4 orennayar(light l){"
+      "  vec3 lightVec = normalize(l.loc - pos);"
+      "  vec3 view = normalize(eye - pos);"
+      "  vec3 h = normalize(view + lightVec);"
+      "  float nh = max(dot(norm, h), 0.0);"
+      "  float nv = max(dot(norm, view), 0.0);"
+      "  float nl = max(dot(norm, lightVec), 0.0);"      
+      "  float vh = max(dot(view, h), 0.0);"
+      "  float lit_A = acos(clamp(nl, -1.0, 1.0));"
+      "  float view_A = acos(clamp(nv, -1.0, 1.0));"
+      "  vec3 lit_B = normalize(lightVec - (nl * norm));"
+      "  vec3 view_B = normalize(view - (nv * norm));"
+      "  float t = max(dot(lit_B, view_B), 0.0);"
+      "  float A = 1.0 - (0.5 * ((roughness * roughness) / ((roughness * roughness) + 0.33)));"
+      "  float B = 0.45 * ((roughness * roughness) / ((roughness * roughness) + 0.09));"
+      "  b = b * 0.95;"
+      "  float res = nl * (A + (B * t * sin(max(lit_A, view_A)) * tan(min(lit_A, view_A))));"
+      "  return(ref * res * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);\n"
+      "}\n"
+    };
+
+    return orennayar;
+  }
+}
+
+
+char *glsl_difftoon(short lamp)
+{
+  if(lamp == LA_HEMI){
+    char *toon = {
+      "\nvec4 difftoon_hemi(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  return((0.5 * dot(lightVec, norm) + 0.5) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return toon;
+  }
+  else if(lamp == LA_SUN){
+    char *toon = {
+      "\nvec4 difftoon_sun(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  float rslt = dot(norm, lightVec);"
+      "  float ang;"
+      "  ang = acos(clamp(rslt, -1.0, 1.0));"
+      "  rslt = clamp(ceil(size + smooth - ang - 0.00001) * (1.0 - (ang - size)) / smooth, 0.0, 1.0);"
+      "  return(rslt * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return toon;
+  }
+  else{
+    char *toon = {
+      "\nvec4 difftoon(light l){"
+      "  vec3 lightVec = normalize(l.loc - pos);"
+      "  float rslt = dot(norm, lightVec);"
+      "  float ang;"
+      "  ang = acos(clamp(rslt, -1.0, 1.0));"
+      "  rslt = clamp(ceil(size + smooth - ang - 0.00001) * (1.0 - (ang - size)) / smooth, 0.0, 1.0);"
+      "  return(rslt * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return toon;
+  }
+}
+
+
+char *glsl_minnaert(short lamp)
+{
+  if(lamp == LA_HEMI){
+    char *minnaert = {
+      "\nvec4 minnaert_hemi(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  return((0.5 * dot(lightVec, norm) + 0.5) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return minnaert;
+  }
+  else if(lamp == LA_SUN){
+    char *minnaert = {
+      "\nvec4 minnaert_sun(light l){"
+      "  vec3 lightVec = normalize(l.vec);"
+      "  vec3 view = normalize(eye - pos);"
+      "  float nl = clamp(dot(norm, lightVec), 0.0, 1.0);"    
+      "  float nv = max(dot(norm, view), 0.0);" 
+      "  float res;"
+      "  if(darkness <= 1.0) res = nl * pow(max(nv * nl, 0.1), darkness - 1.0);"
+      "  else res = nl * pow(1.001 - nv, darkness - 1.0);"
+      "  return(ref * res * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return minnaert;
+  }
+  else{
+    char *minnaert = {
+      "\nvec4 minnaert(light l){"
+      "  vec3 lightVec = normalize(l.loc - pos);"
+      "  vec3 view = normalize(eye - pos);"
+      "  float nl = clamp(dot(norm, lightVec), 0.0, 1.0);"    
+      "  float nv = max(dot(norm, view), 0.0);" 
+      "  float res;"
+      "  if(darkness <= 1.0) res = nl * pow(max(nv * nl, 0.1), darkness - 1.0);"
+      "  else res = nl * pow(1.001 - nv, darkness - 1.0);"
+      "  return(ref * res * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return minnaert;
+  }
+}
+
+
+char *glsl_fresnel(short lamp)
+{
+  if(lamp == LA_HEMI){
+    char *fresnel = {
+      "\nvec4 fresnel_hemi(light l){"
+      "  vec3 view = normalize(l.vec);"
+      "  return((0.5 * dot(view, norm) + 0.5) * ref * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return fresnel;
+  }
+  else if(lamp == LA_SUN){
+    char *fresnel = {
+      "\nvec4 fresnel_sun(light l){"
+      "  vec3 view = normalize(l.vec);"
+      "  float t1 = dot(view, norm);"
+      "  float t2 = 1.0 + abs(t1);"
+      "  t2 = grad + (1.0 - grad) * pow(t2, fac);"
+      "  return(ref * clamp(t2, 0.0, 1.0) * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return fresnel;
+  }
+  else{
+    char *fresnel = {
+      "\nvec4 fresnel(light l){"
+      "  vec3 view = normalize(eye - pos);"
+      "  float t1 = dot(view, norm);"
+      "  float t2 = 1.0 + abs(t1);"
+      "  t2 = grad + (1.0 - grad) * pow(t2, fac);"
+      "  return(ref * clamp(t2, 0.0, 1.0) * l.no_diff * l.layer * vec4(l.color + vert_color, 1.0) * l.energy);"
+      "}\n"
+    };
+
+    return fresnel;
+  }
+}
+

Added: branches/soc-2007-maike/source/blender/src/glsl_light.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_light.c	                        (rev 0)
+++ branches/soc-2007-maike/source/blender/src/glsl_light.c	2007-06-01 16:37:30 UTC (rev 10842)
@@ -0,0 +1,298 @@
+#include "BIF_glsl_light.h"
+#include "BIF_glutil.h"
+
+
+#include "BKE_global.h"
+#include "BKE_scene.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_object_types.h"
+
+#include "MEM_guardedalloc.h"
+
+
+static GLSL_LightList lights = NULL;
+static GLSL_LightList local_lights = NULL;
+
+static int num_lights = 0;
+static int num_local_lights = 0;
+
+// LIGHTS
+
+
+
+int glsl_get_num_lights(void)
+{
+  return num_lights;
+}
+
+
+GLSL_LightList glsl_get_lights(void)
+{
+  return lights;
+}
+
+
+// source/blender/blenkernel/intern/scene.c -> set_scene_bg()
+void glsl_init_scene_light(Lamp *lamp, Object *obj)
+{
+  glsl_create_light(obj->data, obj);
+}
+
+
+void glsl_free_light_structs(void)
+{
+  GLSL_LightList lightlist = lights;
+
+  while(lightlist != NULL){
+    GLSL_LightList tmplist = lightlist;
+    GLSL_Light tmplight = tmplist->light;
+
+    lightlist = lightlist->next;
+    
+    MEM_freeN(tmplight->glsl_light);
+    MEM_freeN(tmplight);
+    MEM_freeN(tmplist);
+  }
+
+  lights = NULL;
+}
+
+
+// called from source/blender/editobject.c in function add_objectLamp()
+void glsl_create_light(Lamp *lamp, Object *obj)
+{
+  GLSL_Light light;
+
+  GLSL_LightList new_light = MEM_mallocN(sizeof(struct GLSL_LightList_), "GLSL LightList"); //(struct GLSL_LightList_ *) malloc(sizeof(struct GLSL_LightList_));
+  new_light->prev = NULL;
+  new_light->next = NULL;
+  light = glsl_create_glsl_light(lamp, obj);
+  new_light->light = light;
+
+  if(lights == NULL)
+    lights = new_light;
+  else{
+    new_light->next = lights;
+    lights->prev = new_light;
+    lights = new_light;
+  }
+
+  num_lights++;
+}
+
+
+GLSL_Light glsl_create_glsl_light(Lamp *lamp, Object *obj)
+{
+  GLSL_Light light = MEM_mallocN(sizeof(struct GLSL_Light_), "GLSL Light"); //(struct GLSL_Light_ *) malloc(sizeof(struct GLSL_Light_));
+
+  light->type = lamp->type;
+
+  switch(lamp->type){
+  case LA_AREA: light->glsl_light = (GLSL_AreaLight) create_area_light(lamp, obj); break;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list