mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-03-01 17:40:59 +00:00
better MBU shaders
This commit is contained in:
parent
1591ea7d72
commit
4a8063f503
4 changed files with 36 additions and 35 deletions
|
|
@ -272,9 +272,6 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
var worker = new ResourceLoaderWorker(() -> {
|
||||
var renderer = cast(this.scene.renderer, h3d.scene.fwd.Renderer);
|
||||
var gammaRes = ResourceLoader.getResource('data/shaders/gammaRamp.png', ResourceLoader.getTexture, this.textureResources);
|
||||
gammaRes.wrap = Repeat;
|
||||
// renderer.addShader(new Gamma(gammaRes, 1 / gammaRes.width));
|
||||
|
||||
for (element in mission.root.elements) {
|
||||
if (element._type != MissionElementType.Sun)
|
||||
|
|
@ -284,11 +281,15 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
var directionalColor = MisParser.parseVector4(sunElement.color);
|
||||
var ambientColor = MisParser.parseVector4(sunElement.ambient);
|
||||
ambientColor.r *= 1.18;
|
||||
ambientColor.g *= 1.06;
|
||||
ambientColor.b *= 0.95;
|
||||
if (this.game == "ultra") {
|
||||
ambientColor.r *= 1.18;
|
||||
ambientColor.g *= 1.06;
|
||||
ambientColor.b *= 0.95;
|
||||
}
|
||||
var sunDirection = MisParser.parseVector3(sunElement.direction);
|
||||
sunDirection.x = -sunDirection.x;
|
||||
// sunDirection.x = 0;
|
||||
// sunDirection.y = 0;
|
||||
// sunDirection.z = -sunDirection.z;
|
||||
var ls = cast(scene.lightSystem, h3d.scene.fwd.LightSystem);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
package shaders;
|
||||
|
||||
class Gamma extends h3d.shader.ScreenShader {
|
||||
static var SRC = {
|
||||
@param var texture:Sampler2D;
|
||||
@param var gammaMap:Sampler2D;
|
||||
@param var gammaRampInvSize:Float;
|
||||
function fragment() {
|
||||
var c = texture.get(input.uv);
|
||||
c = c * (1 - gammaRampInvSize) + 0.5 * gammaRampInvSize;
|
||||
c.x = gammaMap.get(vec2(c.x, 0)).x;
|
||||
c.y = gammaMap.get(vec2(c.y, 0)).x;
|
||||
c.z = gammaMap.get(vec2(c.z, 0)).x;
|
||||
c.a = 1;
|
||||
|
||||
output.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public function new(gammaMap, gammaRampInvSize) {
|
||||
super();
|
||||
this.gammaMap = gammaMap;
|
||||
this.gammaRampInvSize = gammaRampInvSize;
|
||||
}
|
||||
}
|
||||
|
|
@ -82,8 +82,10 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
var tanY = n.cross(tanX) * transformedTangent.w;
|
||||
transformedNormal = (nf.x * tanX + nf.y * tanY + nf.z * n).normalize();
|
||||
|
||||
var bumpDot = dirLight * lambert(transformedNormal, -dirLightDir);
|
||||
var bumpDot = /*dirLight * */ lambert(transformedNormal, -dirLightDir);
|
||||
|
||||
var shading = vec3(1, 1, 0.8980392);
|
||||
outCol.xyz *= shading;
|
||||
outCol.xyz *= bumpDot + ambientLight;
|
||||
|
||||
var eyeVec = (camera.position - transformedPosition).normalize();
|
||||
|
|
@ -92,6 +94,14 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
||||
outCol += specular * diffuse.a;
|
||||
|
||||
// Gamma correction using our regression model
|
||||
var a = 1.00759;
|
||||
var b = 1.18764;
|
||||
outCol.x = a * pow(outCol.x, b);
|
||||
outCol.y = a * pow(outCol.y, b);
|
||||
outCol.z = a * pow(outCol.z, b);
|
||||
|
||||
pixelColor = outCol;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ class PhongMaterial extends hxsl.Shader {
|
|||
transformedTangent = vec4(input.tangent * global.modelView.mat3(), input.tangent.dot(input.tangent) > 0.5 ? 1. : -1.);
|
||||
}
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = isHalfTile ? dot(normal, lightPosition) : ((dot(normal, lightPosition) + 1) * 0.5);
|
||||
if (isHalfTile) {
|
||||
return saturate(dot(normal, lightPosition));
|
||||
}
|
||||
var result = ((dot(normal, lightPosition) + 1) * 0.5);
|
||||
return result;
|
||||
}
|
||||
function vertex() {
|
||||
|
|
@ -54,9 +57,13 @@ class PhongMaterial extends hxsl.Shader {
|
|||
var tanY = n.cross(tanX) * transformedTangent.w;
|
||||
transformedNormal = (nf.x * tanX + nf.y * tanY + nf.z * n).normalize();
|
||||
|
||||
var bumpDot = dirLight * lambert(transformedNormal, -dirLightDir);
|
||||
outCol.xyz *= bumpDot + ambientLight;
|
||||
var shading = vec3(1, 1, 0.8980392);
|
||||
|
||||
var bumpDot = /*dirLight **/ lambert(transformedNormal, -dirLightDir);
|
||||
if (isHalfTile)
|
||||
outCol.xyz *= (shading * bumpDot) + ambientLight;
|
||||
else
|
||||
outCol.xyz *= shading * (bumpDot + ambientLight);
|
||||
var eyeVec = (camera.position - transformedPosition).normalize();
|
||||
var halfAng = (eyeVec - dirLightDir).normalize();
|
||||
var specValue = saturate(transformedNormal.dot(halfAng)) * fragLightW;
|
||||
|
|
@ -64,6 +71,14 @@ class PhongMaterial extends hxsl.Shader {
|
|||
|
||||
outCol += specular * diffuse.a;
|
||||
|
||||
// Gamma correction using our regression model
|
||||
// y ~ ax^b
|
||||
var a = 1.00759;
|
||||
var b = 1.18764;
|
||||
outCol.x = a * pow(outCol.x, b);
|
||||
outCol.y = a * pow(outCol.y, b);
|
||||
outCol.z = a * pow(outCol.z, b);
|
||||
|
||||
pixelColor = outCol;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue