mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix interior lighting
This commit is contained in:
parent
883ef095f0
commit
d5901ffc24
11 changed files with 263 additions and 93 deletions
|
|
@ -450,9 +450,9 @@ class DifBuilder {
|
|||
if (st.x * normal.x + st.y * normal.y + st.z * normal.z < 0) {
|
||||
st.scale(-1);
|
||||
}
|
||||
s.x *= -1;
|
||||
t.x *= -1;
|
||||
st.x *= -1;
|
||||
// s.x *= -1;
|
||||
// t.x *= -1;
|
||||
// st.x *= -1;
|
||||
|
||||
for (k in (surface.windingStart + 2)...(surface.windingStart + surface.windingCount)) {
|
||||
var p1, p2, p3;
|
||||
|
|
@ -589,7 +589,7 @@ class DifBuilder {
|
|||
bucket = {
|
||||
referenceNormal: normal,
|
||||
triangleIndices: [],
|
||||
normals: []
|
||||
normals: [],
|
||||
};
|
||||
buckets.push(bucket);
|
||||
}
|
||||
|
|
@ -764,12 +764,24 @@ class DifBuilder {
|
|||
for (j in 0...bucket.triangleIndices.length) {
|
||||
var index = bucket.triangleIndices[j];
|
||||
var tri = triangles[index];
|
||||
if (tri.p1 == vtex)
|
||||
if (tri.p1 == vtex) {
|
||||
tri.normal1 = avgNormal;
|
||||
if (tri.p2 == vtex)
|
||||
tri.n1 = avgNormal;
|
||||
tri.t1 = tri.t1.sub(avgNormal.scalar(avgNormal.dot(tri.t1))).normalized();
|
||||
tri.b1 = tri.b1.sub(avgNormal.scalar(avgNormal.dot(tri.b1))).normalized();
|
||||
}
|
||||
if (tri.p2 == vtex) {
|
||||
tri.normal2 = avgNormal;
|
||||
if (tri.p3 == vtex)
|
||||
tri.n2 = avgNormal;
|
||||
tri.t2 = tri.t2.sub(avgNormal.scalar(avgNormal.dot(tri.t2))).normalized();
|
||||
tri.b2 = tri.b2.sub(avgNormal.scalar(avgNormal.dot(tri.b2))).normalized();
|
||||
}
|
||||
if (tri.p3 == vtex) {
|
||||
tri.normal3 = avgNormal;
|
||||
tri.n3 = avgNormal;
|
||||
tri.t3 = tri.t3.sub(avgNormal.scalar(avgNormal.dot(tri.t3))).normalized();
|
||||
tri.b3 = tri.b3.sub(avgNormal.scalar(avgNormal.dot(tri.b3))).normalized();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
232
src/DtsObject.hx
232
src/DtsObject.hx
|
|
@ -783,7 +783,7 @@ class DtsObject extends GameObject {
|
|||
normalizeSafe(t0);
|
||||
normalizeSafe(b0);
|
||||
var n0 = t0.cross(b0);
|
||||
n0.x *= -1;
|
||||
// n0.x *= -1;
|
||||
if (n0.dot(vertexNormals[i0]) < 0.0) {
|
||||
n0.scale(-1);
|
||||
}
|
||||
|
|
@ -792,7 +792,7 @@ class DtsObject extends GameObject {
|
|||
normalizeSafe(t1);
|
||||
normalizeSafe(b1);
|
||||
var n1 = t1.cross(b1);
|
||||
n1.x *= -1;
|
||||
// n1.x *= -1;
|
||||
if (n1.dot(vertexNormals[i1]) < 0.0) {
|
||||
n1.scale(-1);
|
||||
}
|
||||
|
|
@ -801,17 +801,17 @@ class DtsObject extends GameObject {
|
|||
normalizeSafe(t2);
|
||||
normalizeSafe(b2);
|
||||
var n2 = t2.cross(b2);
|
||||
n2.x *= -1;
|
||||
// n2.x *= -1;
|
||||
if (n2.dot(vertexNormals[i2]) < 0.0) {
|
||||
n2.scale(-1);
|
||||
}
|
||||
|
||||
t0.x *= -1;
|
||||
t1.x *= -1;
|
||||
t2.x *= -1;
|
||||
b0.x *= -1;
|
||||
b1.x *= -1;
|
||||
b2.x *= -1;
|
||||
// t0.x *= -1;
|
||||
// t1.x *= -1;
|
||||
// t2.x *= -1;
|
||||
// b0.x *= -1;
|
||||
// b1.x *= -1;
|
||||
// b2.x *= -1;
|
||||
|
||||
return [
|
||||
{
|
||||
|
|
@ -832,6 +832,8 @@ class DtsObject extends GameObject {
|
|||
];
|
||||
}
|
||||
|
||||
var triangles = [];
|
||||
|
||||
var ab = new Vector();
|
||||
var ac = new Vector();
|
||||
function addTriangleFromIndices(i1:Int, i2:Int, i3:Int, materialIndex:Int) {
|
||||
|
|
@ -860,22 +862,29 @@ class DtsObject extends GameObject {
|
|||
|
||||
// }
|
||||
|
||||
var geometrydata = materialGeometry[materialIndex];
|
||||
|
||||
for (index in [i3, i2, i1]) {
|
||||
var vertex = vertices[index];
|
||||
geometrydata.vertices.push(new Vector(vertex.x, vertex.y, vertex.z));
|
||||
|
||||
var uv = dtsMesh.uv[index];
|
||||
geometrydata.uvs.push(new UV(uv.x, uv.y));
|
||||
|
||||
var normal = vertexNormals[index];
|
||||
geometrydata.normals.push(new Vector(normal.x, normal.y, normal.z));
|
||||
}
|
||||
|
||||
geometrydata.indices.push(i1);
|
||||
geometrydata.indices.push(i2);
|
||||
geometrydata.indices.push(i3);
|
||||
var tri = {
|
||||
material: materialIndex,
|
||||
vertices: [
|
||||
new Vector(vertices[i3].x, vertices[i3].y, vertices[i3].z),
|
||||
new Vector(vertices[i2].x, vertices[i2].y, vertices[i2].z),
|
||||
new Vector(vertices[i1].x, vertices[i1].y, vertices[i1].z)
|
||||
],
|
||||
uvs: [
|
||||
new UV(dtsMesh.uv[i3].x, dtsMesh.uv[i3].y),
|
||||
new UV(dtsMesh.uv[i2].x, dtsMesh.uv[i2].y),
|
||||
new UV(dtsMesh.uv[i1].x, dtsMesh.uv[i1].y)
|
||||
],
|
||||
normals: [
|
||||
new Vector(vertexNormals[i3].x, vertexNormals[i3].y, vertexNormals[i3].z),
|
||||
new Vector(vertexNormals[i2].x, vertexNormals[i2].y, vertexNormals[i2].z),
|
||||
new Vector(vertexNormals[i1].x, vertexNormals[i1].y, vertexNormals[i1].z)
|
||||
],
|
||||
indices: [i1, i2, i3],
|
||||
t: [],
|
||||
b: [],
|
||||
n: [],
|
||||
};
|
||||
return tri;
|
||||
}
|
||||
|
||||
for (primitive in dtsMesh.primitives) {
|
||||
|
|
@ -891,18 +900,18 @@ class DtsObject extends GameObject {
|
|||
var i2 = dtsMesh.indices[i + 1];
|
||||
var i3 = dtsMesh.indices[i + 2];
|
||||
|
||||
addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
|
||||
var tri = addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
var tbn = createTextureSpaceMatrix(dtsMesh.indices[i], dtsMesh.indices[i + 1], dtsMesh.indices[i + 2]);
|
||||
geometrydata.tangents.push(tbn[2].tangent);
|
||||
geometrydata.tangents.push(tbn[1].tangent);
|
||||
geometrydata.tangents.push(tbn[0].tangent);
|
||||
geometrydata.bitangents.push(tbn[2].bitangent);
|
||||
geometrydata.bitangents.push(tbn[1].bitangent);
|
||||
geometrydata.bitangents.push(tbn[0].bitangent);
|
||||
geometrydata.texNormals.push(tbn[2].normal);
|
||||
geometrydata.texNormals.push(tbn[1].normal);
|
||||
geometrydata.texNormals.push(tbn[0].normal);
|
||||
tri.t.push(tbn[2].tangent);
|
||||
tri.t.push(tbn[1].tangent);
|
||||
tri.t.push(tbn[0].tangent);
|
||||
tri.b.push(tbn[2].bitangent);
|
||||
tri.b.push(tbn[1].bitangent);
|
||||
tri.b.push(tbn[0].bitangent);
|
||||
tri.n.push(tbn[2].normal);
|
||||
tri.n.push(tbn[1].normal);
|
||||
tri.n.push(tbn[0].normal);
|
||||
triangles.push(tri);
|
||||
|
||||
i += 3;
|
||||
}
|
||||
|
|
@ -920,18 +929,18 @@ class DtsObject extends GameObject {
|
|||
i3 = temp;
|
||||
}
|
||||
|
||||
addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
|
||||
var tri = addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
var tbn = createTextureSpaceMatrix(dtsMesh.indices[i], dtsMesh.indices[i + 1], dtsMesh.indices[i + 2]);
|
||||
geometrydata.tangents.push(tbn[2].tangent);
|
||||
geometrydata.tangents.push(tbn[1].tangent);
|
||||
geometrydata.tangents.push(tbn[0].tangent);
|
||||
geometrydata.bitangents.push(tbn[2].bitangent);
|
||||
geometrydata.bitangents.push(tbn[1].bitangent);
|
||||
geometrydata.bitangents.push(tbn[0].bitangent);
|
||||
geometrydata.texNormals.push(tbn[2].normal);
|
||||
geometrydata.texNormals.push(tbn[1].normal);
|
||||
geometrydata.texNormals.push(tbn[0].normal);
|
||||
tri.t.push(tbn[2].tangent);
|
||||
tri.t.push(tbn[1].tangent);
|
||||
tri.t.push(tbn[0].tangent);
|
||||
tri.b.push(tbn[2].bitangent);
|
||||
tri.b.push(tbn[1].bitangent);
|
||||
tri.b.push(tbn[0].bitangent);
|
||||
tri.n.push(tbn[2].normal);
|
||||
tri.n.push(tbn[1].normal);
|
||||
tri.n.push(tbn[0].normal);
|
||||
triangles.push(tri);
|
||||
|
||||
k++;
|
||||
}
|
||||
|
|
@ -942,24 +951,131 @@ class DtsObject extends GameObject {
|
|||
var i2 = dtsMesh.indices[i + 1];
|
||||
var i3 = dtsMesh.indices[i + 2];
|
||||
|
||||
addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
|
||||
var tri = addTriangleFromIndices(i1, i2, i3, materialIndex);
|
||||
var tbn = createTextureSpaceMatrix(dtsMesh.indices[primitive.firstElement], dtsMesh.indices[i + 1], dtsMesh.indices[i + 2]);
|
||||
geometrydata.tangents.push(tbn[2].tangent);
|
||||
geometrydata.tangents.push(tbn[1].tangent);
|
||||
geometrydata.tangents.push(tbn[0].tangent);
|
||||
geometrydata.bitangents.push(tbn[2].bitangent);
|
||||
geometrydata.bitangents.push(tbn[1].bitangent);
|
||||
geometrydata.bitangents.push(tbn[0].bitangent);
|
||||
geometrydata.texNormals.push(tbn[2].normal);
|
||||
geometrydata.texNormals.push(tbn[1].normal);
|
||||
geometrydata.texNormals.push(tbn[0].normal);
|
||||
tri.t.push(tbn[2].tangent);
|
||||
tri.t.push(tbn[1].tangent);
|
||||
tri.t.push(tbn[0].tangent);
|
||||
tri.b.push(tbn[2].bitangent);
|
||||
tri.b.push(tbn[1].bitangent);
|
||||
tri.b.push(tbn[0].bitangent);
|
||||
tri.n.push(tbn[2].normal);
|
||||
tri.n.push(tbn[1].normal);
|
||||
tri.n.push(tbn[0].normal);
|
||||
triangles.push(tri);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var vertexBuckets = new Map<Vector, Array<{
|
||||
refNormal:Vector,
|
||||
triangles:Array<Int>,
|
||||
normals:Array<Vector>,
|
||||
ns:Array<Vector>
|
||||
}>>();
|
||||
|
||||
for (i in 0...triangles.length) {
|
||||
var tri = triangles[i];
|
||||
var norm = tri.normals[0].add(tri.normals[1]).add(tri.normals[2]).multiply(1 / 3);
|
||||
for (k in 0...triangles[i].vertices.length) {
|
||||
var v = triangles[i].vertices[k];
|
||||
var buckets = vertexBuckets.get(v);
|
||||
if (buckets == null) {
|
||||
buckets = [];
|
||||
vertexBuckets.set(v, buckets);
|
||||
}
|
||||
var bucket:{
|
||||
refNormal:Vector,
|
||||
triangles:Array<Int>,
|
||||
normals:Array<Vector>,
|
||||
ns:Array<Vector>
|
||||
} = null;
|
||||
for (j in 0...buckets.length) {
|
||||
bucket = buckets[j];
|
||||
if (tri.normals[k].dot(bucket.refNormal) > Math.cos(Math.PI / 12)) {
|
||||
break;
|
||||
}
|
||||
bucket = null;
|
||||
}
|
||||
if (bucket == null) {
|
||||
bucket = {
|
||||
refNormal: norm,
|
||||
triangles: [],
|
||||
normals: [],
|
||||
ns: [],
|
||||
};
|
||||
buckets.push(bucket);
|
||||
}
|
||||
bucket.triangles.push(i);
|
||||
bucket.normals.push(tri.normals[k]);
|
||||
bucket.ns.push(tri.n[k]);
|
||||
}
|
||||
}
|
||||
|
||||
for (vtex => buckets in vertexBuckets) {
|
||||
for (i in 0...buckets.length) {
|
||||
var bucket = buckets[i];
|
||||
var avgNormal = new Vector();
|
||||
var averageN = new Vector();
|
||||
for (normal in bucket.normals)
|
||||
avgNormal = avgNormal.add(normal);
|
||||
avgNormal.scale(1 / bucket.normals.length);
|
||||
for (n in bucket.ns)
|
||||
averageN = averageN.add(n);
|
||||
averageN.scale(1 / bucket.ns.length);
|
||||
for (j in 0...bucket.triangles.length) {
|
||||
var index = bucket.triangles[j];
|
||||
var tri = triangles[index];
|
||||
if (tri.vertices[0] == vtex) {
|
||||
tri.normals[0] = avgNormal;
|
||||
tri.n[0] = averageN;
|
||||
tri.t[0] = tri.t[0].sub(averageN.multiply(averageN.dot(tri.t[0]))).normalized();
|
||||
tri.b[0] = tri.b[0].sub(averageN.multiply(averageN.dot(tri.b[0]))).normalized();
|
||||
}
|
||||
if (tri.vertices[1] == vtex) {
|
||||
tri.normals[1] = avgNormal;
|
||||
tri.n[1] = averageN;
|
||||
tri.t[1] = tri.t[1].sub(averageN.multiply(averageN.dot(tri.t[1]))).normalized();
|
||||
tri.b[1] = tri.b[1].sub(averageN.multiply(averageN.dot(tri.b[1]))).normalized();
|
||||
}
|
||||
if (tri.vertices[2] == vtex) {
|
||||
tri.normals[2] = avgNormal;
|
||||
tri.n[2] = averageN;
|
||||
tri.t[2] = tri.t[2].sub(averageN.multiply(averageN.dot(tri.t[2]))).normalized();
|
||||
tri.b[2] = tri.b[2].sub(averageN.multiply(averageN.dot(tri.b[2]))).normalized();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now *actually* generate the material geometry
|
||||
for (tri in triangles) {
|
||||
var matGeo = materialGeometry[tri.material];
|
||||
matGeo.vertices.push(tri.vertices[0]);
|
||||
matGeo.vertices.push(tri.vertices[1]);
|
||||
matGeo.vertices.push(tri.vertices[2]);
|
||||
matGeo.normals.push(tri.normals[0]);
|
||||
matGeo.normals.push(tri.normals[1]);
|
||||
matGeo.normals.push(tri.normals[2]);
|
||||
matGeo.tangents.push(tri.t[0]);
|
||||
matGeo.tangents.push(tri.t[1]);
|
||||
matGeo.tangents.push(tri.t[2]);
|
||||
matGeo.bitangents.push(tri.b[0]);
|
||||
matGeo.bitangents.push(tri.b[1]);
|
||||
matGeo.bitangents.push(tri.b[2]);
|
||||
matGeo.texNormals.push(tri.n[0]);
|
||||
matGeo.texNormals.push(tri.n[1]);
|
||||
matGeo.texNormals.push(tri.n[2]);
|
||||
matGeo.uvs.push(tri.uvs[0]);
|
||||
matGeo.uvs.push(tri.uvs[1]);
|
||||
matGeo.uvs.push(tri.uvs[2]);
|
||||
matGeo.indices.push(tri.indices[0]);
|
||||
matGeo.indices.push(tri.indices[1]);
|
||||
matGeo.indices.push(tri.indices[2]);
|
||||
}
|
||||
|
||||
return materialGeometry;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,30 +35,37 @@ class DefaultCubemapMaterial extends hxsl.Shader {
|
|||
@var var outLightVec:Vec4;
|
||||
@var var outPos:Vec3;
|
||||
@var var outEyePos:Vec3;
|
||||
@var var outNormal:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function vertex() {
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
var cubeTrans = mat3(global.modelView);
|
||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||
|
||||
cubeEyePos.x *= -1;
|
||||
calculatedUV = input.uv;
|
||||
|
||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||
outLightVec = vec4(0);
|
||||
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
outNormal = input.normal;
|
||||
outNormal.x *= -1;
|
||||
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
// var cubeVertPos = input.position * cubeTrans;
|
||||
// var cubeNormal = input.normal * cubeTrans;
|
||||
// var eyeToVert = (cubeVertPos - cubeEyePos).normalize();
|
||||
// outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
outPos = (p / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var ambient = vec4(0.472, 0.424, 0.475, 1.00);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
@var var outLightVec:Vec4;
|
||||
@var var outEyePos:Vec3;
|
||||
@var var outReflectVec:Vec3;
|
||||
@var var outNormal:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
|
|
@ -39,21 +40,28 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
outNormal = input.normal;
|
||||
outNormal.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||
outEyePos = eyePos;
|
||||
outShading = vec4(saturate(dot(-inLightVec, input.normal)));
|
||||
outShading = vec4(saturate(dot(-inLightVec, outNormal)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
|
||||
var cubeTrans = mat3(global.modelView);
|
||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||
cubeEyePos.x *= -1;
|
||||
|
||||
var cubeVertPos = input.position * cubeTrans;
|
||||
var cubeNormal = (input.normal * cubeTrans).normalize();
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
|
||||
var cubeVertPos = p * cubeTrans;
|
||||
var cubeNormal = (outNormal * cubeTrans).normalize();
|
||||
var eyeToVert = cubeVertPos - cubeEyePos;
|
||||
outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||
}
|
||||
|
|
@ -67,7 +75,7 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
|
||||
var eyeVec = (outEyePos - input.position).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(input.normal.dot(halfAng)) * outLightVec.w;
|
||||
var specValue = saturate(outNormal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
||||
outCol.a = 1;
|
||||
|
|
|
|||
|
|
@ -35,17 +35,23 @@ class DefaultCubemapNormalNoSpecMaterial extends hxsl.Shader {
|
|||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
outShading = vec4(saturate(dot(-inLightVec, input.normal)));
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var pN = input.normal;
|
||||
pN.x *= -1;
|
||||
outShading = vec4(saturate(dot(-inLightVec, pN)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
var cubeTrans = mat3(global.modelView);
|
||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||
cubeEyePos.x *= -1;
|
||||
|
||||
var cubeVertPos = input.position * cubeTrans;
|
||||
var cubeNormal = (input.normal * cubeTrans).normalize();
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
|
||||
var cubeVertPos = p * cubeTrans;
|
||||
var cubeNormal = (pN * cubeTrans).normalize();
|
||||
var eyeToVert = cubeVertPos - cubeEyePos;
|
||||
outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@ class DefaultDiffuseMaterial extends hxsl.Shader {
|
|||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
outShading = vec4(saturate(dot(-inLightVec, input.normal)));
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var n = input.normal;
|
||||
n.x *= -1;
|
||||
outShading = vec4(saturate(dot(-inLightVec, n)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,13 +43,18 @@ class DefaultMaterial extends hxsl.Shader {
|
|||
}
|
||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
outPos = (p / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
var pN = input.normal;
|
||||
pN.x *= -1;
|
||||
outLightVec.w = step(-0.5, dot(pN, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
@var var outShading:Vec4;
|
||||
@var var outLightVec:Vec4;
|
||||
@var var outEyePos:Vec3;
|
||||
@var var outNormal:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
|
|
@ -39,11 +40,14 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
outNormal = input.normal;
|
||||
outNormal.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||
outEyePos = eyePos;
|
||||
outShading = vec4(saturate(dot(-inLightVec, input.normal)));
|
||||
outShading = vec4(saturate(dot(-inLightVec, outNormal)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
}
|
||||
|
|
@ -56,7 +60,7 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
|
||||
var eyeVec = (outEyePos - input.position).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(input.normal.dot(halfAng)) * outLightVec.w;
|
||||
var specValue = saturate(outNormal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
||||
outCol.a = 1;
|
||||
|
|
|
|||
|
|
@ -39,13 +39,18 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
calculatedUV = input.uv;
|
||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
outPos = (p / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(0, dot(input.normal, -inLightVec));
|
||||
var n = input.normal;
|
||||
n.x *= -1;
|
||||
outLightVec.w = step(0, dot(n, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
|
|
|
|||
|
|
@ -43,11 +43,16 @@ class RefractMaterial extends hxsl.Shader {
|
|||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
outPos = (p / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
var n = input.normal;
|
||||
n.x *= -1;
|
||||
outLightVec.w = step(-0.5, dot(n, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class AntiGravity extends PowerUp {
|
|||
diffuseTex.mipMap = Nearest;
|
||||
var normalTex = ResourceLoader.getTexture("data/shapes/items/antigrav_bump.png").resource;
|
||||
normalTex.wrap = Repeat;
|
||||
normalTex.mipMap = Nearest;
|
||||
normalTex.mipMap = None;
|
||||
var shader = new shaders.DefaultMaterial(diffuseTex, normalTex, 32, new h3d.Vector(0.8, 0.8, 0.6, 1), 1);
|
||||
shader.doGammaRamp = false;
|
||||
var dtsTex = material.mainPass.getShader(shaders.DtsTexture);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue