mirror of https://github.com/buggins/dlangui.git
#183 material diffuseColor, ambientColor
This commit is contained in:
parent
a48dd1d99b
commit
5f0356b3d9
|
@ -138,7 +138,9 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
string src = loadTextResource("suzanne.obj");
|
string src = loadTextResource("suzanne.obj");
|
||||||
importer.parse(src);
|
importer.parse(src);
|
||||||
Log.d("suzanne mesh:", importer.mesh.dumpVertexes(20));
|
Log.d("suzanne mesh:", importer.mesh.dumpVertexes(20));
|
||||||
Material suzanneMaterial = new Material(EffectId("colored.vert", "colored.frag", "DIRECTIONAL_LIGHT_COUNT 1"), null);
|
Material suzanneMaterial = new Material(EffectId("colored.vert", "colored.frag", null), null); //"DIRECTIONAL_LIGHT_COUNT 1"
|
||||||
|
suzanneMaterial.ambientColor = vec3(0.5, 1.0, 0.5);
|
||||||
|
suzanneMaterial.diffuseColor = vec4(1.0, 0.7, 0.7, 1.0);
|
||||||
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
||||||
Node3d suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
Node3d suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
||||||
//suzanneNode.translate(vec3(3, 4, 5));
|
//suzanneNode.translate(vec3(3, 4, 5));
|
||||||
|
|
|
@ -14,10 +14,18 @@ import dlangui.graphics.scene.mesh;
|
||||||
alias MaterialRef = Ref!Material;
|
alias MaterialRef = Ref!Material;
|
||||||
|
|
||||||
class Material : RefCountedObject {
|
class Material : RefCountedObject {
|
||||||
|
// effect
|
||||||
protected EffectRef _effect;
|
protected EffectRef _effect;
|
||||||
protected EffectId _effectId;
|
protected EffectId _effectId;
|
||||||
|
|
||||||
|
// textures
|
||||||
protected TextureRef _texture;
|
protected TextureRef _texture;
|
||||||
protected string _textureId;
|
protected string _textureId;
|
||||||
|
|
||||||
|
// colors
|
||||||
|
protected vec4 _diffuseColor = vec4(1, 1, 1, 1);
|
||||||
|
protected vec3 _ambientColor = vec3(1, 1, 1);
|
||||||
|
|
||||||
// TODO: more material properties
|
// TODO: more material properties
|
||||||
|
|
||||||
this() {
|
this() {
|
||||||
|
@ -28,6 +36,11 @@ class Material : RefCountedObject {
|
||||||
_textureId = textureId;
|
_textureId = textureId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property vec4 diffuseColor() { return _diffuseColor; }
|
||||||
|
@property Material diffuseColor(vec4 color) { _diffuseColor = color; return this; }
|
||||||
|
@property vec3 ambientColor() { return _ambientColor; }
|
||||||
|
@property Material ambientColor(vec3 color) { _ambientColor = color; return this; }
|
||||||
|
|
||||||
@property EffectRef effect() {
|
@property EffectRef effect() {
|
||||||
if (_effect.isNull && !_effectId.empty)
|
if (_effect.isNull && !_effectId.empty)
|
||||||
_effect = EffectCache.instance.get(_effectId);
|
_effect = EffectCache.instance.get(_effectId);
|
||||||
|
@ -81,6 +94,10 @@ class Material : RefCountedObject {
|
||||||
_effect.setUniform(DefaultUniform.u_cameraPosition, node.cameraPosition);
|
_effect.setUniform(DefaultUniform.u_cameraPosition, node.cameraPosition);
|
||||||
if (_effect.hasUniform(DefaultUniform.u_worldViewMatrix))
|
if (_effect.hasUniform(DefaultUniform.u_worldViewMatrix))
|
||||||
_effect.setUniform(DefaultUniform.u_worldViewMatrix, node.worldViewMatrix);
|
_effect.setUniform(DefaultUniform.u_worldViewMatrix, node.worldViewMatrix);
|
||||||
|
if (_effect.hasUniform(DefaultUniform.u_ambientColor))
|
||||||
|
_effect.setUniform(DefaultUniform.u_ambientColor, _ambientColor);
|
||||||
|
if (_effect.hasUniform(DefaultUniform.u_diffuseColor))
|
||||||
|
_effect.setUniform(DefaultUniform.u_diffuseColor, _diffuseColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMesh(Mesh mesh) {
|
void drawMesh(Mesh mesh) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ abstract class GraphicsEffect : RefCountedObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DefaultUniform : int {
|
enum DefaultUniform : int {
|
||||||
|
// colors
|
||||||
u_ambientColor, // vec3
|
u_ambientColor, // vec3
|
||||||
u_diffuseColor, // vec4
|
u_diffuseColor, // vec4
|
||||||
u_lightmapTexture, // sampler2D
|
u_lightmapTexture, // sampler2D
|
||||||
|
@ -56,6 +57,7 @@ enum DefaultUniform : int {
|
||||||
u_modulateColor, //uniform vec4 u_modulateColor;
|
u_modulateColor, //uniform vec4 u_modulateColor;
|
||||||
u_modulateAlpha, //uniform float u_modulateAlpha;
|
u_modulateAlpha, //uniform float u_modulateAlpha;
|
||||||
|
|
||||||
|
// matrix
|
||||||
u_worldViewProjectionMatrix, //uniform mat4 u_worldViewProjectionMatrix;
|
u_worldViewProjectionMatrix, //uniform mat4 u_worldViewProjectionMatrix;
|
||||||
u_inverseTransposeWorldViewMatrix, //uniform mat4 u_inverseTransposeWorldViewMatrix;
|
u_inverseTransposeWorldViewMatrix, //uniform mat4 u_inverseTransposeWorldViewMatrix;
|
||||||
u_worldViewMatrix, //uniform mat4 u_worldViewMatrix;
|
u_worldViewMatrix, //uniform mat4 u_worldViewMatrix;
|
||||||
|
|
Loading…
Reference in New Issue