diff --git a/dlangui-monod-linux.dproj b/dlangui-monod-linux.dproj
index a7a4b57a..029f98f1 100644
--- a/dlangui-monod-linux.dproj
+++ b/dlangui-monod-linux.dproj
@@ -284,6 +284,7 @@
+
diff --git a/dlangui-monod-osx.dproj b/dlangui-monod-osx.dproj
index dfd82c8a..6c1521e3 100644
--- a/dlangui-monod-osx.dproj
+++ b/dlangui-monod-osx.dproj
@@ -143,6 +143,7 @@
+
diff --git a/dlangui-msvc.visualdproj b/dlangui-msvc.visualdproj
index fef32695..2f03e1b7 100644
--- a/dlangui-msvc.visualdproj
+++ b/dlangui-msvc.visualdproj
@@ -775,6 +775,7 @@
+
diff --git a/examples/d3d/src/d3d.d b/examples/d3d/src/d3d.d
index 8fd38ce8..5ca52f2b 100644
--- a/examples/d3d/src/d3d.d
+++ b/examples/d3d/src/d3d.d
@@ -138,7 +138,7 @@ class UiWidget : VerticalLayout, CellVisitor {
string src = loadTextResource("suzanne.obj");
importer.parse(src);
Log.d("suzanne mesh:", importer.mesh.dumpVertexes(20));
- Material suzanneMaterial = new Material(EffectId("colored.vert", "colored.frag", null), null);
+ Material suzanneMaterial = new Material(EffectId("colored.vert", "colored.frag", null), "DIRECTIONAL_LIGHT_COUNT 1");
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
Node3d suzanneNode = new Node3d("suzanne", suzanneDrawable);
//suzanneNode.translate(vec3(3, 4, 5));
diff --git a/src/dlangui/graphics/scene/effect.d b/src/dlangui/graphics/scene/effect.d
index 816f1d3d..7fdc0a03 100644
--- a/src/dlangui/graphics/scene/effect.d
+++ b/src/dlangui/graphics/scene/effect.d
@@ -16,6 +16,7 @@ alias EffectRef = Ref!Effect;
class Effect : GLProgram {
EffectId _id;
string[string] _defs;
+ string _defText;
@property ref const(EffectId) id() const { return _id; }
this(EffectId id) {
@@ -35,13 +36,21 @@ class Effect : GLProgram {
// parse defs
import std.array : split;
string[] defs = _id.definitions.split(";");
+ char[] buf;
foreach(def; defs) {
assert(def.length > 0);
string[] items = def.split(" ");
if (items.length > 0) {
- _defs[items[0]] = items.length > 1 ? items[1] : "";
+ string value = items.length > 1 ? items[1] : "";
+ _defs[items[0]] = value;
+ buf ~= "#define ";
+ buf ~= items[0];
+ buf ~= " ";
+ buf ~= value;
+ buf ~= "\n";
}
}
+ _defText = buf.dup;
// compile shaders
if (!check()) {
Log.e("Failed to compile shaders ", _id.vertexShaderName, " ", _id.fragmentShaderName, " ", _id.definitions);
@@ -50,8 +59,8 @@ class Effect : GLProgram {
}
protected string preProcessSource(string src) {
- // TODO: preprocess source code
- return src;
+ // prepend definitions
+ return _defText ~ src;
}
protected string loadVertexSource(string resourceId) {
diff --git a/src/dlangui/graphics/scene/light.d b/src/dlangui/graphics/scene/light.d
new file mode 100644
index 00000000..d4c9f2b6
--- /dev/null
+++ b/src/dlangui/graphics/scene/light.d
@@ -0,0 +1,31 @@
+module dlangui.graphics.scene.light;
+
+import dlangui.core.math3d;
+import dlangui.core.types;
+
+enum LightType : ubyte {
+ directional,
+ point,
+ spot
+}
+
+/// Reference counted Light object
+alias LightRef = Ref!Light;
+
+class Light : RefCountedObject {
+ protected vec3 _color;
+ protected this(vec3 color) {}
+ @property vec3 color() { return _color; }
+ @property Light color(vec3 c) { _color = c; return this; }
+ @property LightType type() { return LightType.directional; }
+ /// create new directional light
+ static Light createDirectional(vec3 color) {
+ return new DirectionalLight(color);
+ }
+}
+
+protected class DirectionalLight : Light {
+ protected this(vec3 color) {
+ super(color);
+ }
+}
diff --git a/src/dlangui/graphics/scene/node.d b/src/dlangui/graphics/scene/node.d
index 40646f06..5ce43dba 100644
--- a/src/dlangui/graphics/scene/node.d
+++ b/src/dlangui/graphics/scene/node.d
@@ -6,6 +6,7 @@ import dlangui.graphics.scene.transform;
import dlangui.core.collections;
import dlangui.graphics.scene.scene3d;
import dlangui.graphics.scene.drawableobject;
+import dlangui.graphics.scene.light;
/// 3D scene node
class Node3d : Transform {
@@ -14,6 +15,7 @@ class Node3d : Transform {
protected string _id;
protected bool _visible = true;
protected DrawableObjectRef _drawable;
+ protected LightRef _light;
protected mat4 _worldMatrix;
@@ -36,6 +38,9 @@ class Node3d : Transform {
/// drawable attached to node
@property ref DrawableObjectRef drawable() { return _drawable; }
+ /// light attached to node
+ @property ref LightRef light() { return _light; }
+
/// returns scene for node
@property Scene3d scene() {
if (_scene)