mirror of https://github.com/buggins/dlangui.git
#183 : lights, initial version
This commit is contained in:
parent
815283e25c
commit
634dfc195c
|
@ -284,6 +284,7 @@
|
|||
<Compile Include="src\dlangui\graphics\scene\camera.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\drawableobject.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\effect.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\light.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\material.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\mesh.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\model.d" />
|
||||
|
|
|
@ -143,6 +143,7 @@
|
|||
<Compile Include="src\dlangui\graphics\scene\camera.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\drawableobject.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\effect.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\light.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\material.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\mesh.d" />
|
||||
<Compile Include="src\dlangui\graphics\scene\model.d" />
|
||||
|
|
|
@ -775,6 +775,7 @@
|
|||
<File path="src\dlangui\graphics\scene\camera.d" />
|
||||
<File path="src\dlangui\graphics\scene\drawableobject.d" />
|
||||
<File path="src\dlangui\graphics\scene\effect.d" />
|
||||
<File path="src\dlangui\graphics\scene\light.d" />
|
||||
<File path="src\dlangui\graphics\scene\material.d" />
|
||||
<File path="src\dlangui\graphics\scene\mesh.d" />
|
||||
<File path="src\dlangui\graphics\scene\model.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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue