Daniel Salvadori 7 лет назад
Родитель
Сommit
9e48c7ee3e

+ 1 - 2
material/phong.go

@@ -9,8 +9,7 @@ import (
 )
 
 // Phong material is identical to the Standard material but
-// the calculation of the lighting model is done in the
-// fragment shader.
+// the calculation of the lighting model is done in the fragment shader.
 type Phong struct {
 	Standard // Embedded standard material
 }

+ 3 - 4
renderer/shaders/include/lights.glsl

@@ -2,21 +2,21 @@
 // Lights uniforms
 //
 
-// Ambient lights uniforms
 #if AMB_LIGHTS>0
+    // Ambient lights color uniform
     uniform vec3 AmbientLightColor[AMB_LIGHTS];
 #endif
 
-// Directional lights uniform array. Each directional light uses 2 elements
 #if DIR_LIGHTS>0
+    // Directional lights uniform array. Each directional light uses 2 elements
     uniform vec3 DirLight[2*DIR_LIGHTS];
     // Macros to access elements inside the DirectionalLight uniform array
     #define DirLightColor(a)		DirLight[2*a]
     #define DirLightPosition(a)		DirLight[2*a+1]
 #endif
 
-// Point lights uniform array. Each point light uses 3 elements
 #if POINT_LIGHTS>0
+    // Point lights uniform array. Each point light uses 3 elements
     uniform vec3 PointLight[3*POINT_LIGHTS];
     // Macros to access elements inside the PointLight uniform array
     #define PointLightColor(a)			PointLight[3*a]
@@ -28,7 +28,6 @@
 #if SPOT_LIGHTS>0
     // Spot lights uniforms. Each spot light uses 5 elements
     uniform vec3  SpotLight[5*SPOT_LIGHTS];
-    
     // Macros to access elements inside the PointLight uniform array
     #define SpotLightColor(a)			SpotLight[5*a]
     #define SpotLightPosition(a)		SpotLight[5*a+1]

+ 1 - 1
renderer/shaders/shaders.go

@@ -12,7 +12,7 @@ package shaders
 type ProgramInfo struct {
 	Vertex   string // Vertex shader name
 	Fragment string // Fragment shader name
-	Geometry string // Geometry shader name (maybe an empty string)
+	Geometry string // Geometry shader name (optional)
 }
 
 // AddInclude adds a chunk of shader code to the default shaders registry

+ 42 - 8
renderer/shaders/sources.go

@@ -21,21 +21,21 @@ const include_lights_source = `//
 // Lights uniforms
 //
 
-// Ambient lights uniforms
 #if AMB_LIGHTS>0
+    // Ambient lights color uniform
     uniform vec3 AmbientLightColor[AMB_LIGHTS];
 #endif
 
-// Directional lights uniform array. Each directional light uses 2 elements
 #if DIR_LIGHTS>0
+    // Directional lights uniform array. Each directional light uses 2 elements
     uniform vec3 DirLight[2*DIR_LIGHTS];
     // Macros to access elements inside the DirectionalLight uniform array
     #define DirLightColor(a)		DirLight[2*a]
     #define DirLightPosition(a)		DirLight[2*a+1]
 #endif
 
-// Point lights uniform array. Each point light uses 3 elements
 #if POINT_LIGHTS>0
+    // Point lights uniform array. Each point light uses 3 elements
     uniform vec3 PointLight[3*POINT_LIGHTS];
     // Macros to access elements inside the PointLight uniform array
     #define PointLightColor(a)			PointLight[3*a]
@@ -47,7 +47,6 @@ const include_lights_source = `//
 #if SPOT_LIGHTS>0
     // Spot lights uniforms. Each spot light uses 5 elements
     uniform vec3  SpotLight[5*SPOT_LIGHTS];
-    
     // Macros to access elements inside the PointLight uniform array
     #define SpotLightColor(a)			SpotLight[5*a]
     #define SpotLightPosition(a)		SpotLight[5*a+1]
@@ -112,6 +111,40 @@ uniform vec3 Material[6];
             //texMixed.rgb /= texMixed.a;                                                      \
 `
 
+const include_morphtarget_vertex_source = `#ifdef MORPHTARGETS
+	uniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];
+#endif
+
+#ifdef MORPHTARGETS
+	attribute vec3 MorphPosition{X};
+
+	#ifdef MORPHTARGETS_NORMAL
+	attribute vec3 MorphNormal{X};
+	#endif
+#endif
+
+#ifdef MORPHTARGETS
+	positionUpdated += (MorphPosition{X} - VertexPosition) * morphTargetInfluences[{X}];
+
+	#ifdef MORPHTARGETS_NORMAL
+	normalUpdated += (MorphNormal{X} - VertexNormal) * morphTargetInfluences[{X}];
+	#endif
+#endif
+
+
+//
+// Vertex attributes
+//
+layout(location = 0) in  vec3  VertexPosition;
+layout(location = 1) in  vec3  VertexNormal;
+layout(location = 2) in  vec3  VertexColor;
+layout(location = 3) in  vec2  VertexTexcoord;
+layout(location = 4) in  float VertexDistance;
+layout(location = 5) in  vec4  VertexTexoffsets;
+
+
+`
+
 const include_phong_model_source = `/***
  phong lighting model
  Parameters:
@@ -1222,10 +1255,11 @@ void main() {
 // Maps include name with its source code
 var includeMap = map[string]string{
 
-	"attributes":  include_attributes_source,
-	"lights":      include_lights_source,
-	"material":    include_material_source,
-	"phong_model": include_phong_model_source,
+	"attributes":         include_attributes_source,
+	"lights":             include_lights_source,
+	"material":           include_material_source,
+	"morphtarget_vertex": include_morphtarget_vertex_source,
+	"phong_model":        include_phong_model_source,
 }
 
 // Maps shader name with its source code