mirror of https://github.com/buggins/dlangui.git
#183 point lights are working
This commit is contained in:
parent
56795f24da
commit
ec25eb2104
|
@ -121,7 +121,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
dirLightNode.translateX(2);
|
||||
dirLightNode.translateY(3);
|
||||
dirLightNode.translateZ(3);
|
||||
dirLightNode.light = Light.createPoint(vec3(110, 110.5, 110.5), 15); //Light.createDirectional(vec3(1, 0.5, 0.5));
|
||||
dirLightNode.light = Light.createPoint(vec3(1, 0.5, 0.5), 15); //Light.createDirectional(vec3(1, 0.5, 0.5));
|
||||
//dirLightNode.light = Light.createDirectional(vec3(11, 10.5, 10.5));
|
||||
dirLightNode.light.enabled = true;
|
||||
_scene.addChild(dirLightNode);
|
||||
|
@ -156,7 +156,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
suzanneMaterial.diffuseColor = vec4(1.0, 0.7, 0.5, 1.0);
|
||||
//suzanneMaterial.specular = true;
|
||||
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
||||
Node3d suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
||||
suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
||||
//suzanneNode.translate(vec3(3, 4, 5));
|
||||
_scene.addChild(suzanneNode);
|
||||
|
||||
|
@ -174,7 +174,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
int bx = rnd.next(6)-32;
|
||||
int by = rnd.next(4);
|
||||
int bz = rnd.next(6)-32;
|
||||
Log.fd("Setting cell %d,%d,%d", bx, by, bz);
|
||||
//Log.fd("Setting cell %d,%d,%d", bx, by, bz);
|
||||
_world.setCell(bx, by, bz, 3);
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
}
|
||||
|
||||
Node3d dirLightNode;
|
||||
Node3d suzanneNode;
|
||||
|
||||
float rotationX;
|
||||
float rotationY;
|
||||
|
@ -272,6 +273,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
|||
_cam.rotateY(0.02);
|
||||
angle += interval * 0.000002f;
|
||||
invalidate();
|
||||
suzanneNode.rotateY(interval * 0.000002f);
|
||||
}
|
||||
float angle = 0;
|
||||
|
||||
|
|
|
@ -1007,6 +1007,17 @@ struct mat4 {
|
|||
return this;
|
||||
}
|
||||
|
||||
/// transpose matrix
|
||||
void transpose() {
|
||||
float[16] tmp = [
|
||||
m[0], m[4], m[8], m[12],
|
||||
m[1], m[5], m[9], m[13],
|
||||
m[2], m[6], m[10], m[14],
|
||||
m[3], m[7], m[11], m[15]
|
||||
];
|
||||
m = tmp;
|
||||
}
|
||||
|
||||
mat4 invert() const
|
||||
{
|
||||
float a0 = m[0] * m[5] - m[1] * m[4];
|
||||
|
|
|
@ -124,16 +124,17 @@ class Material : RefCountedObject {
|
|||
texture.texture.setup();
|
||||
texture.texture.setSamplerParams(true);
|
||||
}
|
||||
// TODO: more uniforms
|
||||
// matrixes, positions uniforms
|
||||
if (_effect.hasUniform(DefaultUniform.u_worldViewProjectionMatrix))
|
||||
_effect.setUniform(DefaultUniform.u_worldViewProjectionMatrix, node.projectionViewModelMatrix);
|
||||
if (_effect.hasUniform(DefaultUniform.u_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);
|
||||
//Log.d("DefaultUniform.u_worldViewMatrix: ", node.worldViewMatrix);
|
||||
//Log.d("DefaultUniform.u_worldViewMatrix * 3,3,3: ", node.worldViewMatrix * vec3(3,3,3));
|
||||
}
|
||||
if (_effect.hasUniform(DefaultUniform.u_inverseTransposeWorldViewMatrix))
|
||||
_effect.setUniform(DefaultUniform.u_inverseTransposeWorldViewMatrix, node.inverseTransposeWorldViewMatrix);
|
||||
|
||||
// color uniforms
|
||||
if (_effect.hasUniform(DefaultUniform.u_ambientColor))
|
||||
_effect.setUniform(DefaultUniform.u_ambientColor, _ambientColor);
|
||||
if (_effect.hasUniform(DefaultUniform.u_diffuseColor))
|
||||
|
@ -142,6 +143,8 @@ class Material : RefCountedObject {
|
|||
_effect.setUniform(DefaultUniform.u_modulateColor, _modulateColor);
|
||||
if (_effect.hasUniform(DefaultUniform.u_modulateAlpha))
|
||||
_effect.setUniform(DefaultUniform.u_modulateAlpha, _modulateAlpha);
|
||||
|
||||
// lighting uniforms
|
||||
if (lights && !lights.empty) {
|
||||
if (lights.u_directionalLightDirection.length) {
|
||||
if (_effect.hasUniform(DefaultUniform.u_directionalLightDirection)) {
|
||||
|
|
|
@ -175,6 +175,37 @@ class Node3d : Transform {
|
|||
return translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inverse transpose world matrix corresponding to this node.
|
||||
*
|
||||
* This matrix is typically used to transform normal vectors into world space.
|
||||
*
|
||||
* @return The inverse world matrix of this node.
|
||||
*/
|
||||
@property ref const(mat4) inverseTransposeWorldMatrix() {
|
||||
static __gshared mat4 invTransWorld;
|
||||
invTransWorld = worldMatrix;
|
||||
invTransWorld.invert();
|
||||
invTransWorld.transpose();
|
||||
return invTransWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inverse transpose world view matrix corresponding to this node.
|
||||
*
|
||||
* This matrix is typically used to transform normal vectors into view space.
|
||||
*
|
||||
* @return The inverse world view matrix of this node.
|
||||
*/
|
||||
@property ref const(mat4) inverseTransposeWorldViewMatrix() {
|
||||
static __gshared mat4 invTransWorldView;
|
||||
invTransWorldView = viewMatrix * worldMatrix;
|
||||
invTransWorldView.invert();
|
||||
invTransWorldView.transpose();
|
||||
return invTransWorldView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the forward vector of the Node in world space.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue