lots of shader stuff
BIN
data/textures/DefaultDiffuse.png
Normal file
|
After Width: | Height: | Size: 86 B |
BIN
data/textures/DefaultNormal.png
Normal file
|
After Width: | Height: | Size: 122 B |
BIN
data/textures/DefaultSpec.png
Normal file
|
After Width: | Height: | Size: 113 B |
BIN
data/textures/beam.normal.png
Normal file
|
After Width: | Height: | Size: 98 B |
BIN
data/textures/beam.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
data/textures/beam_side.normal.png
Normal file
|
After Width: | Height: | Size: 229 B |
BIN
data/textures/beam_side.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
data/textures/edge.normal.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
data/textures/edge_white.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
data/textures/edge_white_shadow.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
data/textures/friction_high.normal.png
Normal file
|
After Width: | Height: | Size: 149 KiB |
BIN
data/textures/friction_high.png
Normal file
|
After Width: | Height: | Size: 483 KiB |
BIN
data/textures/friction_high_shadow.png
Normal file
|
After Width: | Height: | Size: 372 KiB |
BIN
data/textures/friction_high_shadow_mbu.png
Normal file
|
After Width: | Height: | Size: 111 KiB |
BIN
data/textures/friction_low.normal.png
Normal file
|
After Width: | Height: | Size: 403 KiB |
BIN
data/textures/friction_low.png
Normal file
|
After Width: | Height: | Size: 441 KiB |
BIN
data/textures/friction_low_shadow.png
Normal file
|
After Width: | Height: | Size: 126 KiB |
BIN
data/textures/noise.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
data/textures/noise4.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
data/textures/noise_blue.jpg
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
data/textures/noise_blue_shadow.jpg
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
data/textures/noise_green.jpg
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
data/textures/noise_green_shadow.jpg
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
data/textures/noise_red.jpg
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
data/textures/noise_red_shadow.jpg
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
data/textures/noise_shadow.jpg
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
data/textures/plate.normal.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
data/textures/plate.randomize.png
Normal file
|
After Width: | Height: | Size: 2 MiB |
BIN
data/textures/stripe_caution.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
data/textures/tile_advanced.png
Normal file
|
After Width: | Height: | Size: 858 KiB |
BIN
data/textures/tile_advanced_blue.jpg
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
data/textures/tile_advanced_blue_shadow.png
Normal file
|
After Width: | Height: | Size: 150 KiB |
BIN
data/textures/tile_advanced_green.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
data/textures/tile_advanced_green_shadow.png
Normal file
|
After Width: | Height: | Size: 134 KiB |
BIN
data/textures/tile_advanced_shadow.png
Normal file
|
After Width: | Height: | Size: 593 KiB |
BIN
data/textures/tile_beginner.png
Normal file
|
After Width: | Height: | Size: 587 KiB |
BIN
data/textures/tile_beginner_blue.jpg
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
data/textures/tile_beginner_blue_shadow.png
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
data/textures/tile_beginner_red.jpg
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
data/textures/tile_beginner_red_shadow.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
data/textures/tile_beginner_shadow.png
Normal file
|
After Width: | Height: | Size: 358 KiB |
BIN
data/textures/tile_intermediate.normal.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
data/textures/tile_intermediate.png
Normal file
|
After Width: | Height: | Size: 736 KiB |
BIN
data/textures/tile_intermediate_green.jpg
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
data/textures/tile_intermediate_green_shadow.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
data/textures/tile_intermediate_red.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
data/textures/tile_intermediate_red_shadow.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
data/textures/tile_intermediate_shadow.png
Normal file
|
After Width: | Height: | Size: 389 KiB |
BIN
data/textures/tile_underside.png
Normal file
|
After Width: | Height: | Size: 136 KiB |
BIN
data/textures/wall_beginner.png
Normal file
|
After Width: | Height: | Size: 118 KiB |
|
|
@ -1 +1 @@
|
|||
by16:font%2Farial.fntaoy3:veri1y4:timei1659272757y4:hashy40:dc7f069d72e0d1b6b7edfd5b9e6af9c22f9c641cy3:outy23:tmp%2Ffont%2Farial.bfntghy21:font%2FMarkerFelt.fntaoR1i1R2i1685983312R3y40:eb239790210478413cc111da54400b3d38aba041R5y28:tmp%2Ffont%2FMarkerFelt.bfntghy27:font%2FLucida%20Console.fntaoR1i1R2i1685983312R3y40:b56483df1b8f3d8472856b51459d5ce8f3cdfa09R5y34:tmp%2Ffont%2FLucida%20Console.bfntghy16:font%2FEXPON.fntaoR1i1R2i1659272757R3y40:ba8ecd55d9475ee0f9d20c9a5189fe6a9c9ff727R5y23:tmp%2Ffont%2FEXPON.bfntghy21:font%2FDomCasualD.fntaoR1i1R2i1659272757R3y40:ea40ffbf969a51d3e653a3d09b450143a814c7eeR5y28:tmp%2Ffont%2FDomCasualD.bfntghy23:font%2FArial%20Bold.fntaoR1i1R2i1659272757R3y40:dce4a5edf92262f9ea5540d55271f8423683d064R5y30:tmp%2Ffont%2FArial%20Bold.bfntghy23:data%2Ffont%2Farial.fntaoR1i1R2i1659272757R3R4R5y37:data%2Ftmp%2Fdata%2Ffont%2Farial.bfntghy28:data%2Ffont%2FMarkerFelt.fntaoR1i1R2i1675969447R3R8R5y42:data%2Ftmp%2Fdata%2Ffont%2FMarkerFelt.bfntghy34:data%2Ffont%2FLucida%20Console.fntaoR1i1R2i1675969447R3R11R5y48:data%2Ftmp%2Fdata%2Ffont%2FLucida%20Console.bfntghy23:data%2Ffont%2FEXPON.fntaoR1i1R2i1659272757R3R14R5y37:data%2Ftmp%2Fdata%2Ffont%2FEXPON.bfntghy28:data%2Ffont%2FDomCasualD.fntaoR1i1R2i1659272757R3R17R5y42:data%2Ftmp%2Fdata%2Ffont%2FDomCasualD.bfntghy30:data%2Ffont%2FArial%20Bold.fntaoR1i1R2i1659272757R3R20R5y44:data%2Ftmp%2Fdata%2Ffont%2FArial%20Bold.bfntghh
|
||||
by27:font%2FLucida%20Console.fntaoy3:outy34:tmp%2Ffont%2FLucida%20Console.bfnty3:veri1y4:hashy40:b56483df1b8f3d8472856b51459d5ce8f3cdfa09y4:timei1685983312ghy16:font%2FEXPON.fntaoR1y23:tmp%2Ffont%2FEXPON.bfntR3i1R4y40:ba8ecd55d9475ee0f9d20c9a5189fe6a9c9ff727R6i1659272757ghy21:font%2FDomCasualD.fntaoR1y28:tmp%2Ffont%2FDomCasualD.bfntR3i1R4y40:ea40ffbf969a51d3e653a3d09b450143a814c7eeR6i1659272757ghy30:data%2Ffont%2FArial%20Bold.fntaoR1y44:data%2Ftmp%2Fdata%2Ffont%2FArial%20Bold.bfntR3i1R4y40:dce4a5edf92262f9ea5540d55271f8423683d064R6i1659272757ghy23:font%2FArial%20Bold.fntaoR1y30:tmp%2Ffont%2FArial%20Bold.bfntR3i1R4R15R6i1659272757ghy28:data%2Ffont%2FMarkerFelt.fntaoR1y42:data%2Ftmp%2Fdata%2Ffont%2FMarkerFelt.bfntR3i1R4y40:eb239790210478413cc111da54400b3d38aba041R6i1685983312ghy16:font%2Farial.fntaoR1y23:tmp%2Ffont%2Farial.bfntR3i1R4y40:dc7f069d72e0d1b6b7edfd5b9e6af9c22f9c641cR6i1659272757ghy21:font%2FMarkerFelt.fntaoR1y28:tmp%2Ffont%2FMarkerFelt.bfntR3i1R4R20R6i1685983312ghy34:data%2Ffont%2FLucida%20Console.fntaoR1y48:data%2Ftmp%2Fdata%2Ffont%2FLucida%20Console.bfntR3i1R4R5R6i1685983312ghy28:data%2Ffont%2FDomCasualD.fntaoR1y42:data%2Ftmp%2Fdata%2Ffont%2FDomCasualD.bfntR3i1R4R12R6i1659272757ghy23:data%2Ffont%2Farial.fntaoR1y37:data%2Ftmp%2Fdata%2Ffont%2Farial.bfntR3i1R4R23R6i1659272757ghy23:data%2Ffont%2FEXPON.fntaoR1y37:data%2Ftmp%2Fdata%2Ffont%2FEXPON.bfntR3i1R4R9R6i1659272757ghh
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package src;
|
||||
|
||||
import shaders.DefaultNormalMaterial;
|
||||
import shaders.DefaultMaterial;
|
||||
import h3d.scene.Mesh;
|
||||
import shaders.NormalMaterial;
|
||||
import shaders.NoiseTileMaterial;
|
||||
import shaders.DirLight;
|
||||
|
|
@ -19,10 +22,9 @@ import hxd.res.Image;
|
|||
import h3d.mat.Texture;
|
||||
import haxe.io.Path;
|
||||
import hxd.File;
|
||||
import h3d.scene.Mesh;
|
||||
import mesh.Polygon;
|
||||
import h3d.prim.UV;
|
||||
import h3d.col.Point;
|
||||
import h3d.prim.Polygon;
|
||||
import dif.math.Point2F;
|
||||
import dif.math.Point3F;
|
||||
import h3d.prim.BigPrimitive;
|
||||
|
|
@ -45,6 +47,15 @@ class DifBuilderTriangle {
|
|||
public var uv1:Point2F;
|
||||
public var uv2:Point2F;
|
||||
public var uv3:Point2F;
|
||||
public var t1:Point3F;
|
||||
public var t2:Point3F;
|
||||
public var t3:Point3F;
|
||||
public var b1:Point3F;
|
||||
public var b2:Point3F;
|
||||
public var b3:Point3F;
|
||||
public var n1:Point3F;
|
||||
public var n2:Point3F;
|
||||
public var n3:Point3F;
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
|
@ -184,45 +195,53 @@ class DifBuilder {
|
|||
},
|
||||
];
|
||||
|
||||
static function createPhongMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, normalTexture:String, shininess:Float, specularColor:Vector,
|
||||
uvScaleFactor:Float = 1) {
|
||||
static function createDefaultMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, normalTexture:String, shininess:Float, specularColor:Vector,
|
||||
uvScaleFactor:Float = 1, half:Bool = false) {
|
||||
var worker = new ResourceLoaderWorker(() -> {
|
||||
var diffuseTex = ResourceLoader.getTexture('data/interiors_mbu/${baseTexture}').resource;
|
||||
var diffuseTex = ResourceLoader.getTexture(baseTexture).resource;
|
||||
diffuseTex.wrap = Repeat;
|
||||
diffuseTex.mipMap = Nearest;
|
||||
var normalTex = ResourceLoader.getTexture('data/shaders/tex/${normalTexture}').resource;
|
||||
var normalTex = ResourceLoader.getTexture(normalTexture).resource;
|
||||
normalTex.wrap = Repeat;
|
||||
normalTex.mipMap = Nearest;
|
||||
var shader = new PhongMaterial(diffuseTex, normalTex, shininess, specularColor, MarbleGame.instance.world.ambient,
|
||||
MarbleGame.instance.world.dirLight, MarbleGame.instance.world.dirLightDir, uvScaleFactor);
|
||||
if (uvScaleFactor == 0.5)
|
||||
shader.isHalfTile = true;
|
||||
var shader = new DefaultMaterial(diffuseTex, normalTex, shininess, specularColor, uvScaleFactor, half);
|
||||
onFinish(shader);
|
||||
});
|
||||
worker.loadFile('interiors_mbu/${baseTexture}');
|
||||
worker.loadFile('shaders/tex/${normalTexture}');
|
||||
worker.loadFile(baseTexture);
|
||||
worker.loadFile(normalTexture);
|
||||
worker.run();
|
||||
}
|
||||
|
||||
static function createDefaultNormalMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, shininess:Float, specularColor:Vector,
|
||||
uvScaleFactor:Float = 1) {
|
||||
var worker = new ResourceLoaderWorker(() -> {
|
||||
var diffuseTex = ResourceLoader.getTexture(baseTexture).resource;
|
||||
diffuseTex.wrap = Repeat;
|
||||
diffuseTex.mipMap = Nearest;
|
||||
var shader = new DefaultNormalMaterial(diffuseTex, shininess, specularColor, uvScaleFactor);
|
||||
onFinish(shader);
|
||||
});
|
||||
worker.loadFile(baseTexture);
|
||||
worker.run();
|
||||
}
|
||||
|
||||
static function createNoiseTileMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, noiseSuffix:String, shininess:Float, specular:Vector) {
|
||||
var worker = new ResourceLoaderWorker(() -> {
|
||||
var diffuseTex = ResourceLoader.getTexture('data/interiors_mbu/${baseTexture}').resource;
|
||||
var diffuseTex = ResourceLoader.getTexture('data/textures/${baseTexture}').resource;
|
||||
diffuseTex.wrap = Repeat;
|
||||
diffuseTex.mipMap = Nearest;
|
||||
var normalTex = ResourceLoader.getTexture('data/shaders/tex/tile_mbu.normal.png').resource;
|
||||
var normalTex = ResourceLoader.getTexture('data/textures/tile_intermediate.normal.png').resource;
|
||||
normalTex.wrap = Repeat;
|
||||
normalTex.mipMap = Nearest;
|
||||
var noiseTex = ResourceLoader.getTexture('data/shaders/tex/noise${noiseSuffix}.jpg').resource;
|
||||
var noiseTex = ResourceLoader.getTexture('data/textures/noise${noiseSuffix}.jpg').resource;
|
||||
noiseTex.wrap = Repeat;
|
||||
noiseTex.mipMap = Nearest;
|
||||
var shader = new NoiseTileMaterial(diffuseTex, normalTex, noiseTex, shininess, specular, MarbleGame.instance.world.ambient,
|
||||
MarbleGame.instance.world.dirLight, MarbleGame.instance.world.dirLightDir, 1);
|
||||
var shader = new NoiseTileMaterial(diffuseTex, normalTex, noiseTex, shininess, specular, 1);
|
||||
onFinish(shader);
|
||||
});
|
||||
worker.loadFile('interiors_mbu/${baseTexture}');
|
||||
worker.loadFile('shaders/tex/noise${noiseSuffix}.jpg');
|
||||
worker.loadFile('shaders/tex/tile_mbu.spec.jpg');
|
||||
worker.loadFile('shaders/tex/tile_mbu.normal.png');
|
||||
worker.loadFile('textures/${baseTexture}');
|
||||
worker.loadFile('textures/noise${noiseSuffix}.jpg');
|
||||
worker.loadFile('textures/tile_intermediate.normal.png');
|
||||
worker.run();
|
||||
}
|
||||
|
||||
|
|
@ -241,59 +260,49 @@ class DifBuilder {
|
|||
}
|
||||
|
||||
static var shaderMaterialDict:Map<String, (hxsl.Shader->Void)->Void> = [
|
||||
'interiors_mbu/plate_1.jpg' => (onFinish) -> createPhongMaterial(onFinish, 'plate.randomize.png', 'plate.normal.png', 8, new Vector(1, 1, 0.8, 1),
|
||||
0.5),
|
||||
'interiors_mbu/tile_beginner.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_beginner_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_shadow', 40,
|
||||
'plate_1' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/plate.randomize.png', 'data/textures/plate.normal.png', 8,
|
||||
new Vector(1, 1, 0.8, 1), 1, true),
|
||||
'tile_beginner' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_beginner_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_shadow', 40, new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'tile_beginner_red' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_red', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_beginner_red_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_red_shadow', 40, new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'tile_beginner_blue' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_blue', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_beginner_blue_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_blue_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_beginner_red.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_red', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_beginner_red_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_red_shadow', 40,
|
||||
'tile_intermediate' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_intermediate_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_shadow', 40, new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'tile_intermediate_red' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_red', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_intermediate_red_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_red_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_beginner_blue.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_blue', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_beginner_blue_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_beginner.png', '_blue_shadow', 40,
|
||||
'tile_intermediate_green' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_green', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_intermediate_green_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_green_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_intermediate.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_intermediate_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_shadow', 40,
|
||||
'tile_advanced' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_advanced_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_shadow', 40, new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'tile_advanced_blue' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_blue', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_advanced_blue_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_blue_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_intermediate_red.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_red', 40,
|
||||
new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_intermediate_red_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_red_shadow', 40,
|
||||
'tile_advanced_green' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_green', 40, new Vector(1, 1, 1, 1)),
|
||||
'tile_advanced_green_shadow' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_green_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_intermediate_green.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_green', 40,
|
||||
new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_intermediate_green_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_intermediate.png', '_green_shadow', 40,
|
||||
'tile_underside' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_underside.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'wall_beginner' => (onFinish) -> createDefaultNormalMaterial(onFinish, 'data/textures/wall_beginner.png', 12, new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'edge_white' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/edge_white.png', 'data/textures/edge.normal.png', 50,
|
||||
new Vector(0.8, 0.8, 0.8, 1)),
|
||||
'edge_white_shadow' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/edge_white_shadow.png', 'data/textures/edge.normal.png', 50,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_advanced.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_advanced_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_advanced_blue.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_blue', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_advanced_blue_shadow.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_blue_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_advanced_green.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_green', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/tile_advanced_green_shadow.jpg' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_advanced.png', '_green_shadow', 40,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/tile_underside.png' => (onFinish) -> createNoiseTileMaterial(onFinish, 'tile_underside.png', '', 40, new Vector(1, 1, 1, 1)),
|
||||
'interiors_mbu/wall_beginner.png' => (onFinish) -> createPhongMaterial(onFinish, 'wall_beginner.png', 'wall_mbu.normal.png', 12,
|
||||
'beam' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/beam.png', 'data/textures/beam.normal.png', 12, new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'beam_side' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/beam_side.png', 'data/textures/beam_side.normal.png', 12,
|
||||
new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'interiors_mbu/edge_white.png' => (onFinish) -> createPhongMaterial(onFinish, 'edge_white.png', 'edge.normal.png', 50, new Vector(0.8, 0.8, 0.8, 1)),
|
||||
'interiors_mbu/edge_white.jpg' => (onFinish) -> createPhongMaterial(onFinish, 'edge_white.png', 'edge.normal.png', 50, new Vector(0.8, 0.8, 0.8, 1)),
|
||||
'interiors_mbu/edge_white_shadow.png' => (onFinish) -> createPhongMaterial(onFinish, 'edge_white_shadow.png', 'edge.normal.png', 50,
|
||||
new Vector(0.2, 0.2, 0.2, 0.2)),
|
||||
'interiors_mbu/beam.png' => (onFinish) -> createPhongMaterial(onFinish, 'beam.png', 'beam.normal.png', 12, new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'interiors_mbu/beam_side.png' => (onFinish) -> createPhongMaterial(onFinish, 'beam_side.png', 'beam_side.normal.png', 12,
|
||||
new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'interiors_mbu/friction_low.png' => (onFinish) -> createPhongMaterial(onFinish, 'friction_low.png', 'friction_low.normal.png', 128,
|
||||
new Vector(1, 1, 1, 0.8)),
|
||||
'interiors_mbu/friction_low.jpg' => (onFinish) -> createPhongMaterial(onFinish, 'friction_low.png', 'friction_low.normal.png', 128,
|
||||
new Vector(1, 1, 1, 0.8)),
|
||||
'interiors_mbu/friction_low_shadow.png' => (onFinish) -> createPhongMaterial(onFinish, 'friction_low_shadow.png', 'friction_low.normal.png', 128,
|
||||
// 'friction_low.png' => (onFinish) -> createPhongMaterial(onFinish, 'data/textures/friction_low.png', 'data/textures/friction_low.normal.png', 128,
|
||||
// new Vector(1, 1, 1, 0.8)),
|
||||
// 'friction_low_shadow' => (onFinish) -> createPhongMaterial(onFinish, 'data/textures/friction_low_shadow.png', 'data/textures/friction_low.normal.png',
|
||||
// 128, new Vector(0.3, 0.3, 0.35, 1)),
|
||||
'friction_high' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/friction_high.png', 'data/textures/friction_high.normal.png', 10,
|
||||
new Vector(0.3, 0.3, 0.35, 1)),
|
||||
'interiors_mbu/friction_high.png' => (onFinish) -> createPhongMaterial(onFinish, 'friction_high.png', 'friction_high.normal.png', 10,
|
||||
new Vector(0.3, 0.3, 0.35, 1)),
|
||||
'interiors_mbu/friction_high_shadow.png' => (onFinish) -> createPhongMaterial(onFinish, 'friction_high_shadow.png', 'friction_high.normal.png', 10,
|
||||
new Vector(0.15, 0.15, 0.16, 1.0)),
|
||||
'interiors_mbu/stripe_caution.png' => (onFinish) -> createPhongMaterial(onFinish, 'stripe_caution.png', 'DefaultNormal.png', 12,
|
||||
new Vector(0.8, 0.8, 0.6, 1)),
|
||||
'friction_high_shadow' => (onFinish) -> createDefaultMaterial(onFinish, 'data/textures/friction_high_shadow.png',
|
||||
'data/textures/friction_high.normal.png', 10, new Vector(0.15, 0.15, 0.16, 1.0)),
|
||||
'stripe_caution' => (onFinish) -> createDefaultNormalMaterial(onFinish, 'data/textures/stripe_caution.png', 12, new Vector(0.8, 0.8, 0.6, 1)),
|
||||
];
|
||||
|
||||
public static function loadDif(path:String, itr:InteriorObject, onFinish:Void->Void, ?so:Int = -1) {
|
||||
|
|
@ -348,9 +357,77 @@ class DifBuilder {
|
|||
colliderSurface.edgeConcavities = [];
|
||||
colliderSurface.originalIndices = [];
|
||||
colliderSurface.originalSurfaceIndex = surfaceindex;
|
||||
|
||||
var pc0 = geo.points[geo.windings[surface.windingStart + 1]];
|
||||
var pc1 = geo.points[geo.windings[surface.windingStart + 0]];
|
||||
var pc2 = geo.points[geo.windings[surface.windingStart + 2]];
|
||||
|
||||
var texPlanes = geo.texGenEQs[surface.texGenIndex];
|
||||
var tc0 = new Vector(texPlanes.planeX.x * pc0.x
|
||||
+ texPlanes.planeX.y * pc0.y
|
||||
+ texPlanes.planeX.z * pc0.z
|
||||
+ texPlanes.planeX.d,
|
||||
texPlanes.planeY.x * pc0.x
|
||||
+ texPlanes.planeY.y * pc0.y
|
||||
+ texPlanes.planeY.z * pc0.z
|
||||
+ texPlanes.planeY.d, 0, 0);
|
||||
var tc1 = new Vector(texPlanes.planeX.x * pc1.x
|
||||
+ texPlanes.planeX.y * pc1.y
|
||||
+ texPlanes.planeX.z * pc1.z
|
||||
+ texPlanes.planeX.d,
|
||||
texPlanes.planeY.x * pc1.x
|
||||
+ texPlanes.planeY.y * pc1.y
|
||||
+ texPlanes.planeY.z * pc1.z
|
||||
+ texPlanes.planeY.d, 0, 0);
|
||||
var tc2 = new Vector(texPlanes.planeX.x * pc2.x
|
||||
+ texPlanes.planeX.y * pc2.y
|
||||
+ texPlanes.planeX.z * pc2.z
|
||||
+ texPlanes.planeX.d,
|
||||
texPlanes.planeY.x * pc2.x
|
||||
+ texPlanes.planeY.y * pc2.y
|
||||
+ texPlanes.planeY.z * pc2.z
|
||||
+ texPlanes.planeY.d, 0, 0);
|
||||
|
||||
var edge1 = new Vector(pc1.x - pc0.x, tc1.x - tc0.x, tc1.y - tc0.y);
|
||||
var edge2 = new Vector(pc2.x - pc0.x, tc2.x - tc0.x, tc2.y - tc0.y);
|
||||
var cp = edge1.cross(edge2);
|
||||
var s = new Vector();
|
||||
var t = new Vector();
|
||||
if (Math.abs(cp.x) > 1e-12) {
|
||||
s.x = -cp.y / cp.x;
|
||||
t.x = -cp.z / cp.x;
|
||||
}
|
||||
edge1.set(pc1.y - pc0.y, tc1.x - tc0.x, tc1.y - tc0.y);
|
||||
edge2.set(pc2.y - pc0.y, tc2.x - tc0.x, tc2.y - tc0.y);
|
||||
cp = edge1.cross(edge2);
|
||||
if (Math.abs(cp.x) > 1e-12) {
|
||||
s.y = -cp.y / cp.x;
|
||||
t.y = -cp.z / cp.x;
|
||||
}
|
||||
edge1.set(pc1.z - pc0.z, tc1.x - tc0.x, tc1.y - tc0.y);
|
||||
edge2.set(pc2.z - pc0.z, tc2.x - tc0.x, tc2.y - tc0.y);
|
||||
cp = edge1.cross(edge2);
|
||||
if (Math.abs(cp.x) > 1e-12) {
|
||||
s.z = -cp.y / cp.x;
|
||||
t.z = -cp.z / cp.x;
|
||||
}
|
||||
s.normalize();
|
||||
t.normalize();
|
||||
var st = s.cross(t);
|
||||
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;
|
||||
|
||||
for (k in (surface.windingStart + 2)...(surface.windingStart + surface.windingCount)) {
|
||||
var p1, p2, p3;
|
||||
var i1, i2, i3;
|
||||
if ((k - (surface.windingStart + 2)) % 2 == 0) {
|
||||
i1 = k;
|
||||
i2 = k - 1;
|
||||
i3 = k - 2;
|
||||
p1 = points[geo.windings[k]];
|
||||
p2 = points[geo.windings[k - 1]];
|
||||
p3 = points[geo.windings[k - 2]];
|
||||
|
|
@ -358,6 +435,9 @@ class DifBuilder {
|
|||
colliderSurface.originalIndices.push(geo.windings[k - 1]);
|
||||
colliderSurface.originalIndices.push(geo.windings[k - 2]);
|
||||
} else {
|
||||
i1 = k - 2;
|
||||
i2 = k - 1;
|
||||
i3 = k;
|
||||
p1 = points[geo.windings[k - 2]];
|
||||
p2 = points[geo.windings[k - 1]];
|
||||
p3 = points[geo.windings[k]];
|
||||
|
|
@ -407,6 +487,37 @@ class DifBuilder {
|
|||
tri.uv1 = uv1;
|
||||
tri.uv2 = uv2;
|
||||
tri.uv3 = uv3;
|
||||
|
||||
// if (geo.normalIndices != null && geo.normalIndices.length > 0) {
|
||||
// tri.t1 = geo.normals2[geo.normalIndices[3 * i1 + 3 * surface.windingStart]];
|
||||
// tri.t1.x *= -1;
|
||||
// tri.n1 = geo.normals2[geo.normalIndices[3 * i1 + 1 + 3 * surface.windingStart]];
|
||||
// tri.n1.x *= -1;
|
||||
// tri.b1 = geo.normals2[geo.normalIndices[3 * i1 + 2 + 3 * surface.windingStart]];
|
||||
// tri.b1.x *= -1;
|
||||
// tri.t2 = geo.normals2[geo.normalIndices[3 * i2 + 3 * surface.windingStart]];
|
||||
// tri.t2.x *= -1;
|
||||
// tri.n2 = geo.normals2[geo.normalIndices[3 * i2 + 1 + 3 * surface.windingStart]];
|
||||
// tri.n2.x *= -1;
|
||||
// tri.b2 = geo.normals2[geo.normalIndices[3 * i2 + 2 + 3 * surface.windingStart]];
|
||||
// tri.b2.x *= -1;
|
||||
// tri.t3 = geo.normals2[geo.normalIndices[3 * i3 + 3 * surface.windingStart]];
|
||||
// tri.t3.x *= -1;
|
||||
// tri.n3 = geo.normals2[geo.normalIndices[3 * i3 + 1 + 3 * surface.windingStart]];
|
||||
// tri.n3.x *= -1;
|
||||
// tri.b3 = geo.normals2[geo.normalIndices[3 * i3 + 2 + 3 * surface.windingStart]];
|
||||
// tri.b3.x *= -1;
|
||||
// } else {
|
||||
tri.t1 = new Point3F(s.x, s.y, s.z);
|
||||
tri.n1 = new Point3F(st.x, st.y, st.z);
|
||||
tri.b1 = new Point3F(t.x, t.y, t.z);
|
||||
tri.t2 = new Point3F(s.x, s.y, s.z);
|
||||
tri.n2 = new Point3F(st.x, st.y, st.z);
|
||||
tri.b2 = new Point3F(t.x, t.y, t.z);
|
||||
tri.t3 = new Point3F(s.x, s.y, s.z);
|
||||
tri.n3 = new Point3F(st.x, st.y, st.z);
|
||||
tri.b3 = new Point3F(t.x, t.y, t.z);
|
||||
// }
|
||||
triangles.push(tri);
|
||||
var materialName = stripTexName(texture).toLowerCase();
|
||||
var hasMaterialInfo = materialDict.exists(materialName);
|
||||
|
|
@ -652,18 +763,10 @@ class DifBuilder {
|
|||
path = StringTools.replace(path, "data/", "");
|
||||
#end
|
||||
|
||||
if (ResourceLoader.exists(Path.directory(path) + "/" + tex + ".jpg")) {
|
||||
if (ResourceLoader.exists("data/textures/" + tex + ".jpg")) {
|
||||
return true;
|
||||
}
|
||||
if (ResourceLoader.exists(Path.directory(path) + "/" + tex + ".png")) {
|
||||
return true;
|
||||
}
|
||||
var prevDir = Path.directory(Path.directory(path));
|
||||
|
||||
if (ResourceLoader.exists(prevDir + "/" + tex + ".jpg")) {
|
||||
return true;
|
||||
}
|
||||
if (ResourceLoader.exists(prevDir + "/" + tex + ".png")) {
|
||||
if (ResourceLoader.exists("data/textures/" + tex + ".png")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -674,20 +777,11 @@ class DifBuilder {
|
|||
tex = tex.split('/')[1];
|
||||
}
|
||||
|
||||
if (ResourceLoader.exists(Path.directory(path) + "/" + tex + ".jpg")) {
|
||||
return Path.directory(path) + "/" + tex + ".jpg";
|
||||
if (ResourceLoader.exists("data/textures/" + tex + ".jpg")) {
|
||||
return "data/textures/" + tex + ".jpg";
|
||||
}
|
||||
if (ResourceLoader.exists(Path.directory(path) + "/" + tex + ".png")) {
|
||||
return Path.directory(path) + "/" + tex + ".png";
|
||||
}
|
||||
|
||||
var prevDir = Path.directory(Path.directory(path));
|
||||
|
||||
if (ResourceLoader.exists(prevDir + "/" + tex + ".jpg")) {
|
||||
return prevDir + "/" + tex + ".jpg";
|
||||
}
|
||||
if (ResourceLoader.exists(prevDir + "/" + tex + ".png")) {
|
||||
return prevDir + "/" + tex + ".png";
|
||||
if (ResourceLoader.exists("data/textures/" + tex + ".png")) {
|
||||
return "data/textures/" + tex + ".png";
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -708,6 +802,9 @@ class DifBuilder {
|
|||
var points = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
var t = [];
|
||||
var b = [];
|
||||
var n = [];
|
||||
for (tri in tris) {
|
||||
var p1 = new Point(-tri.p1.x, tri.p1.y, tri.p1.z);
|
||||
var p2 = new Point(-tri.p2.x, tri.p2.y, tri.p2.z);
|
||||
|
|
@ -727,18 +824,27 @@ 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));
|
||||
}
|
||||
var prim = new Polygon(points);
|
||||
prim.uvs = uvs;
|
||||
prim.normals = normals;
|
||||
prim.tangents = t;
|
||||
prim.bitangents = b;
|
||||
prim.texMatNormals = n;
|
||||
var material:Material;
|
||||
var texture:Texture;
|
||||
if (canFindTex(grp)) {
|
||||
texture = ResourceLoader.getTextureRealpath(tex(grp)).resource; // ResourceLoader.getTexture(tex(grp), false).resource;
|
||||
texture.wrap = Wrap.Repeat;
|
||||
texture.mipMap = Nearest;
|
||||
var exactName = StringTools.replace(texture.name, "data/", "");
|
||||
material = h3d.mat.Material.create(texture);
|
||||
var exactName = StringTools.replace(grp.toLowerCase(), "textures/", "");
|
||||
if (canFindTex(grp) || shaderMaterialDict.exists(exactName)) {
|
||||
material = h3d.mat.Material.create();
|
||||
if (shaderMaterialDict.exists(exactName)) {
|
||||
var retrievefunc = shaderMaterialDict[exactName];
|
||||
shaderWorker.addTask(fwd -> {
|
||||
|
|
@ -753,8 +859,11 @@ class DifBuilder {
|
|||
fwd();
|
||||
});
|
||||
});
|
||||
prim.addTangents();
|
||||
} else {
|
||||
texture = ResourceLoader.getTextureRealpath(tex(grp)).resource; // ResourceLoader.getTexture(tex(grp), false).resource;
|
||||
texture.wrap = Wrap.Repeat;
|
||||
texture.mipMap = Nearest;
|
||||
material.texture = texture;
|
||||
material.shadows = false;
|
||||
material.receiveShadows = true;
|
||||
}
|
||||
|
|
|
|||
139
src/DtsObject.hx
|
|
@ -19,7 +19,7 @@ import hxd.FloatBuffer;
|
|||
import src.DynamicPolygon;
|
||||
import dts.Sequence;
|
||||
import h3d.scene.Mesh;
|
||||
import h3d.prim.Polygon;
|
||||
import mesh.Polygon;
|
||||
import h3d.prim.UV;
|
||||
import h3d.Vector;
|
||||
import h3d.Quat;
|
||||
|
|
@ -61,6 +61,9 @@ typedef GraphNode = {
|
|||
typedef MaterialGeometry = {
|
||||
var vertices:Array<Vector>;
|
||||
var normals:Array<Vector>;
|
||||
var tangents:Array<Vector>;
|
||||
var bitangents:Array<Vector>;
|
||||
var texNormals:Array<Vector>;
|
||||
var uvs:Array<UV>;
|
||||
var indices:Array<Int>;
|
||||
}
|
||||
|
|
@ -198,6 +201,9 @@ class DtsObject extends GameObject {
|
|||
var poly = new Polygon(geometry[k].vertices.map(x -> x.toPoint()));
|
||||
poly.normals = geometry[k].normals.map(x -> x.toPoint());
|
||||
poly.uvs = geometry[k].uvs;
|
||||
poly.tangents = geometry[k].tangents.map(x -> x.toPoint());
|
||||
poly.bitangents = geometry[k].bitangents.map(x -> x.toPoint());
|
||||
poly.texMatNormals = geometry[k].texNormals.map(x -> x.toPoint());
|
||||
|
||||
var obj = new Mesh(poly, materials[k], this.graphNodes[i]);
|
||||
}
|
||||
|
|
@ -609,17 +615,133 @@ class DtsObject extends GameObject {
|
|||
vertices: [],
|
||||
normals: [],
|
||||
uvs: [],
|
||||
indices: []
|
||||
indices: [],
|
||||
tangents: [],
|
||||
bitangents: [],
|
||||
texNormals: []
|
||||
});
|
||||
if (materialGeometry.length == 0 && dtsMesh.primitives.length > 0) {
|
||||
materialGeometry.push({
|
||||
vertices: [],
|
||||
normals: [],
|
||||
uvs: [],
|
||||
indices: []
|
||||
indices: [],
|
||||
tangents: [],
|
||||
bitangents: [],
|
||||
texNormals: []
|
||||
});
|
||||
}
|
||||
|
||||
function createTextureSpaceMatrix(i0:Int, i1:Int, i2:Int) {
|
||||
var t0 = new Vector();
|
||||
var t1 = new Vector();
|
||||
var t2 = new Vector();
|
||||
var b0 = new Vector();
|
||||
var b1 = new Vector();
|
||||
var b2 = new Vector();
|
||||
var edge1 = new Vector();
|
||||
var edge2 = new Vector();
|
||||
var cp = new Vector();
|
||||
edge1.set(vertices[i1].x - vertices[i0].x, vertices[i1].y - vertices[i0].y, vertices[i1].z - vertices[i0].z);
|
||||
edge2.set(vertices[i2].x - vertices[i0].x, vertices[i2].y - vertices[i0].y, vertices[i2].z - vertices[i0].z);
|
||||
var fVar1 = vertices[i1].x - vertices[i0].x;
|
||||
var fVar2 = vertices[i2].x - vertices[i0].x;
|
||||
var fVar4 = dtsMesh.uv[i1].x - dtsMesh.uv[i0].x;
|
||||
var fVar5 = dtsMesh.uv[i2].x - dtsMesh.uv[i0].x;
|
||||
var fVar6 = dtsMesh.uv[i1].y - dtsMesh.uv[i0].y;
|
||||
var fVar7 = dtsMesh.uv[i2].y - dtsMesh.uv[i0].y;
|
||||
var fVar3 = fVar7 * fVar4 - fVar5 * fVar6;
|
||||
if (1e-12 < Math.abs(fVar3)) {
|
||||
fVar3 = 1.0 / fVar3;
|
||||
fVar4 = -(fVar3 * (fVar5 * fVar1 - fVar4 * fVar2));
|
||||
fVar1 = -(fVar3 * (fVar6 * fVar2 - fVar7 * fVar1));
|
||||
t0.x = fVar1;
|
||||
t1.x = fVar1;
|
||||
t2.x = fVar1;
|
||||
b0.x = fVar4;
|
||||
b1.x = fVar4;
|
||||
b2.x = fVar4;
|
||||
}
|
||||
fVar1 = dtsMesh.uv[i1].x - dtsMesh.uv[i0].x;
|
||||
fVar2 = dtsMesh.uv[i2].x - dtsMesh.uv[i0].x;
|
||||
fVar3 = dtsMesh.uv[i1].y - dtsMesh.uv[i0].y;
|
||||
fVar6 = vertices[i1].y - vertices[i0].y;
|
||||
fVar4 = dtsMesh.uv[i2].y - dtsMesh.uv[i0].y;
|
||||
fVar7 = vertices[i2].y - vertices[i0].y;
|
||||
fVar5 = fVar4 * fVar1 - fVar2 * fVar3;
|
||||
if (1e-12 < Math.abs(fVar5)) {
|
||||
fVar5 = 1.0 / fVar5;
|
||||
fVar3 = -(fVar5 * (fVar3 * fVar7 - fVar4 * fVar6));
|
||||
fVar1 = -(fVar5 * (fVar2 * fVar6 - fVar1 * fVar7));
|
||||
b0.y = fVar1;
|
||||
b1.y = fVar1;
|
||||
b2.y = fVar1;
|
||||
t0.y = fVar3;
|
||||
t1.y = fVar3;
|
||||
t2.y = fVar3;
|
||||
}
|
||||
fVar1 = dtsMesh.uv[i1].x - dtsMesh.uv[i0].x;
|
||||
fVar2 = dtsMesh.uv[i2].x - dtsMesh.uv[i0].x;
|
||||
fVar3 = dtsMesh.uv[i1].y - dtsMesh.uv[i0].y;
|
||||
fVar5 = vertices[i1].z - vertices[i0].z;
|
||||
fVar4 = dtsMesh.uv[i2].y - dtsMesh.uv[i0].y;
|
||||
fVar6 = vertices[i2].z - vertices[i0].z;
|
||||
fVar7 = fVar4 * fVar1 - fVar2 * fVar3;
|
||||
if (1e-12 < Math.abs(fVar7)) {
|
||||
fVar7 = 1.0 / fVar7;
|
||||
fVar3 = -(fVar7 * (fVar3 * fVar6 - fVar4 * fVar5));
|
||||
fVar1 = -(fVar7 * (fVar2 * fVar5 - fVar1 * fVar6));
|
||||
b0.z = fVar1;
|
||||
b1.z = fVar1;
|
||||
b2.z = fVar1;
|
||||
t0.z = fVar3;
|
||||
t1.z = fVar3;
|
||||
t2.z = fVar3;
|
||||
}
|
||||
|
||||
// v0
|
||||
t0.normalize();
|
||||
b0.normalized();
|
||||
var n0 = t0.cross(b0);
|
||||
if (n0.dot(vertexNormals[i0]) < 0.0) {
|
||||
n0.scale(-1);
|
||||
}
|
||||
|
||||
// v1
|
||||
t1.normalize();
|
||||
b1.normalized();
|
||||
var n1 = t1.cross(b1);
|
||||
if (n1.dot(vertexNormals[i1]) < 0.0) {
|
||||
n1.scale(-1);
|
||||
}
|
||||
|
||||
// v2
|
||||
t2.normalize();
|
||||
b2.normalized();
|
||||
var n2 = t2.cross(b2);
|
||||
if (n2.dot(vertexNormals[i2]) < 0.0) {
|
||||
n2.scale(-1);
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
tangent: t0,
|
||||
bitangent: b0,
|
||||
normal: n0
|
||||
},
|
||||
{
|
||||
tangent: t1,
|
||||
bitangent: b1,
|
||||
normal: n1
|
||||
},
|
||||
{
|
||||
tangent: t2,
|
||||
bitangent: b2,
|
||||
normal: n2
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
var ab = new Vector();
|
||||
var ac = new Vector();
|
||||
function addTriangleFromIndices(i1:Int, i2:Int, i3:Int, materialIndex:Int) {
|
||||
|
|
@ -655,6 +777,17 @@ class DtsObject extends GameObject {
|
|||
geometrydata.normals.push(new Vector(normal.x, normal.y, normal.z));
|
||||
}
|
||||
|
||||
var tbn = createTextureSpaceMatrix(i1, i2, i3);
|
||||
geometrydata.tangents.push(tbn[0].tangent);
|
||||
geometrydata.tangents.push(tbn[1].tangent);
|
||||
geometrydata.tangents.push(tbn[2].tangent);
|
||||
geometrydata.bitangents.push(tbn[0].bitangent);
|
||||
geometrydata.bitangents.push(tbn[1].bitangent);
|
||||
geometrydata.bitangents.push(tbn[2].bitangent);
|
||||
geometrydata.texNormals.push(tbn[0].normal);
|
||||
geometrydata.texNormals.push(tbn[1].normal);
|
||||
geometrydata.texNormals.push(tbn[2].normal);
|
||||
|
||||
geometrydata.indices.push(i1);
|
||||
geometrydata.indices.push(i2);
|
||||
geometrydata.indices.push(i3);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import h3d.scene.Object;
|
|||
class InteriorObject extends GameObject {
|
||||
public var collider:CollisionEntity;
|
||||
public var interiorFile:String;
|
||||
public var useInstancing = true;
|
||||
public var useInstancing = false;
|
||||
public var level:MarbleWorld;
|
||||
|
||||
public function new() {
|
||||
|
|
|
|||
|
|
@ -335,13 +335,6 @@ class Marble extends GameObject {
|
|||
mat.mainPass.addShader(new MarbleReflection(this.cubemapRenderer.cubemap));
|
||||
} else {
|
||||
// Generate tangents for next shaders, only for Ultra
|
||||
for (node in marbleDts.graphNodes) {
|
||||
for (ch in node.children) {
|
||||
var chmesh = cast(ch, Mesh);
|
||||
var chpoly = cast(chmesh.primitive, h3d.prim.Polygon);
|
||||
chpoly.addTangents();
|
||||
}
|
||||
}
|
||||
|
||||
mat.mainPass.removeShader(mat.textureShader);
|
||||
|
||||
|
|
|
|||
311
src/mesh/Polygon.hx
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
package mesh;
|
||||
|
||||
import h3d.prim.*;
|
||||
import h3d.col.Point;
|
||||
|
||||
class Polygon extends MeshPrimitive {
|
||||
public var points:Array<Point>;
|
||||
public var normals:Array<Point>;
|
||||
public var tangents:Array<Point>;
|
||||
public var bitangents:Array<Point>;
|
||||
public var texMatNormals:Array<Point>;
|
||||
public var uvs:Array<UV>;
|
||||
public var idx:hxd.IndexBuffer;
|
||||
|
||||
var scaled = 1.;
|
||||
var translatedX = 0.;
|
||||
var translatedY = 0.;
|
||||
var translatedZ = 0.;
|
||||
|
||||
public function new(points, ?idx) {
|
||||
this.points = points;
|
||||
this.idx = idx;
|
||||
}
|
||||
|
||||
override function getBounds() {
|
||||
var b = new h3d.col.Bounds();
|
||||
for (p in points)
|
||||
b.addPoint(p);
|
||||
return b;
|
||||
}
|
||||
|
||||
override function alloc(engine:h3d.Engine) {
|
||||
dispose();
|
||||
|
||||
var size = 3;
|
||||
var names = ["position"];
|
||||
var positions = [0];
|
||||
if (normals != null) {
|
||||
names.push("normal");
|
||||
positions.push(size);
|
||||
size += 3;
|
||||
}
|
||||
if (tangents != null) {
|
||||
names.push("t");
|
||||
positions.push(size);
|
||||
size += 3;
|
||||
}
|
||||
if (bitangents != null) {
|
||||
names.push("b");
|
||||
positions.push(size);
|
||||
size += 3;
|
||||
}
|
||||
if (texMatNormals != null) {
|
||||
names.push("n");
|
||||
positions.push(size);
|
||||
size += 3;
|
||||
}
|
||||
if (uvs != null) {
|
||||
names.push("uv");
|
||||
positions.push(size);
|
||||
size += 2;
|
||||
}
|
||||
|
||||
var buf = new hxd.FloatBuffer();
|
||||
for (k in 0...points.length) {
|
||||
var p = points[k];
|
||||
buf.push(p.x);
|
||||
buf.push(p.y);
|
||||
buf.push(p.z);
|
||||
if (normals != null) {
|
||||
var n = normals[k];
|
||||
buf.push(n.x);
|
||||
buf.push(n.y);
|
||||
buf.push(n.z);
|
||||
}
|
||||
if (tangents != null) {
|
||||
var t = tangents[k];
|
||||
buf.push(t.x);
|
||||
buf.push(t.y);
|
||||
buf.push(t.z);
|
||||
}
|
||||
if (bitangents != null) {
|
||||
var t = bitangents[k];
|
||||
buf.push(t.x);
|
||||
buf.push(t.y);
|
||||
buf.push(t.z);
|
||||
}
|
||||
if (texMatNormals != null) {
|
||||
var t = texMatNormals[k];
|
||||
buf.push(t.x);
|
||||
buf.push(t.y);
|
||||
buf.push(t.z);
|
||||
}
|
||||
if (uvs != null) {
|
||||
var t = uvs[k];
|
||||
buf.push(t.u);
|
||||
buf.push(t.v);
|
||||
}
|
||||
}
|
||||
var flags:Array<h3d.Buffer.BufferFlag> = [];
|
||||
if (idx == null)
|
||||
flags.push(Triangles);
|
||||
if (normals == null || tangents != null)
|
||||
flags.push(RawFormat);
|
||||
buffer = h3d.Buffer.ofFloats(buf, size, flags);
|
||||
|
||||
for (i in 0...names.length)
|
||||
addBuffer(names[i], buffer, positions[i]);
|
||||
|
||||
if (idx != null)
|
||||
indexes = h3d.Indexes.alloc(idx);
|
||||
}
|
||||
|
||||
public function unindex() {
|
||||
if (idx != null && points.length != idx.length) {
|
||||
var p = [];
|
||||
var used = [];
|
||||
for (i in 0...idx.length)
|
||||
p.push(points[idx[i]].clone());
|
||||
if (normals != null) {
|
||||
var n = [];
|
||||
for (i in 0...idx.length)
|
||||
n.push(normals[idx[i]].clone());
|
||||
normals = n;
|
||||
}
|
||||
if (tangents != null) {
|
||||
var t = [];
|
||||
for (i in 0...idx.length)
|
||||
t.push(tangents[idx[i]].clone());
|
||||
tangents = t;
|
||||
}
|
||||
if (uvs != null) {
|
||||
var t = [];
|
||||
for (i in 0...idx.length)
|
||||
t.push(uvs[idx[i]].clone());
|
||||
uvs = t;
|
||||
}
|
||||
points = p;
|
||||
idx = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function translate(dx, dy, dz) {
|
||||
translatedX += dx;
|
||||
translatedY += dy;
|
||||
translatedZ += dz;
|
||||
for (p in points) {
|
||||
p.x += dx;
|
||||
p.y += dy;
|
||||
p.z += dz;
|
||||
}
|
||||
}
|
||||
|
||||
public function scale(s:Float) {
|
||||
scaled *= s;
|
||||
for (p in points) {
|
||||
p.x *= s;
|
||||
p.y *= s;
|
||||
p.z *= s;
|
||||
}
|
||||
}
|
||||
|
||||
public function addNormals() {
|
||||
// make per-point normal
|
||||
normals = new Array();
|
||||
for (i in 0...points.length)
|
||||
normals[i] = new Point();
|
||||
var pos = 0;
|
||||
for (i in 0...triCount()) {
|
||||
var i0, i1, i2;
|
||||
if (idx == null) {
|
||||
i0 = pos++;
|
||||
i1 = pos++;
|
||||
i2 = pos++;
|
||||
} else {
|
||||
i0 = idx[pos++];
|
||||
i1 = idx[pos++];
|
||||
i2 = idx[pos++];
|
||||
}
|
||||
var p0 = points[i0];
|
||||
var p1 = points[i1];
|
||||
var p2 = points[i2];
|
||||
// this is the per-face normal
|
||||
var n = p1.sub(p0).cross(p2.sub(p0));
|
||||
// add it to each point
|
||||
normals[i0].x += n.x;
|
||||
normals[i0].y += n.y;
|
||||
normals[i0].z += n.z;
|
||||
normals[i1].x += n.x;
|
||||
normals[i1].y += n.y;
|
||||
normals[i1].z += n.z;
|
||||
normals[i2].x += n.x;
|
||||
normals[i2].y += n.y;
|
||||
normals[i2].z += n.z;
|
||||
}
|
||||
// normalize all normals
|
||||
for (n in normals)
|
||||
n.normalize();
|
||||
}
|
||||
|
||||
public function addTangents() {
|
||||
if (normals == null)
|
||||
addNormals();
|
||||
if (uvs == null)
|
||||
addUVs();
|
||||
tangents = [];
|
||||
for (i in 0...points.length)
|
||||
tangents[i] = new Point();
|
||||
var pos = 0;
|
||||
for (i in 0...triCount()) {
|
||||
var i0, i1, i2;
|
||||
if (idx == null) {
|
||||
i0 = pos++;
|
||||
i1 = pos++;
|
||||
i2 = pos++;
|
||||
} else {
|
||||
i0 = idx[pos++];
|
||||
i1 = idx[pos++];
|
||||
i2 = idx[pos++];
|
||||
}
|
||||
var p0 = points[i0];
|
||||
var p1 = points[i1];
|
||||
var p2 = points[i2];
|
||||
var uv0 = uvs[i0];
|
||||
var uv1 = uvs[i1];
|
||||
var uv2 = uvs[i2];
|
||||
var n = normals[i0];
|
||||
|
||||
var k0 = p1.sub(p0);
|
||||
var k1 = p2.sub(p0);
|
||||
k0.scale(uv2.v - uv0.v);
|
||||
k1.scale(uv1.v - uv0.v);
|
||||
var t = k0.sub(k1);
|
||||
var b = n.cross(t);
|
||||
b.normalize();
|
||||
t = b.cross(n);
|
||||
t.normalize();
|
||||
|
||||
// add it to each point
|
||||
tangents[i0].x += t.x;
|
||||
tangents[i0].y += t.y;
|
||||
tangents[i0].z += t.z;
|
||||
tangents[i1].x += t.x;
|
||||
tangents[i1].y += t.y;
|
||||
tangents[i1].z += t.z;
|
||||
tangents[i2].x += t.x;
|
||||
tangents[i2].y += t.y;
|
||||
tangents[i2].z += t.z;
|
||||
}
|
||||
for (t in tangents)
|
||||
t.normalize();
|
||||
}
|
||||
|
||||
public function addUVs() {
|
||||
uvs = [];
|
||||
for (i in 0...points.length)
|
||||
uvs[i] = new UV(points[i].x, points[i].y);
|
||||
}
|
||||
|
||||
public function uvScale(su:Float, sv:Float) {
|
||||
if (uvs == null)
|
||||
throw "Missing UVs";
|
||||
var m = new Map<UV, Bool>();
|
||||
for (t in uvs) {
|
||||
if (m.exists(t))
|
||||
continue;
|
||||
m.set(t, true);
|
||||
t.u *= su;
|
||||
t.v *= sv;
|
||||
}
|
||||
}
|
||||
|
||||
override function triCount() {
|
||||
var n = super.triCount();
|
||||
if (n != 0)
|
||||
return n;
|
||||
return Std.int((idx == null ? points.length : idx.length) / 3);
|
||||
}
|
||||
|
||||
override function vertexCount() {
|
||||
return points.length;
|
||||
}
|
||||
|
||||
override function getCollider():h3d.col.Collider {
|
||||
var vertexes = new haxe.ds.Vector<hxd.impl.Float32>(points.length * 3);
|
||||
var indexes = new haxe.ds.Vector<Int>(idx.length);
|
||||
var vid = 0;
|
||||
for (p in points) {
|
||||
vertexes[vid++] = p.x;
|
||||
vertexes[vid++] = p.y;
|
||||
vertexes[vid++] = p.z;
|
||||
}
|
||||
for (i in 0...idx.length)
|
||||
indexes[i] = idx[i];
|
||||
var poly = new h3d.col.Polygon();
|
||||
poly.addBuffers(vertexes, indexes);
|
||||
return poly;
|
||||
}
|
||||
|
||||
override function render(engine:h3d.Engine) {
|
||||
if (buffer == null || buffer.isDisposed())
|
||||
alloc(engine);
|
||||
var bufs = getBuffers(engine);
|
||||
if (indexes != null)
|
||||
engine.renderMultiBuffers(bufs, indexes);
|
||||
else if (buffer.flags.has(Quads))
|
||||
engine.renderMultiBuffers(bufs, engine.mem.quadIndexes, 0, triCount());
|
||||
else
|
||||
engine.renderMultiBuffers(bufs, engine.mem.triIndexes, 0, triCount());
|
||||
}
|
||||
}
|
||||
95
src/shaders/DefaultMaterial.hx
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package shaders;
|
||||
|
||||
class DefaultMaterial extends hxsl.Shader {
|
||||
static var SRC = {
|
||||
@param var diffuseMap:Sampler2D;
|
||||
@param var specularColor:Vec4;
|
||||
@param var normalMap:Sampler2D;
|
||||
@param var shininess:Float;
|
||||
@param var secondaryMapUvFactor:Float;
|
||||
@global var camera:{
|
||||
var position:Vec3;
|
||||
@var var dir:Vec3;
|
||||
};
|
||||
@global var global:{
|
||||
@perObject var modelView:Mat4;
|
||||
@perObject var modelViewInverse:Mat4;
|
||||
};
|
||||
@input var input:{
|
||||
var position:Vec3;
|
||||
var normal:Vec3;
|
||||
var uv:Vec2;
|
||||
var t:Vec3;
|
||||
var b:Vec3;
|
||||
var n:Vec3;
|
||||
};
|
||||
var calculatedUV:Vec2;
|
||||
var pixelColor:Vec4;
|
||||
var specColor:Vec3;
|
||||
var specPower:Float;
|
||||
@var var outLightVec:Vec4;
|
||||
@var var outPos:Vec3;
|
||||
@var var outEyePos:Vec3;
|
||||
@const var isHalfTile:Bool;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
if (isHalfTile) {
|
||||
calculatedUV *= 0.5;
|
||||
}
|
||||
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 eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(-0.5, dot(input.normal, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var bumpDot = isHalfTile ? saturate(dot(bumpNormal, outLightVec.xyz)) : ((dot(bumpNormal, outLightVec.xyz) + 1) * 0.5);
|
||||
// Diffuse part
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
var ambient = vec4(0.472, 0.424, 0.475, 1.00);
|
||||
|
||||
var outCol = diffuse;
|
||||
var shading = vec4(1.08, 1.03, 0.90, 1);
|
||||
if (isHalfTile) {
|
||||
outCol = shading * diffuse * (bumpDot + ambient);
|
||||
} else {
|
||||
outCol *= (shading * bumpDot) + ambient;
|
||||
}
|
||||
|
||||
var eyeVec = (outEyePos - outPos).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(bumpNormal.dot(halfAng)) * outLightVec.w;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function new(diffuse, normal, shininess, specularColor, secondaryMapUvFactor, isHalfTile = false) {
|
||||
super();
|
||||
this.diffuseMap = diffuse;
|
||||
this.normalMap = normal;
|
||||
this.shininess = shininess;
|
||||
this.specularColor = specularColor;
|
||||
this.secondaryMapUvFactor = secondaryMapUvFactor;
|
||||
this.isHalfTile = isHalfTile;
|
||||
}
|
||||
}
|
||||
82
src/shaders/DefaultNormalMaterial.hx
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package shaders;
|
||||
|
||||
class DefaultNormalMaterial extends hxsl.Shader {
|
||||
static var SRC = {
|
||||
@param var diffuseMap:Sampler2D;
|
||||
@param var specularColor:Vec4;
|
||||
@param var shininess:Float;
|
||||
@param var secondaryMapUvFactor:Float;
|
||||
@global var camera:{
|
||||
var position:Vec3;
|
||||
@var var dir:Vec3;
|
||||
};
|
||||
@global var global:{
|
||||
@perObject var modelView:Mat4;
|
||||
@perObject var modelViewInverse:Mat4;
|
||||
};
|
||||
@input var input:{
|
||||
var position:Vec3;
|
||||
var normal:Vec3;
|
||||
var uv:Vec2;
|
||||
var t:Vec3;
|
||||
var b:Vec3;
|
||||
var n:Vec3;
|
||||
};
|
||||
var calculatedUV:Vec2;
|
||||
var pixelColor:Vec4;
|
||||
var specColor:Vec3;
|
||||
var specPower:Float;
|
||||
@var var outShading:Vec4;
|
||||
@var var outLightVec:Vec4;
|
||||
@var var outEyePos:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
outLightVec = vec4(0);
|
||||
var inLightVec = vec3(-0.5732, 0.27536, -0.77176) * mat3(global.modelViewInverse);
|
||||
var eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
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));
|
||||
outEyePos = eyePos;
|
||||
outShading = vec4(saturate(dot(-inLightVec, input.normal)));
|
||||
outShading.w = 1;
|
||||
outShading *= vec4(1.08, 1.03, 0.90, 1);
|
||||
}
|
||||
function fragment() {
|
||||
// Diffuse part
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
var ambient = vec4(0.472, 0.424, 0.475, 1.00);
|
||||
|
||||
var outCol = (outShading + ambient) * diffuse;
|
||||
|
||||
var eyeVec = (outEyePos - input.position).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(input.normal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
||||
outCol.a = 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function new(diffuse, shininess, specularColor, secondaryMapUvFactor) {
|
||||
super();
|
||||
this.diffuseMap = diffuse;
|
||||
this.shininess = shininess;
|
||||
this.specularColor = specularColor;
|
||||
this.secondaryMapUvFactor = secondaryMapUvFactor;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,9 +7,6 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
@param var normalMap:Sampler2D;
|
||||
@param var noiseMap:Sampler2D;
|
||||
@param var shininess:Float;
|
||||
@param var ambientLight:Vec3;
|
||||
@param var dirLight:Vec3;
|
||||
@param var dirLightDir:Vec3;
|
||||
@param var secondaryMapUvFactor:Float;
|
||||
@global var camera:{
|
||||
var position:Vec3;
|
||||
|
|
@ -20,32 +17,42 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
@perObject var modelViewInverse:Mat4;
|
||||
};
|
||||
@input var input:{
|
||||
var position:Vec3;
|
||||
var normal:Vec3;
|
||||
var tangent:Vec3;
|
||||
var uv:Vec2;
|
||||
var t:Vec3;
|
||||
var b:Vec3;
|
||||
var n:Vec3;
|
||||
};
|
||||
var calculatedUV:Vec2;
|
||||
var pixelColor:Vec4;
|
||||
var specColor:Vec3;
|
||||
var specPower:Float;
|
||||
var transformedPosition:Vec3;
|
||||
var transformedNormal:Vec3;
|
||||
@var var transformedTangent:Vec4;
|
||||
@var var fragLightW:Float;
|
||||
function __init__vertex() {
|
||||
transformedTangent = vec4(input.tangent * global.modelView.mat3(), input.tangent.dot(input.tangent) > 0.5 ? 1. : -1.);
|
||||
}
|
||||
@var var outLightVec:Vec4;
|
||||
@var var outPos:Vec3;
|
||||
@var var outEyePos:Vec3;
|
||||
function lambert(normal:Vec3, lightPosition:Vec3):Float {
|
||||
var result = dot(normal, lightPosition);
|
||||
return saturate(result);
|
||||
}
|
||||
function vertex() {
|
||||
calculatedUV = input.uv;
|
||||
fragLightW = step(0, dot(dirLight, input.normal));
|
||||
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 eyePos = camera.position * mat3x4(global.modelViewInverse);
|
||||
eyePos /= vec3(global.modelViewInverse[0].x, global.modelViewInverse[1].y, global.modelViewInverse[2].z);
|
||||
outLightVec.xyz = -inLightVec * objToTangentSpace;
|
||||
outPos = (input.position / 100.0) * objToTangentSpace;
|
||||
outEyePos = (eyePos / 100.0) * objToTangentSpace;
|
||||
outLightVec.w = step(0, dot(input.normal, -inLightVec));
|
||||
}
|
||||
function fragment() {
|
||||
var bumpNormal = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var bumpDot = saturate(dot(bumpNormal, outLightVec.xyz));
|
||||
// Diffuse part
|
||||
var diffuse = diffuseMap.get(calculatedUV);
|
||||
var ambient = vec4(0.472, 0.424, 0.475, 1.00);
|
||||
// noise
|
||||
|
||||
var noiseIndex:Vec2;
|
||||
|
|
@ -75,22 +82,13 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
var noiseAdd = finalNoiseCol * diffuse.a;
|
||||
|
||||
var outCol = diffuse + noiseAdd;
|
||||
|
||||
var n = transformedNormal;
|
||||
var nf = unpackNormal(normalMap.get(calculatedUV * secondaryMapUvFactor));
|
||||
var tanX = transformedTangent.xyz.normalize();
|
||||
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 shading = vec3(1, 1, 0.8980392);
|
||||
var shading = vec3(1.08, 1.03, 0.90);
|
||||
outCol.xyz *= shading;
|
||||
outCol.xyz *= bumpDot + ambientLight;
|
||||
outCol *= bumpDot + ambient;
|
||||
|
||||
var eyeVec = (camera.position - transformedPosition).normalize();
|
||||
var halfAng = (eyeVec - dirLightDir).normalize();
|
||||
var specValue = saturate(transformedNormal.dot(halfAng)) * fragLightW;
|
||||
var eyeVec = (outEyePos - outPos).normalize();
|
||||
var halfAng = (eyeVec + outLightVec.xyz).normalize();
|
||||
var specValue = saturate(bumpNormal.dot(halfAng)) * outLightVec.w;
|
||||
var specular = specularColor * pow(specValue, shininess);
|
||||
|
||||
outCol += specular * diffuse.a;
|
||||
|
|
@ -106,16 +104,13 @@ class NoiseTileMaterial extends hxsl.Shader {
|
|||
}
|
||||
}
|
||||
|
||||
public function new(diffuse, normal, noise, shininess, specularColor, ambientLight, dirLight, dirLightDir, secondaryMapUvFactor) {
|
||||
public function new(diffuse, normal, noise, shininess, specularColor, secondaryMapUvFactor) {
|
||||
super();
|
||||
this.diffuseMap = diffuse;
|
||||
this.normalMap = normal;
|
||||
this.noiseMap = noise;
|
||||
this.shininess = shininess;
|
||||
this.specularColor = specularColor;
|
||||
this.ambientLight = ambientLight.clone();
|
||||
this.dirLight = dirLight.clone();
|
||||
this.dirLightDir = dirLightDir.clone();
|
||||
this.secondaryMapUvFactor = secondaryMapUvFactor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||