mirror of https://github.com/buggins/dlangui.git
bump mapping - cube mesh with tangent and binormal
This commit is contained in:
parent
31f2c79271
commit
ca71fe2e54
|
@ -121,8 +121,8 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
//dirLightNode.rotateX(20);
|
//dirLightNode.rotateX(20);
|
||||||
dirLightNode.translateX(2);
|
dirLightNode.translateX(2);
|
||||||
dirLightNode.translateY(3);
|
dirLightNode.translateY(3);
|
||||||
dirLightNode.translateZ(3);
|
dirLightNode.translateZ(0);
|
||||||
dirLightNode.light = Light.createPoint(vec3(1, 0.5, 0.5), 15); //Light.createDirectional(vec3(1, 0.5, 0.5));
|
dirLightNode.light = Light.createPoint(vec3(3, 3, 3), 15); //Light.createDirectional(vec3(1, 0.5, 0.5));
|
||||||
//dirLightNode.light = Light.createDirectional(vec3(1, 0.5, 0.8));
|
//dirLightNode.light = Light.createDirectional(vec3(1, 0.5, 0.8));
|
||||||
dirLightNode.light.enabled = true;
|
dirLightNode.light.enabled = true;
|
||||||
_scene.addChild(dirLightNode);
|
_scene.addChild(dirLightNode);
|
||||||
|
@ -166,12 +166,12 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
//suzanneMaterial.specular = true;
|
//suzanneMaterial.specular = true;
|
||||||
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
Model suzanneDrawable = new Model(suzanneMaterial, importer.mesh);
|
||||||
suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
suzanneNode = new Node3d("suzanne", suzanneDrawable);
|
||||||
suzanneNode.translate(vec3(2, 3, -5));
|
suzanneNode.translate(vec3(2, 2, -5));
|
||||||
_scene.addChild(suzanneNode);
|
_scene.addChild(suzanneNode);
|
||||||
|
|
||||||
|
|
||||||
brickNode = new Node3d("brick");
|
brickNode = new Node3d("brick");
|
||||||
brickNode.translate(vec3(-2, 3, -3));
|
brickNode.translate(vec3(-2, 2, -3));
|
||||||
Mesh brickMesh = Mesh.createCubeMesh(vec3(0, 0, 0), 0.8, vec4(0.8, 0.8, 0.8, 1));
|
Mesh brickMesh = Mesh.createCubeMesh(vec3(0, 0, 0), 0.8, vec4(0.8, 0.8, 0.8, 1));
|
||||||
Material brickMaterial = new Material(EffectId("textured.vert", "textured.frag", null), "brick", "brickn"); // with bump mapping
|
Material brickMaterial = new Material(EffectId("textured.vert", "textured.frag", null), "brick", "brickn"); // with bump mapping
|
||||||
brickNode.drawable = new Model(brickMaterial, brickMesh);
|
brickNode.drawable = new Model(brickMaterial, brickMesh);
|
||||||
|
@ -291,6 +291,9 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
angle += interval * 0.000002f;
|
angle += interval * 0.000002f;
|
||||||
invalidate();
|
invalidate();
|
||||||
suzanneNode.rotateY(interval * 0.000002f);
|
suzanneNode.rotateY(interval * 0.000002f);
|
||||||
|
brickNode.rotateY(interval * 0.00000123f);
|
||||||
|
brickNode.rotateZ(interval * 0.0000004123f);
|
||||||
|
brickNode.rotateX(interval * 0.0000007543f);
|
||||||
}
|
}
|
||||||
float angle = 0;
|
float angle = 0;
|
||||||
|
|
||||||
|
|
|
@ -481,10 +481,27 @@ class Mesh : RefCountedObject {
|
||||||
|
|
||||||
private void addQuad(ref vec3 v0, ref vec3 v1, ref vec3 v2, ref vec3 v3, ref vec4 color) {
|
private void addQuad(ref vec3 v0, ref vec3 v1, ref vec3 v2, ref vec3 v3, ref vec4 color) {
|
||||||
ushort startVertex = cast(ushort)vertexCount;
|
ushort startVertex = cast(ushort)vertexCount;
|
||||||
addVertex([v0.x, v0.y, v0.z, color.r, color.g, color.b, color.a, 0, 0]);
|
if (hasElement(VertexElementType.NORMAL)) {
|
||||||
addVertex([v1.x, v1.y, v1.z, color.r, color.g, color.b, color.a, 1, 0]);
|
vec3 normal = vec3.crossProduct((v1 - v0), (v3 - v0)).normalized;
|
||||||
addVertex([v2.x, v2.y, v2.z, color.r, color.g, color.b, color.a, 1, 1]);
|
if (hasElement(VertexElementType.TANGENT)) {
|
||||||
addVertex([v3.x, v3.y, v3.z, color.r, color.g, color.b, color.a, 0, 1]);
|
vec3 tangent = (v1 - v0).normalized;
|
||||||
|
vec3 binormal = (v3 - v0).normalized;
|
||||||
|
addVertex([v0.x, v0.y, v0.z, color.r, color.g, color.b, color.a, 0, 0, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z]);
|
||||||
|
addVertex([v1.x, v1.y, v1.z, color.r, color.g, color.b, color.a, 1, 0, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z]);
|
||||||
|
addVertex([v2.x, v2.y, v2.z, color.r, color.g, color.b, color.a, 1, 1, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z]);
|
||||||
|
addVertex([v3.x, v3.y, v3.z, color.r, color.g, color.b, color.a, 0, 1, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z]);
|
||||||
|
} else {
|
||||||
|
addVertex([v0.x, v0.y, v0.z, color.r, color.g, color.b, color.a, 0, 0, normal.x, normal.y, normal.z]);
|
||||||
|
addVertex([v1.x, v1.y, v1.z, color.r, color.g, color.b, color.a, 1, 0, normal.x, normal.y, normal.z]);
|
||||||
|
addVertex([v2.x, v2.y, v2.z, color.r, color.g, color.b, color.a, 1, 1, normal.x, normal.y, normal.z]);
|
||||||
|
addVertex([v3.x, v3.y, v3.z, color.r, color.g, color.b, color.a, 0, 1, normal.x, normal.y, normal.z]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addVertex([v0.x, v0.y, v0.z, color.r, color.g, color.b, color.a, 0, 0]);
|
||||||
|
addVertex([v1.x, v1.y, v1.z, color.r, color.g, color.b, color.a, 1, 0]);
|
||||||
|
addVertex([v2.x, v2.y, v2.z, color.r, color.g, color.b, color.a, 1, 1]);
|
||||||
|
addVertex([v3.x, v3.y, v3.z, color.r, color.g, color.b, color.a, 0, 1]);
|
||||||
|
}
|
||||||
addPart(PrimitiveType.triangles, [
|
addPart(PrimitiveType.triangles, [
|
||||||
cast(ushort)(startVertex + 0),
|
cast(ushort)(startVertex + 0),
|
||||||
cast(ushort)(startVertex + 1),
|
cast(ushort)(startVertex + 1),
|
||||||
|
@ -513,7 +530,7 @@ class Mesh : RefCountedObject {
|
||||||
|
|
||||||
static Mesh createCubeMesh(vec3 pos, float d=1, vec4 color = vec4(1,1,1,1)) {
|
static Mesh createCubeMesh(vec3 pos, float d=1, vec4 color = vec4(1,1,1,1)) {
|
||||||
Mesh mesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.COLOR, VertexElementType.TEXCOORD0
|
Mesh mesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.COLOR, VertexElementType.TEXCOORD0
|
||||||
//, VertexElementType.TANGENT, VertexElementType.BINORMAL
|
, VertexElementType.NORMAL, VertexElementType.TANGENT, VertexElementType.BINORMAL
|
||||||
));
|
));
|
||||||
mesh.addCubeMesh(pos, d, color);
|
mesh.addCubeMesh(pos, d, color);
|
||||||
return mesh;
|
return mesh;
|
||||||
|
|
Loading…
Reference in New Issue