Skip to content

Commit

Permalink
#154 描画処理を改修
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Dec 13, 2024
1 parent ef1c6ff commit f61ef62
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
42 changes: 21 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
<script>
window.addEventListener("DOMContentLoaded", async () =>
{
// next2d.load("develop");
const { Sprite, Shape } = next2d.display;
const root = await next2d.createRootMovieClip(480, 480);
const shape = root.addChild(new Shape());
shape.x = 75;
shape.y = 75;
shape
.graphics
.beginFill(0x0000ff)
.moveTo(0, 0).curveTo(50, -25, 100, 0).curveTo(125, 50, 100, 100).lineTo(0, 100).curveTo(20, 50, 0, 0)
// .endFill()
// non-zero
// .beginFill(0x00ff00)
.moveTo(75, 75).curveTo(170, 30, 75, 50).curveTo(50, 10, 50, 50).curveTo(95, 25+35/2, 50, 75).lineTo(75, 75)
// .endFill()
// even-odd
// .beginFill(0xff0000)
// .moveTo(25, 25).lineTo(60, 25).lineTo(60, 60).lineTo(25, 60).curveTo(-55, 25+35/2, 25, 25)
// .beginFill(0x00ff00)
// .moveTo(35, 35).lineTo(70, 35).curveTo(100, 52, 70, 70).lineTo(35, 70).curveTo(100, 52, 35, 35)
.endFill();
next2d.load("develop");
// const { Sprite, Shape } = next2d.display;
// const root = await next2d.createRootMovieClip(480, 480);
// const shape = root.addChild(new Shape());
// shape.x = 75;
// shape.y = 75;
// shape
// .graphics
// .beginFill(0x0000ff)
// .moveTo(0, 0).curveTo(50, -25, 100, 0).curveTo(125, 50, 100, 100).lineTo(0, 100).curveTo(20, 50, 0, 0)
// .endFill()
// // non-zero
// // .beginFill(0x00ff00)
// .moveTo(75, 75).curveTo(170, 30, 75, 50).curveTo(50, 10, 50, 50).curveTo(95, 25+35/2, 50, 75).lineTo(75, 75)
// // .endFill()
// // even-odd
// // .beginFill(0xff0000)
// // .moveTo(25, 25).lineTo(60, 25).lineTo(60, 60).lineTo(25, 60).curveTo(-55, 25+35/2, 25, 25)
// // .beginFill(0x00ff00)
// // .moveTo(35, 35).lineTo(70, 35).curveTo(100, 52, 70, 70).lineTo(35, 70).curveTo(100, 52, 35, 35)
// .endFill();
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ precision mediump float;
uniform sampler2D u_texture;
in vec4 mul;
in vec4 add;
in vec4 v_mul;
in vec4 v_add;
in vec2 v_coord;
out vec4 o_color;
void main() {
vec4 src = texture(u_texture, v_coord);
if (mul.x != 1.0 || mul.y != 1.0 || mul.z != 1.0 || mul.w != 1.0
|| add.x != 0.0 || add.y != 0.0 || add.z != 0.0 || add.w != 0.0
if (v_mul.x != 1.0 || v_mul.y != 1.0 || v_mul.z != 1.0 || v_mul.w != 1.0
|| v_add.x != 0.0 || v_add.y != 0.0 || v_add.z != 0.0 || v_add.w != 0.0
) {
src.rgb /= max(0.0001, src.a);
src = clamp(src * mul + add, 0.0, 1.0);
src = clamp(src * v_mul + v_add, 0.0, 1.0);
src.rgb *= src.a;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/webgl/src/Shader/Vertex/VertexShaderSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ layout (location = 5) in vec4 a_mul;
layout (location = 6) in vec4 a_add;
out vec2 v_coord;
out vec4 mul;
out vec4 add;
out vec4 v_mul;
out vec4 v_add;
void main() {
v_coord = a_vertex * a_rect.zw + a_rect.xy;
mul = a_mul;
add = a_add;
v_mul = a_mul;
v_add = a_add;
vec2 position = vec2(a_vertex.x, 1.0 - a_vertex.y);
position = position * a_size.xy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { ShaderInstancedManager } from "../../Shader/ShaderInstancedManager";
import { execute as vertexArrayObjectBindService } from "../service/VertexArrayObjectBindService";
import { $gl } from "../../WebGLUtil";
import {
$gl,
$upperPowerOfTwo
} from "../../WebGLUtil";
import {
$instancedVertexArrayObject,
$getAttributeBuffer,
Expand All @@ -27,7 +30,7 @@ export const execute = (shader_instanced_manager: ShaderInstancedManager): void
if (shader_instanced_manager.attributes.length > attributeBuffer.length) {

attributeBuffer = new Float32Array(
shader_instanced_manager.attributes.length
$upperPowerOfTwo(shader_instanced_manager.attributes.length)
);
$setAttributeBuffer(attributeBuffer);

Expand Down

0 comments on commit f61ef62

Please sign in to comment.