-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
156 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
precision highp float; | ||
|
||
varying vec3 v_color; | ||
|
||
void main() { | ||
|
||
gl_FragColor = vec4(v_color, 1.0); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Geometry } from "@threeify/geometry/Geometry"; | ||
import { ShaderMaterial } from "@threeify/materials/ShaderMaterial"; | ||
import { RenderingContext } from "@threeify/renderers/webgl2"; | ||
import { BufferGeometry } from "@threeify/renderers/webgl2/buffers/BufferGeometry"; | ||
import { Float32AttributeAccessor, Int32AttributeAccessor } from "lib/geometry/AttributeAccessor"; | ||
import fragmentSourceCode from "./fragment.glsl"; | ||
import vertexSourceCode from "./vertex.glsl"; | ||
|
||
// create triangle buffers. | ||
|
||
function createGeometry(): Geometry { | ||
const positions: Float32Array = new Float32Array([0, 0.5, 0.5, -0.5, -0.5, -0.5]); | ||
const colors: Float32Array = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]); | ||
const indices: Int32Array = new Int32Array([0, 1, 2]); | ||
|
||
const positionAttribute = new Float32AttributeAccessor(positions, 2); | ||
const colorsAttribute = new Float32AttributeAccessor(colors, 3); | ||
const indicesAttribute = new Int32AttributeAccessor(indices, 3); | ||
|
||
const triangleGeometry = new Geometry(); | ||
triangleGeometry.attributeAccessors.set("position", positionAttribute); | ||
triangleGeometry.attributeAccessors.set("color", colorsAttribute); | ||
triangleGeometry.indices = indicesAttribute; | ||
|
||
return triangleGeometry; | ||
} | ||
|
||
const geometry = createGeometry(); | ||
const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode); | ||
|
||
const context = new RenderingContext(); | ||
const canvasFramebuffer = context.canvasFramebuffer; | ||
document.body.appendChild(canvasFramebuffer.canvas); | ||
|
||
const bufferGeometry = BufferGeometry.FromAttributeGeometry(context, geometry); | ||
const program = context.programPool.request(material); | ||
|
||
canvasFramebuffer.renderBufferGeometry(program, {}, bufferGeometry); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
attribute vec2 position; | ||
attribute vec3 color; | ||
|
||
varying vec3 v_color; | ||
|
||
void main() { | ||
|
||
v_color = a_color; | ||
|
||
gl_Position = vec4( a_position.x, a_position.y, 0.5, 1.0 ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters