1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package h3d.shader;
- class LineShader extends hxsl.Shader {
- static var SRC = {
- @global var camera : {
- var view : Mat4;
- var proj : Mat4;
- var viewProj : Mat4;
- var projDepth : Float;
- var zNear : Float;
- var zFar : Float;
- };
- @global var global : {
- var pixelSize : Vec2;
- @perObject var modelView : Mat4;
- };
- @input var input : {
- var position : Vec3;
- var normal : Vec3;
- var uv : Vec2;
- }
- var output : {
- var position : Vec4;
- };
- var transformedNormal : Vec3;
- var transformedPosition : Vec3;
- var projectedPosition : Vec4;
- @param var lengthScale : Float;
- @param var width : Float;
- var pdir : Vec4;
- function __init__() {
- {
- var dir = input.normal * global.modelView.mat3(); // keep scale
- pdir = vec4(dir * mat3(camera.view), 1) * camera.proj;
- pdir.xy *= 1 / sqrt(pdir.x * pdir.x + pdir.y * pdir.y);
- transformedPosition += dir * input.uv.x * lengthScale;
- transformedNormal = dir.normalize();
- }
- }
- function linearize(d : Float) : Float {
- var n = camera.zNear;
- var f = camera.zFar;
- return (2 * n * f) / (f + n - (2 * d - 1) * (f - n) * camera.projDepth);
- }
- function vertex() {
- projectedPosition.xy += (pdir.yx * vec2(1,-1)) * (input.uv.y - 0.5) * linearize(projectedPosition.z / projectedPosition.w) * global.pixelSize * width;
- }
- };
- public function new( width = 1.5, lengthScale = 1. ) {
- super();
- this.width = width;
- this.lengthScale = lengthScale;
- }
- }
|