889 added ray test

This commit is contained in:
Michael Gevlich 2025-10-22 11:35:02 +04:00
parent c55eff653c
commit 0acc441acf
7 changed files with 93 additions and 2 deletions

21
sandbox/ray/ray.html Normal file
View File

@ -0,0 +1,21 @@
<html>
<head>
<title>Draco loader sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./ray.js" type="module"></script>
<link rel="stylesheet" href="../../css/og.css" type="text/css" />
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div style="width: 100%; height: 100%">
<canvas id="frame" style="width: 100%; height: 100%"> </canvas>
</div>
</body>
</html>

54
sandbox/ray/ray.js Normal file
View File

@ -0,0 +1,54 @@
import {
control,
Entity,
Object3d,
Renderer,
Vec3,
Mat4,
RenderNode,
EntityCollection,
scene,
} from "../../lib/og.es.js";
let renderer = new Renderer("frame", {
msaa: 8,
controls: [new control.SimpleNavigation({ speed: 0.01 })],
autoActivate: true
});
class MyScene extends RenderNode {
constructor() {
super("MyScene");
}
init() {
let rayEntity = new Entity({
cartesian: new Vec3(1, 1, 1),
independentPicking: true,
ray: {
thickness: 5,
startPosition: [0, 0, 0],
endPosition: [10, 10, 10],
startColor: "red",
endColor: "green",
}
});
let collection = new EntityCollection({
entities: [rayEntity]
});
collection.addTo(this);
window.collection = collection;
this.renderer.activeCamera.set(new Vec3(-4, 11, 13), new Vec3(1, 0, 0));
this.renderer.activeCamera.update();
}
}
renderer.addNodes([
new scene.Axes(),
new MyScene()
]);

View File

@ -316,6 +316,8 @@ class RayHandler {
gl.uniform1f(shu.uOpacity, ec._fadingOpacity);
gl.uniform1i(shu.u_texAtlas, 0);
gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera!.getViewMatrix());
gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera!.getProjectionMatrix());

View File

@ -1,7 +1,10 @@
precision highp float;
uniform sampler2D u_texture;
varying vec2 v_texCoords;
varying vec4 v_rgba;
void main () {
vec4 color = texture2D(u_texture, v_texCoords);
if(color.a < 0.1)

View File

@ -1,5 +1,13 @@
precision highp float;
uniform sampler2D texAtlas;
varying vec4 v_rgba;
varying vec2 v_texCoord;
void main () {
gl_FragColor = v_rgba;
vec4 color = texture2D(texAtlas, v_texCoord);
gl_FragColor = v_rgba + color;
}

View File

@ -15,7 +15,7 @@ export function rayScreen(): Program {
texAtlas: "sampler2d"
},
attributes: {
a_texCoords: "vec2",
a_texCoord: "vec2",
a_vertices: "vec2",
a_startPosHigh: "vec3",
a_startPosLow: "vec3",

View File

@ -7,8 +7,10 @@ attribute vec3 a_endPosHigh;
attribute vec3 a_endPosLow;
attribute vec2 a_vertices;
attribute float a_thickness;
attribute vec2 a_texCoord;
varying vec4 v_rgba;
varying vec2 v_texCoord;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
@ -20,6 +22,7 @@ uniform float uOpacity;
void main() {
v_rgba = vec4(a_rgba.rgb, a_rgba.a * uOpacity);
v_texCoord = a_texCoord;
vec3 v = (a_endPosHigh - a_startPosHigh) + (a_endPosLow - a_startPosLow);