mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
some fixes to shaders
This commit is contained in:
parent
96dd92577c
commit
c63efec2bf
9 changed files with 65 additions and 25 deletions
|
|
@ -204,7 +204,7 @@ class DifBuilder {
|
|||
diffuseTex.mipMap = Nearest;
|
||||
var normalTex = ResourceLoader.getTexture(normalTexture).resource;
|
||||
normalTex.wrap = Repeat;
|
||||
normalTex.mipMap = Nearest;
|
||||
normalTex.mipMap = None;
|
||||
var shader = new DefaultMaterial(diffuseTex, normalTex, shininess, specularColor, uvScaleFactor, half);
|
||||
onFinish(shader);
|
||||
});
|
||||
|
|
@ -221,7 +221,7 @@ class DifBuilder {
|
|||
diffuseTex.mipMap = Nearest;
|
||||
var normalTex = ResourceLoader.getTexture(normalTexture).resource;
|
||||
normalTex.wrap = Repeat;
|
||||
normalTex.mipMap = Nearest;
|
||||
normalTex.mipMap = None;
|
||||
|
||||
var cubemapTex = new h3d.mat.Texture(128, 128, [Cube]);
|
||||
var cubemapFace1 = ResourceLoader.getImage('data/textures/acubexpos2.png').resource;
|
||||
|
|
@ -268,7 +268,7 @@ class DifBuilder {
|
|||
normalTex.mipMap = Nearest;
|
||||
var noiseTex = ResourceLoader.getTexture('data/textures/noise${noiseSuffix}.jpg').resource;
|
||||
noiseTex.wrap = Repeat;
|
||||
noiseTex.mipMap = Nearest;
|
||||
noiseTex.mipMap = None;
|
||||
var shader = new NoiseTileMaterial(diffuseTex, normalTex, noiseTex, shininess, specular, 1);
|
||||
onFinish(shader);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class DefaultCubemapMaterial extends hxsl.Shader {
|
|||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
function vertex() {
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
|
|
@ -55,7 +58,8 @@ class DefaultCubemapMaterial extends hxsl.Shader {
|
|||
outNormal = input.normal;
|
||||
outNormal.x *= -1;
|
||||
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
// var cubeVertPos = input.position * cubeTrans;
|
||||
// var cubeNormal = input.normal * cubeTrans;
|
||||
|
|
@ -73,7 +77,8 @@ class DefaultCubemapMaterial extends hxsl.Shader {
|
|||
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
var outCol = diffuse;
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1;
|
||||
bumpNormal.y *= -1;
|
||||
|
||||
var incidentRay = normalize(pixelTransformedPosition - camera.position);
|
||||
var reflectionRay = reflect(incidentRay, transformedNormal);
|
||||
|
|
|
|||
|
|
@ -33,14 +33,19 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
@var var outEyePos:Vec3;
|
||||
@var var outReflectVec:Vec3;
|
||||
@var var outNormal:Vec3;
|
||||
@var var outPos:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
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) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
outNormal = input.normal;
|
||||
|
|
@ -57,11 +62,13 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
var cubeEyePos = camera.position - global.modelView[3].xyz;
|
||||
cubeEyePos.x *= -1;
|
||||
|
||||
var p = input.position;
|
||||
p.x *= -1;
|
||||
outPos = input.position;
|
||||
outPos.x *= -1;
|
||||
|
||||
var cubeVertPos = p * cubeTrans;
|
||||
var cubeNormal = (outNormal * cubeTrans).normalize();
|
||||
var cubeVertPos = input.position * cubeTrans;
|
||||
cubeVertPos.x *= -1;
|
||||
var cubeNormal = (input.normal * cubeTrans).normalize();
|
||||
cubeNormal.x *= -1;
|
||||
var eyeToVert = cubeVertPos - cubeEyePos;
|
||||
outReflectVec = reflect(eyeToVert, cubeNormal);
|
||||
}
|
||||
|
|
@ -73,7 +80,7 @@ class DefaultCubemapNormalMaterial extends hxsl.Shader {
|
|||
var outCol = (outShading + ambient) * diffuse;
|
||||
outCol += diffuse.a * cubeMap.get(outReflectVec);
|
||||
|
||||
var eyeVec = (outEyePos - input.position).normalize();
|
||||
var eyeVec = (outEyePos - outPos).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(outNormal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
|
|
|||
|
|
@ -33,9 +33,13 @@ class DefaultCubemapNormalNoSpecMaterial extends hxsl.Shader {
|
|||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
var inLightVec = vec3(0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var pN = input.normal;
|
||||
pN.x *= -1;
|
||||
outShading = vec4(saturate(dot(-inLightVec, pN)));
|
||||
|
|
|
|||
|
|
@ -22,10 +22,14 @@ class DefaultDiffuseMaterial extends hxsl.Shader {
|
|||
var calculatedUV:Vec2;
|
||||
var pixelColor:Vec4;
|
||||
@var var outShading:Vec4;
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
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);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var n = input.normal;
|
||||
n.x *= -1;
|
||||
outShading = vec4(saturate(dot(-inLightVec, n)));
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ class DefaultMaterial extends hxsl.Shader {
|
|||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
if (isHalfTile) {
|
||||
|
|
@ -43,9 +46,10 @@ 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) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos *= -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;
|
||||
|
|
@ -54,10 +58,10 @@ class DefaultMaterial extends hxsl.Shader {
|
|||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
var pN = input.normal;
|
||||
pN.x *= -1;
|
||||
outLightVec.w = step(-0.5, dot(pN, -inLightVec));
|
||||
outLightVec.w = isHalfTile ? step(0, dot(pN, -inLightVec)) : step(-0.5, dot(pN, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1;
|
||||
var bumpDot = isHalfTile ? saturate(dot(bumpNormal, outLightVec.xyz)) : ((dot(bumpNormal, outLightVec.xyz) + 1) * 0.5);
|
||||
// Diffuse part
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
|
|
|
|||
|
|
@ -31,14 +31,19 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
@var var outLightVec:Vec4;
|
||||
@var var outEyePos:Vec3;
|
||||
@var var outNormal:Vec3;
|
||||
@var var outPos:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
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) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
outNormal = input.normal;
|
||||
|
|
@ -50,6 +55,8 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
outShading = vec4(saturate(dot(-inLightVec, outNormal)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
outPos = input.position;
|
||||
outPos.x *= -1;
|
||||
}
|
||||
function fragment() {
|
||||
// Diffuse part
|
||||
|
|
@ -58,7 +65,7 @@ class DefaultNormalMaterial extends hxsl.Shader {
|
|||
|
||||
var outCol = (outShading + ambient) * diffuse;
|
||||
|
||||
var eyeVec = (outEyePos - input.position).normalize();
|
||||
var eyeVec = (outEyePos - outPos).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(outNormal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
|
|
|||
|
|
@ -35,11 +35,15 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
function vertex() {
|
||||
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) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
|
|
@ -53,7 +57,8 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
outLightVec.w = step(0, dot(n, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1;
|
||||
bumpNormal.y *= -1;
|
||||
var bumpDot = saturate(dot(bumpNormal, outLightVec.xyz));
|
||||
// Diffuse part
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
|
|
|
|||
|
|
@ -37,11 +37,15 @@ class RefractMaterial extends hxsl.Shader {
|
|||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function transposeMat3(m:Mat3):Mat3 {
|
||||
return mat3(vec3(m[0].x, m[1].x, m[2].x), vec3(m[0].y, m[1].y, m[2].y), vec3(m[0].z, m[1].z, m[2].z));
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
var objToTangentSpace = mat3(input.t, input.b, input.n);
|
||||
var objToTangentSpace = transposeMat3(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) * transposeMat3(mat3(global.modelView));
|
||||
inLightVec.x *= -1;
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos.x *= -1;
|
||||
// eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
|
|
@ -55,8 +59,8 @@ class RefractMaterial extends hxsl.Shader {
|
|||
outLightVec.w = step(-0.5, dot(n, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
|
||||
var bumpNormal = normalMap.get(calculatedUV * secondaryMapUvFactor).xyz * 2 - 1;
|
||||
bumpNormal.y *= -1;
|
||||
// Refract
|
||||
var distortion = 0.3;
|
||||
var off = projectedPosition;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue