From c404df39ef3e1d0647ebc56227e6db49fab45298 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sun, 2 Jul 2023 00:35:15 +0530 Subject: [PATCH] better shaders a bit --- src/DifBuilder.hx | 18 +++++++++--------- src/DtsObject.hx | 15 +++++++++------ src/shaders/DefaultCubemapMaterial.hx | 10 +++++----- src/shaders/DefaultCubemapNormalMaterial.hx | 14 +++++++------- .../DefaultCubemapNormalNoSpecMaterial.hx | 8 ++++---- src/shaders/DefaultDiffuseMaterial.hx | 4 ++-- src/shaders/DefaultMaterial.hx | 8 ++++---- src/shaders/DefaultNormalMaterial.hx | 8 ++++---- src/shaders/NoiseTileMaterial.hx | 8 ++++---- src/shaders/RefractMaterial.hx | 10 +++++----- 10 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/DifBuilder.hx b/src/DifBuilder.hx index b874a3b0..09b514ad 100644 --- a/src/DifBuilder.hx +++ b/src/DifBuilder.hx @@ -933,15 +933,15 @@ class DifBuilder { uvs.push(uv3); uvs.push(uv2); uvs.push(uv1); - t.push(new Point(tri.t3.x, tri.t3.y, tri.t3.z)); - t.push(new Point(tri.t2.x, tri.t2.y, tri.t2.z)); - t.push(new Point(tri.t1.x, tri.t1.y, tri.t1.z)); - b.push(new Point(tri.b3.x, tri.b3.y, tri.b3.z)); - b.push(new Point(tri.b2.x, tri.b2.y, tri.b2.z)); - b.push(new Point(tri.b1.x, tri.b1.y, tri.b1.z)); - n.push(new Point(tri.n3.x, tri.n3.y, tri.n3.z)); - n.push(new Point(tri.n2.x, tri.n2.y, tri.n2.z)); - n.push(new Point(tri.n1.x, tri.n1.y, tri.n1.z)); + t.push(new Point(-tri.t3.x, tri.t3.y, tri.t3.z)); + t.push(new Point(-tri.t2.x, tri.t2.y, tri.t2.z)); + t.push(new Point(-tri.t1.x, tri.t1.y, tri.t1.z)); + b.push(new Point(-tri.b3.x, tri.b3.y, tri.b3.z)); + b.push(new Point(-tri.b2.x, tri.b2.y, tri.b2.z)); + b.push(new Point(-tri.b1.x, tri.b1.y, tri.b1.z)); + n.push(new Point(-tri.n3.x, tri.n3.y, tri.n3.z)); + n.push(new Point(-tri.n2.x, tri.n2.y, tri.n2.z)); + n.push(new Point(-tri.n1.x, tri.n1.y, tri.n1.z)); } var prim = new Polygon(points); prim.uvs = uvs; diff --git a/src/DtsObject.hx b/src/DtsObject.hx index 220d95c5..2d93fa1d 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -826,12 +826,15 @@ class DtsObject extends GameObject { 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; + n0.x *= -1; + n1.x *= -1; + n2.x *= -1; return [ { diff --git a/src/shaders/DefaultCubemapMaterial.hx b/src/shaders/DefaultCubemapMaterial.hx index 1741bccb..f8caea43 100644 --- a/src/shaders/DefaultCubemapMaterial.hx +++ b/src/shaders/DefaultCubemapMaterial.hx @@ -45,28 +45,28 @@ class DefaultCubemapMaterial extends hxsl.Shader { } function vertex() { var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // 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; + // cubeEyePos.x *= -1; calculatedUV = input.uv; var objToTangentSpace = mat3(input.t, input.b, input.n); outLightVec = vec4(0); outNormal = input.normal; - outNormal.x *= -1; + // outNormal.x *= -1; var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; outLightVec.xyz = -inLightVec * objToTangentSpace; // var cubeVertPos = input.position * cubeTrans; // var cubeNormal = input.normal * cubeTrans; // var eyeToVert = (cubeVertPos - cubeEyePos).normalize(); // outReflectVec = reflect(eyeToVert, cubeNormal); var p = input.position; - p.x *= -1; + // p.x *= -1; outPos = (p / 100.0) * objToTangentSpace; outEyePos = (eyePos / 100.0) * objToTangentSpace; outLightVec.w = step(-0.5, dot(outNormal, -inLightVec)); diff --git a/src/shaders/DefaultCubemapNormalMaterial.hx b/src/shaders/DefaultCubemapNormalMaterial.hx index 6c92a65a..b42cf0e7 100644 --- a/src/shaders/DefaultCubemapNormalMaterial.hx +++ b/src/shaders/DefaultCubemapNormalMaterial.hx @@ -45,11 +45,11 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader { calculatedUV = input.uv; outLightVec = vec4(0); var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // eyePos.x *= -1; outNormal = input.normal; - outNormal.x *= -1; + // 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(outNormal, -inLightVec)); @@ -60,15 +60,15 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader { var cubeTrans = mat3(global.modelView); var cubeEyePos = camera.position - global.modelView[3].xyz; - cubeEyePos.x *= -1; + // cubeEyePos.x *= -1; outPos = input.position; - outPos.x *= -1; + // outPos.x *= -1; var cubeVertPos = input.position * cubeTrans; - cubeVertPos.x *= -1; + // cubeVertPos.x *= -1; var cubeNormal = (input.normal * cubeTrans).normalize(); - cubeNormal.x *= -1; + // cubeNormal.x *= -1; var eyeToVert = cubeVertPos - cubeEyePos; outReflectVec = reflect(eyeToVert, cubeNormal); } diff --git a/src/shaders/DefaultCubemapNormalNoSpecMaterial.hx b/src/shaders/DefaultCubemapNormalNoSpecMaterial.hx index c5a1b7ad..bf6f13ff 100644 --- a/src/shaders/DefaultCubemapNormalNoSpecMaterial.hx +++ b/src/shaders/DefaultCubemapNormalNoSpecMaterial.hx @@ -39,9 +39,9 @@ class DefaultCubemapNormalNoSpecMaterial extends hxsl.Shader { function vertex() { calculatedUV = input.uv; var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var pN = input.normal; - pN.x *= -1; + // pN.x *= -1; outShading = vec4(saturate(dot(-inLightVec, pN))); outShading.w = 1; outShading *= vec4(1.08, 1.03, 0.90, 1); @@ -49,10 +49,10 @@ class DefaultCubemapNormalNoSpecMaterial extends hxsl.Shader { // 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; + // cubeEyePos.x *= -1; var p = input.position; - p.x *= -1; + // p.x *= -1; var cubeVertPos = p * cubeTrans; var cubeNormal = (pN * cubeTrans).normalize(); diff --git a/src/shaders/DefaultDiffuseMaterial.hx b/src/shaders/DefaultDiffuseMaterial.hx index 19c0b766..e220deba 100644 --- a/src/shaders/DefaultDiffuseMaterial.hx +++ b/src/shaders/DefaultDiffuseMaterial.hx @@ -29,9 +29,9 @@ class DefaultDiffuseMaterial extends hxsl.Shader { calculatedUV = input.uv; var objToTangentSpace = mat3(input.t, input.b, input.n); var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var n = input.normal; - n.x *= -1; + // n.x *= -1; outShading = vec4(saturate(dot(-inLightVec, n))); outShading.w = 1; outShading *= vec4(1.08, 1.03, 0.90, 1); diff --git a/src/shaders/DefaultMaterial.hx b/src/shaders/DefaultMaterial.hx index 2a9e5daf..5abd9e61 100644 --- a/src/shaders/DefaultMaterial.hx +++ b/src/shaders/DefaultMaterial.hx @@ -47,17 +47,17 @@ 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) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // eyePos.x *= -1; // eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z); outLightVec.xyz = -inLightVec * objToTangentSpace; var p = input.position; - p.x *= -1; + // p.x *= -1; outPos = (p / 100.0) * objToTangentSpace; outEyePos = (eyePos / 100.0) * objToTangentSpace; var pN = input.normal; - pN.x *= -1; + // pN.x *= -1; outLightVec.w = isHalfTile ? step(0, dot(pN, -inLightVec)) : step(-0.5, dot(pN, -inLightVec)); } function fragment() { diff --git a/src/shaders/DefaultNormalMaterial.hx b/src/shaders/DefaultNormalMaterial.hx index b8b12ac1..4b7a9d73 100644 --- a/src/shaders/DefaultNormalMaterial.hx +++ b/src/shaders/DefaultNormalMaterial.hx @@ -43,11 +43,11 @@ class DefaultNormalMaterial extends hxsl.Shader { calculatedUV = input.uv; outLightVec = vec4(0); var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // eyePos.x *= -1; outNormal = input.normal; - outNormal.x *= -1; + // 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(outNormal, -inLightVec)); @@ -56,7 +56,7 @@ class DefaultNormalMaterial extends hxsl.Shader { outShading.w = 1; outShading *= vec4(1.08, 1.03, 0.90, 1); outPos = input.position; - outPos.x *= -1; + // outPos.x *= -1; } function fragment() { // Diffuse part diff --git a/src/shaders/NoiseTileMaterial.hx b/src/shaders/NoiseTileMaterial.hx index 3bf56761..07bd8f91 100644 --- a/src/shaders/NoiseTileMaterial.hx +++ b/src/shaders/NoiseTileMaterial.hx @@ -43,17 +43,17 @@ class NoiseTileMaterial extends hxsl.Shader { var objToTangentSpace = mat3(input.t, input.b, input.n); outLightVec = vec4(0); var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // eyePos.x *= -1; // eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z); outLightVec.xyz = -inLightVec * objToTangentSpace; var p = input.position; - p.x *= -1; + // p.x *= -1; outPos = (p / 100.0) * objToTangentSpace; outEyePos = (eyePos / 100.0) * objToTangentSpace; var n = input.normal; - n.x *= -1; + // n.x *= -1; outLightVec.w = step(0, dot(n, -inLightVec)); } function fragment() { diff --git a/src/shaders/RefractMaterial.hx b/src/shaders/RefractMaterial.hx index 701d5427..0a3a0d62 100644 --- a/src/shaders/RefractMaterial.hx +++ b/src/shaders/RefractMaterial.hx @@ -42,20 +42,20 @@ class RefractMaterial extends hxsl.Shader { } function vertex() { calculatedUV = input.uv; - var objToTangentSpace = transposeMat3(mat3(input.t, input.b, input.n)); + var objToTangentSpace = mat3(input.t, input.b, input.n); outLightVec = vec4(0); var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView)); - inLightVec.x *= -1; + // inLightVec.x *= -1; var eyePos = camera.position * mat3x4(global.modelViewInverse); - eyePos.x *= -1; + // eyePos.x *= -1; // eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z); outLightVec.xyz = -inLightVec * objToTangentSpace; var p = input.position; - p.x *= -1; + // p.x *= -1; outPos = (p / 100.0) * objToTangentSpace; outEyePos = (eyePos / 100.0) * objToTangentSpace; var n = input.normal; - n.x *= -1; + // n.x *= -1; outLightVec.w = step(-0.5, dot(n, -inLightVec)); } function fragment() {