-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathshield_2.html
95 lines (77 loc) · 3.33 KB
/
shield_2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="cache-control" content="no-cache" />
<style>
html,body{margin:0px; padding:0px; width:100%; height:100%;}
body{background-color:#404040;}
canvas{border:0px solid green;}
div{display:flex; width:100%; height:100%; align-items:center; justify-content:center;}
#lblFPS{position:absolute; top:0px; left:0px; width:40px; padding:5px 5px;
background:gray; color:white; font-weight:bold; text-align:center; font-family:arial; font-size:13px; }
</style>
<script type="module">
import gl from "./fungi/gl.js";
import Fungi from "./fungi/Fungi.js";
import Downloader from "./fungi/util/Downloader.js";
import FacedCube from "./fungi/primitives/FacedCube.js";
import Quad from "./fungi/primitives/Quad.js";
import UVSphere from "./fungi/primitives/UVSphere.js";
window.addEventListener("load",function(){
Fungi.init(); //Prepare Context and Canvas
//........................................
//Starting Loading data and Creating Threads to handle things
var dl = Downloader.start([
{type:"shader",file:"fungi/shaders/deferred/VecWColor.txt"},
{type:"shader",file:"fungi/shaders/deferred/DeferredRender.txt"},
{type:"shader",file:"fungi/shaders/deferred/Shield_Simple.txt"},
{type:"shader",file:"fungi/shaders/SingleColor.txt"},
{type:"image",name:"tex01", file:"noise001.jpg"},
]).catch(function(err){ console.log(err); });
//........................................
//Wait for all threads to be completed
Promise.all([dl]).then(values=>{ setTimeout(onInit,50); },reason =>{ console.log(reason); });
});
var shield,cube;
function onInit(){
//........................................
//Prepare the bare needed to get the scene running
Fungi.ready(onRender,6)
.setupDeferred("MatDeferredRender",onPreRender,onPostRender);
gl.setClearColor("505050");
//Set Textures on Deferred Render
gl.res.materials["MatDeferredRender"]
.setUniforms( "bufColor",Fungi.deferred.fboRender.bColor.texture );
gl.res.materials["MatShield"]
.setUniforms("bufDepth",Fungi.deferred.fboRender.bDepth.texture);
//........................................
//Add extra items to the scenen
Fungi.scene.push(cube = FacedCube("MatVecWColor").setPosition(0,0.26,0).setScale(0.5,0.5,0.5));
Fungi.scene.push(Quad(-2,-2,2,2,"ColorGray").setPosition(0,0.01,0).setDegrees(-90));
//shield = new Quad(-4,0,4,3,"MatIntersectHighlight").setOptions(false);
shield = UVSphere("MatShield").setPosition(0,0.4,0).setScale(2,2,2);
shield.updateMatrix();
//........................................
//Begin rendering the scene
Fungi.renderLoop.start();
}
function onRender(dt,ss){
cube.position.z = 1.0 * Math.sin(ss*0.0005);
Fungi.update().render(Fungi.scene);
}
function onPreRender(){ Fungi.deferred.onPreRender(); }
function onPostRender(){
Fungi.deferred.onPostRender();
//shield.position.y = 0.5 + 0.5 * Math.sin(Fungi.sinceStart * 0.0003);
//shield.updateMatrix();
gl.ctx.depthMask(false);//Disable Writing to Depth Buffer
Fungi.render.prepareNext(shield).draw();
gl.ctx.depthMask(true);//Enable it Writing to Depth Buffer
}
</script>
</head>
<body>
<div><canvas id="FungiCanvas"></canvas></div>
<span id="lblFPS">0</div>
</body>
</html>