mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 20:51:38 +00:00
better shaders a bit
This commit is contained in:
parent
3ab79b461b
commit
d155a8b709
10 changed files with 53 additions and 50 deletions
|
|
@ -933,15 +933,15 @@ class DifBuilder {
|
||||||
uvs.push(uv3);
|
uvs.push(uv3);
|
||||||
uvs.push(uv2);
|
uvs.push(uv2);
|
||||||
uvs.push(uv1);
|
uvs.push(uv1);
|
||||||
t.push(new Point(tri.t3.x, tri.t3.y, tri.t3.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.t2.x, tri.t2.y, tri.t2.z));
|
||||||
t.push(new Point(tri.t1.x, tri.t1.y, tri.t1.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.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.b2.x, tri.b2.y, tri.b2.z));
|
||||||
b.push(new Point(tri.b1.x, tri.b1.y, tri.b1.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.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.n2.x, tri.n2.y, tri.n2.z));
|
||||||
n.push(new Point(tri.n1.x, tri.n1.y, tri.n1.z));
|
n.push(new Point(-tri.n1.x, tri.n1.y, tri.n1.z));
|
||||||
}
|
}
|
||||||
var prim = new Polygon(points);
|
var prim = new Polygon(points);
|
||||||
prim.uvs = uvs;
|
prim.uvs = uvs;
|
||||||
|
|
|
||||||
|
|
@ -826,12 +826,15 @@ class DtsObject extends GameObject {
|
||||||
n2.scale(-1);
|
n2.scale(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// t0.x *= -1;
|
t0.x *= -1;
|
||||||
// t1.x *= -1;
|
t1.x *= -1;
|
||||||
// t2.x *= -1;
|
t2.x *= -1;
|
||||||
// b0.x *= -1;
|
b0.x *= -1;
|
||||||
// b1.x *= -1;
|
b1.x *= -1;
|
||||||
// b2.x *= -1;
|
b2.x *= -1;
|
||||||
|
n0.x *= -1;
|
||||||
|
n1.x *= -1;
|
||||||
|
n2.x *= -1;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -45,28 +45,28 @@ class DefaultCubemapMaterial extends hxsl.Shader {
|
||||||
}
|
}
|
||||||
function vertex() {
|
function vertex() {
|
||||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
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);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
var cubeTrans = mat3(global.modelView);
|
var cubeTrans = mat3(global.modelView);
|
||||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||||
cubeEyePos.x *= -1;
|
// cubeEyePos.x *= -1;
|
||||||
calculatedUV = input.uv;
|
calculatedUV = input.uv;
|
||||||
|
|
||||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||||
outLightVec = vec4(0);
|
outLightVec = vec4(0);
|
||||||
|
|
||||||
outNormal = input.normal;
|
outNormal = input.normal;
|
||||||
outNormal.x *= -1;
|
// outNormal.x *= -1;
|
||||||
|
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||||
inLightVec.x *= -1;
|
// inLightVec.x *= -1;
|
||||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||||
// var cubeVertPos = input.position * cubeTrans;
|
// var cubeVertPos = input.position * cubeTrans;
|
||||||
// var cubeNormal = input.normal * cubeTrans;
|
// var cubeNormal = input.normal * cubeTrans;
|
||||||
// var eyeToVert = (cubeVertPos - cubeEyePos).normalize();
|
// var eyeToVert = (cubeVertPos - cubeEyePos).normalize();
|
||||||
// outReflectVec = reflect(eyeToVert, cubeNormal);
|
// outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||||
var p = input.position;
|
var p = input.position;
|
||||||
p.x *= -1;
|
// p.x *= -1;
|
||||||
outPos = (p / 100.0) * objToTangentSpace;
|
outPos = (p / 100.0) * objToTangentSpace;
|
||||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
||||||
calculatedUV = input.uv;
|
calculatedUV = input.uv;
|
||||||
outLightVec = vec4(0);
|
outLightVec = vec4(0);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
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);
|
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||||
eyePos.x *= -1;
|
// eyePos.x *= -1;
|
||||||
outNormal = input.normal;
|
outNormal = input.normal;
|
||||||
outNormal.x *= -1;
|
// outNormal.x *= -1;
|
||||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
outLightVec.xyz = -inLightVec;
|
outLightVec.xyz = -inLightVec;
|
||||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||||
|
|
@ -60,15 +60,15 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
||||||
|
|
||||||
var cubeTrans = mat3(global.modelView);
|
var cubeTrans = mat3(global.modelView);
|
||||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||||
cubeEyePos.x *= -1;
|
// cubeEyePos.x *= -1;
|
||||||
|
|
||||||
outPos = input.position;
|
outPos = input.position;
|
||||||
outPos.x *= -1;
|
// outPos.x *= -1;
|
||||||
|
|
||||||
var cubeVertPos = input.position * cubeTrans;
|
var cubeVertPos = input.position * cubeTrans;
|
||||||
cubeVertPos.x *= -1;
|
// cubeVertPos.x *= -1;
|
||||||
var cubeNormal = (input.normal * cubeTrans).normalize();
|
var cubeNormal = (input.normal * cubeTrans).normalize();
|
||||||
cubeNormal.x *= -1;
|
// cubeNormal.x *= -1;
|
||||||
var eyeToVert = cubeVertPos - cubeEyePos;
|
var eyeToVert = cubeVertPos - cubeEyePos;
|
||||||
outReflectVec = reflect(eyeToVert, cubeNormal);
|
outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ class DefaultCubemapNormalNoSpecMaterial extends hxsl.Shader {
|
||||||
function vertex() {
|
function vertex() {
|
||||||
calculatedUV = input.uv;
|
calculatedUV = input.uv;
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||||
inLightVec.x *= -1;
|
// inLightVec.x *= -1;
|
||||||
var pN = input.normal;
|
var pN = input.normal;
|
||||||
pN.x *= -1;
|
// pN.x *= -1;
|
||||||
outShading = vec4(saturate(dot(-inLightVec, pN)));
|
outShading = vec4(saturate(dot(-inLightVec, pN)));
|
||||||
outShading.w = 1;
|
outShading.w = 1;
|
||||||
outShading *= vec4(1.08, 1.03, 0.90, 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);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
var cubeTrans = mat3(global.modelView);
|
var cubeTrans = mat3(global.modelView);
|
||||||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||||
cubeEyePos.x *= -1;
|
// cubeEyePos.x *= -1;
|
||||||
|
|
||||||
var p = input.position;
|
var p = input.position;
|
||||||
p.x *= -1;
|
// p.x *= -1;
|
||||||
|
|
||||||
var cubeVertPos = p * cubeTrans;
|
var cubeVertPos = p * cubeTrans;
|
||||||
var cubeNormal = (pN * cubeTrans).normalize();
|
var cubeNormal = (pN * cubeTrans).normalize();
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ class DefaultDiffuseMaterial extends hxsl.Shader {
|
||||||
calculatedUV = input.uv;
|
calculatedUV = input.uv;
|
||||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||||
inLightVec.x *= -1;
|
// inLightVec.x *= -1;
|
||||||
var n = input.normal;
|
var n = input.normal;
|
||||||
n.x *= -1;
|
// n.x *= -1;
|
||||||
outShading = vec4(saturate(dot(-inLightVec, n)));
|
outShading = vec4(saturate(dot(-inLightVec, n)));
|
||||||
outShading.w = 1;
|
outShading.w = 1;
|
||||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||||
|
|
|
||||||
|
|
@ -47,17 +47,17 @@ class DefaultMaterial extends hxsl.Shader {
|
||||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||||
outLightVec = vec4(0);
|
outLightVec = vec4(0);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
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);
|
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);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||||
var p = input.position;
|
var p = input.position;
|
||||||
p.x *= -1;
|
// p.x *= -1;
|
||||||
outPos = (p / 100.0) * objToTangentSpace;
|
outPos = (p / 100.0) * objToTangentSpace;
|
||||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||||
var pN = input.normal;
|
var pN = input.normal;
|
||||||
pN.x *= -1;
|
// pN.x *= -1;
|
||||||
outLightVec.w = isHalfTile ? step(0, dot(pN, -inLightVec)) : step(-0.5, dot(pN, -inLightVec));
|
outLightVec.w = isHalfTile ? step(0, dot(pN, -inLightVec)) : step(-0.5, dot(pN, -inLightVec));
|
||||||
}
|
}
|
||||||
function fragment() {
|
function fragment() {
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
||||||
calculatedUV = input.uv;
|
calculatedUV = input.uv;
|
||||||
outLightVec = vec4(0);
|
outLightVec = vec4(0);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
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);
|
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||||
eyePos.x *= -1;
|
// eyePos.x *= -1;
|
||||||
outNormal = input.normal;
|
outNormal = input.normal;
|
||||||
outNormal.x *= -1;
|
// outNormal.x *= -1;
|
||||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
outLightVec.xyz = -inLightVec;
|
outLightVec.xyz = -inLightVec;
|
||||||
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
outLightVec.w = step(-0.5, dot(outNormal, -inLightVec));
|
||||||
|
|
@ -56,7 +56,7 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
||||||
outShading.w = 1;
|
outShading.w = 1;
|
||||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||||
outPos = input.position;
|
outPos = input.position;
|
||||||
outPos.x *= -1;
|
// outPos.x *= -1;
|
||||||
}
|
}
|
||||||
function fragment() {
|
function fragment() {
|
||||||
// Diffuse part
|
// Diffuse part
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,17 @@ class NoiseTileMaterial extends hxsl.Shader {
|
||||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||||
outLightVec = vec4(0);
|
outLightVec = vec4(0);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
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);
|
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);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||||
var p = input.position;
|
var p = input.position;
|
||||||
p.x *= -1;
|
// p.x *= -1;
|
||||||
outPos = (p / 100.0) * objToTangentSpace;
|
outPos = (p / 100.0) * objToTangentSpace;
|
||||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||||
var n = input.normal;
|
var n = input.normal;
|
||||||
n.x *= -1;
|
// n.x *= -1;
|
||||||
outLightVec.w = step(0, dot(n, -inLightVec));
|
outLightVec.w = step(0, dot(n, -inLightVec));
|
||||||
}
|
}
|
||||||
function fragment() {
|
function fragment() {
|
||||||
|
|
|
||||||
|
|
@ -42,20 +42,20 @@ class RefractMaterial extends hxsl.Shader {
|
||||||
}
|
}
|
||||||
function vertex() {
|
function vertex() {
|
||||||
calculatedUV = input.uv;
|
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);
|
outLightVec = vec4(0);
|
||||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
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);
|
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);
|
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||||
var p = input.position;
|
var p = input.position;
|
||||||
p.x *= -1;
|
// p.x *= -1;
|
||||||
outPos = (p / 100.0) * objToTangentSpace;
|
outPos = (p / 100.0) * objToTangentSpace;
|
||||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||||
var n = input.normal;
|
var n = input.normal;
|
||||||
n.x *= -1;
|
// n.x *= -1;
|
||||||
outLightVec.w = step(-0.5, dot(n, -inLightVec));
|
outLightVec.w = step(-0.5, dot(n, -inLightVec));
|
||||||
}
|
}
|
||||||
function fragment() {
|
function fragment() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue