mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 21:21:41 +00:00
mbg lighting
This commit is contained in:
parent
04c8498a28
commit
8b1615ccae
3 changed files with 81 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ import src.MarbleGame;
|
||||||
import gui.EndGameGui;
|
import gui.EndGameGui;
|
||||||
import sdl.Cursor;
|
import sdl.Cursor;
|
||||||
import src.ForceObject;
|
import src.ForceObject;
|
||||||
import h3d.scene.fwd.DirLight;
|
import shaders.DirLight;
|
||||||
import h3d.col.Bounds;
|
import h3d.col.Bounds;
|
||||||
import triggers.HelpTrigger;
|
import triggers.HelpTrigger;
|
||||||
import triggers.InBoundsTrigger;
|
import triggers.InBoundsTrigger;
|
||||||
|
|
|
||||||
41
src/shaders/DirLight.hx
Normal file
41
src/shaders/DirLight.hx
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
package shaders;
|
||||||
|
|
||||||
|
import h3d.scene.Light;
|
||||||
|
|
||||||
|
class DirLight extends Light {
|
||||||
|
var dshader:DirLightShader;
|
||||||
|
|
||||||
|
public function new(?dir:h3d.Vector, ?parent) {
|
||||||
|
dshader = new DirLightShader();
|
||||||
|
super(dshader, parent);
|
||||||
|
priority = 100;
|
||||||
|
if (dir != null)
|
||||||
|
setDirection(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
override function get_color() {
|
||||||
|
return dshader.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
override function set_color(v) {
|
||||||
|
return dshader.color = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
override function get_enableSpecular() {
|
||||||
|
return dshader.enableSpecular;
|
||||||
|
}
|
||||||
|
|
||||||
|
override function set_enableSpecular(b) {
|
||||||
|
return dshader.enableSpecular = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
override function getShadowDirection():h3d.Vector {
|
||||||
|
return absPos.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
override function emit(ctx) {
|
||||||
|
dshader.direction.load(absPos.front());
|
||||||
|
dshader.direction.normalize();
|
||||||
|
super.emit(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/shaders/DirLightShader.hx
Normal file
39
src/shaders/DirLightShader.hx
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package shaders;
|
||||||
|
|
||||||
|
class DirLightShader extends hxsl.Shader {
|
||||||
|
static var SRC = {
|
||||||
|
@param var color:Vec3;
|
||||||
|
@param var direction:Vec3;
|
||||||
|
@const var enableSpecular:Bool;
|
||||||
|
@global var camera:{
|
||||||
|
var position:Vec3;
|
||||||
|
};
|
||||||
|
var lightColor:Vec3;
|
||||||
|
var lightPixelColor:Vec3;
|
||||||
|
var transformedNormal:Vec3;
|
||||||
|
var transformedPosition:Vec3;
|
||||||
|
var specPower:Float;
|
||||||
|
var specColor:Vec3;
|
||||||
|
function calcLighting():Vec3 {
|
||||||
|
var diff = transformedNormal.dot(-direction).max(0.);
|
||||||
|
if (!enableSpecular)
|
||||||
|
return color * diff;
|
||||||
|
var r = reflect(direction, transformedNormal).normalize();
|
||||||
|
var specValue = r.dot((camera.position - transformedPosition).normalize()).max(0.);
|
||||||
|
return color * (diff + specColor * pow(specValue, specPower));
|
||||||
|
}
|
||||||
|
function vertex() {
|
||||||
|
lightColor.rgb += calcLighting();
|
||||||
|
lightColor = saturate(lightColor);
|
||||||
|
}
|
||||||
|
function fragment() {
|
||||||
|
lightPixelColor.rgb += calcLighting();
|
||||||
|
lightPixelColor = saturate(lightPixelColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
color.set(1, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue