Compare commits

...

61 Commits

Author SHA1 Message Date
6ad647ae56 Merge pull request 'main' (#132) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#132
2026-07-24 09:22:31 +00:00
b77aca926a Refactor shader sockets 2026-07-24 01:59:51 -07:00
c2bb20f905 Moises Jpelaez: 5.2 Updates 2026-07-23 23:41:13 -07:00
14c6a7be03 Merge pull request 'main' (#131) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#131
2026-07-24 06:13:01 +00:00
85d63e8413 Merge branch 'main' of https://dev.leenkx.com/Onek8/LNXSDK 2026-07-23 23:08:56 -07:00
78452aaf67 Finished Viewport 2026-07-23 23:02:14 -07:00
1f72636350 Merge pull request 'main' (#130) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#130
2026-07-23 07:00:06 +00:00
62433ce86a merge upstream 2026-07-23 06:58:51 +00:00
2be36398f7 Merge branch 'main' of https://dev.leenkx.com/Onek8/LNXSDK 2026-07-22 21:04:07 -07:00
2675138ddc Windows RunT/Krom WebView2 DX11 and OpenGL 2026-07-22 21:03:43 -07:00
572665e8e6 Merge pull request 'main' (#129) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#129
2026-07-22 04:01:11 +00:00
0839f39dfa merge upstream 2026-07-22 03:59:30 +00:00
57cf4955a1 Live patch - Light properties, object visibility and world 2026-07-21 20:57:36 -07:00
c52ae2e4f1 Merge pull request 'main' (#128) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#128
2026-07-21 03:26:52 +00:00
48141f23c5 Merge pull request 'MacOS arm64 Kmake' (#10) from Dante/LNXSDK:main into main
Reviewed-on: #10
2026-07-21 03:25:03 +00:00
cbbcd053fb MacOS arm64 Kmake 2026-07-20 20:15:25 -07:00
a57923860e Merge pull request 'main' (#127) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#127
2026-07-19 04:35:30 +00:00
160f6bdadf Viewport build 2026-07-18 21:33:47 -07:00
50ad462318 Live patch refactor 2026-07-18 19:49:25 -07:00
1239145da4 LivePatch Global 2026-07-18 16:32:51 -07:00
102941b5d2 Update 2026-07-18 16:31:21 -07:00
defff993a0 Merge pull request 'main' (#126) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#126
2026-07-18 16:24:34 +00:00
e408151295 merge upstream 2026-07-18 16:22:37 +00:00
22159c9f37 Delete leenkx/Sources/leenkx/logicnode/PlayActionFromNode.hx.backup 2026-07-18 16:22:17 +00:00
9a2779982d Update leenkx/Sources/iron/data/Geometry.hx 2026-07-18 16:21:39 +00:00
2fc7e9880a Upload files to "Krom" 2026-07-18 04:30:47 +00:00
7e1ac5fa5c Merge pull request 'main' (#125) from Onek8/LNXSDK:main into main
Reviewed-on: LeenkxTeam/LNXSDK#125
2026-07-18 03:27:17 +00:00
b2395f30fc VOX_PATCH_2 + VOX_5 2026-07-16 23:49:44 -07:00
f4b0bf1e93 Merge pull request 'Webview for RunT/Krom' (#9) from Dante/LNXSDK:main into main
Reviewed-on: #9
2026-07-14 00:02:33 +00:00
31a6a9d7ec Webview for RunT/Krom 2026-07-13 15:44:52 -07:00
7b2f21c499 Missing particle node 2026-07-10 19:04:13 -07:00
17c31b4a4b FSR Probe fix 2026-07-10 15:56:10 -07:00
013c8653ff SSGI rewrite 2026-07-10 12:43:24 -07:00
bd8b49a416 Multithreaded windows 2026-07-09 23:59:31 -07:00
9d83c318b6 Jolt Patch 2026-07-09 17:25:48 -07:00
cb19c9b5b4 Update lib/aura/Backends/hl/aura/math/FFT.h 2026-07-09 04:26:08 +00:00
f4fe822ef6 Update leenkx/Sources/leenkx/renderpath/Sky.hx 2026-07-09 02:06:06 +00:00
6689fbc734 Merge pull request 'Incremental recompute' (#8) from Dante/LNXSDK:main into main
Reviewed-on: #8
2026-06-26 04:40:09 +00:00
91b6c203e9 Incremental recompute 2026-06-25 21:33:51 -07:00
2c30554504 Moises Jpelaez - CPU particle visual fixes 2026-06-24 20:33:46 -07:00
37c8779d12 Patch_5 2026-06-24 20:23:12 -07:00
6b704ff469 Merge pull request 'main' (#7) from Dante/LNXSDK:main into main
Reviewed-on: #7
2026-06-24 07:15:29 +00:00
2a3bff5a18 Nishita to Sky 2026-06-24 00:12:30 -07:00
91482071b8 merge upstream 2026-06-24 07:06:56 +00:00
38151eb233 Update 2026-06-24 00:05:37 -07:00
78ea055aea Update Aura 2026-06-23 14:54:15 -07:00
db2482dbe2 Update leenkx/Sources/leenkx/logicnode/LeenkxSendMessageNode.hx 2026-06-23 05:58:41 +00:00
5ae6a9e698 Merge pull request 'main' (#6) from Dante/LNXSDK:main into main
Reviewed-on: #6
2026-06-23 02:39:31 +00:00
6db83e559b merge upstream 2026-06-23 02:07:46 +00:00
e7ec872747 FSR buffer 2026-06-22 19:07:01 -07:00
31226a3871 Merge pull request 'Update leenkx/Sources/leenkx/renderpath/RenderPathDeferred.hx' (#5) from Dante/LNXSDK:main into main
Reviewed-on: #5
2026-06-22 23:57:45 +00:00
9be3240d6c Update leenkx/Sources/leenkx/renderpath/RenderPathDeferred.hx 2026-06-22 22:42:52 +00:00
96134404a2 Compute 0 2026-06-15 20:07:42 -07:00
3aac63d255 Update Kha/Backends/Kore-HL/kha/korehl/graphics4/Graphics.hx 2026-06-10 05:55:02 +00:00
a8d6095204 Update Kha/Backends/Kore-HL/kha/korehl/graphics4/Graphics.hx 2026-06-10 02:37:45 +00:00
960095d0d5 Upload files to "Krom" 2026-06-09 23:02:56 +00:00
2b221338ae Merge pull request 'main' (#4) from Dante/LNXSDK:main into main
Reviewed-on: #4
2026-06-02 04:36:04 +00:00
7ef0d59cfc Update Krom 2026-06-01 20:46:47 -07:00
da1d893342 Update Kmake 2026-06-01 20:41:12 -07:00
7b5a72036a Update leenkx/Sources/leenkx/renderpath/DynamicResolutionScale.hx 2026-05-31 18:50:44 +00:00
694b226345 Wrong 2026-05-31 18:48:47 +00:00
203 changed files with 8023 additions and 2998 deletions

View File

@ -142,6 +142,8 @@ class Image implements Canvas implements Resource {
return 5;
case A16:
return 7;
case R32UI:
return 8;
default:
return 1; // Grey8
}

View File

@ -1,397 +1,397 @@
package kha.korehl.graphics4;
import kha.arrays.Float32Array;
import kha.graphics4.ComputeShader;
import kha.graphics4.CubeMap;
import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState;
import kha.graphics4.ShaderStorageBuffer;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.Usage;
import kha.graphics4.VertexBuffer;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.Canvas;
import kha.Image;
import kha.Video;
import kha.Color;
class Graphics implements kha.graphics4.Graphics {
var target: Canvas;
public function new(target: Canvas = null) {
this.target = target;
}
public function vsynced(): Bool {
return kinc_graphics_vsynced();
}
public function refreshRate(): Int {
return kinc_graphics_refreshrate();
}
public function clear(?color: Color, ?z: FastFloat, ?stencil: Int): Void {
var flags: Int = 0;
if (color != null)
flags |= 1;
if (z != null)
flags |= 2;
if (stencil != null)
flags |= 4;
kinc_graphics_clear(flags, color == null ? 0 : color.value, z, stencil);
}
public function viewport(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_viewport(x, y, width, height);
}
public function setVertexBuffer(vertexBuffer: kha.graphics4.VertexBuffer): Void {
kinc_graphics_set_vertexbuffer(vertexBuffer._buffer);
}
public function setVertexBuffers(vertexBuffers: Array<kha.graphics4.VertexBuffer>): Void {
kinc_graphics_set_vertexbuffers(vertexBuffers.length > 0 ? vertexBuffers[0]._buffer : null,
vertexBuffers.length > 1 ? vertexBuffers[1]._buffer : null, vertexBuffers.length > 2 ? vertexBuffers[2]._buffer : null,
vertexBuffers.length > 3 ? vertexBuffers[3]._buffer : null, vertexBuffers.length);
}
public function setIndexBuffer(indexBuffer: kha.graphics4.IndexBuffer): Void {
kinc_graphics_set_indexbuffer(indexBuffer._buffer);
}
public function maxTextureSize(): Int {
return 4096;
}
public function supportsNonPow2Textures(): Bool {
return false;
}
public function setCubeMap(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
if (cubeMap._texture != null)
kinc_graphics_set_cubemap_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._texture);
else
kinc_graphics_set_cubemap_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function setCubeMapDepth(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
kinc_graphics_set_cubemap_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function scissor(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_scissor(x, y, width, height);
}
public function disableScissor(): Void {
kinc_graphics_disable_scissor();
}
public function instancedRenderingAvailable(): Bool {
return true;
}
public function setTextureParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTexture3DParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture3d_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, wAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTextureCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_texture_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setCubeMapCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_cube_map_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
if (texture._texture != null)
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
else
kinc_graphics_set_render_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setTextureArray(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_array(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._textureArray);
}
public function setTextureDepth(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setVideoTexture(unit: kha.graphics4.TextureUnit, texture: kha.Video): Void {
if (texture == null)
return;
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, Image.fromVideo(texture)._texture);
}
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
kinc_graphics_set_image_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
}
public function maxBoundTextures(): Int {
return 8;
}
public function setPipeline(pipe: PipelineState): Void {
pipe.set();
}
public function setStencilReferenceValue(value: Int): Void {}
public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
kinc_graphics_set_bool(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt(location: kha.graphics4.ConstantLocation, value: Int): Void {
kinc_graphics_set_int(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt2(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int): Void {
kinc_graphics_set_int2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setInt3(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int): Void {
kinc_graphics_set_int3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setInt4(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {
kinc_graphics_set_int4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setInts(location: kha.graphics4.ConstantLocation, values: kha.arrays.Int32Array): Void {
kinc_graphics_set_ints(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public function setFloat(location: kha.graphics4.ConstantLocation, value: FastFloat): Void {
kinc_graphics_set_float(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setFloat2(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setFloat3(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setFloat4(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setVector2(location: kha.graphics4.ConstantLocation, value: FastVector2): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y);
}
public function setVector3(location: kha.graphics4.ConstantLocation, value: FastVector3): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z);
}
public function setVector4(location: kha.graphics4.ConstantLocation, value: FastVector4): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z, value.w);
}
public function setFloats(location: kha.graphics4.ConstantLocation, values: Float32Array): Void {
kinc_graphics_set_floats(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public inline function setMatrix(location: kha.graphics4.ConstantLocation, matrix: FastMatrix4): Void {
kinc_graphics_set_matrix(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._30, matrix._01,
matrix._11, matrix._21, matrix._31, matrix._02, matrix._12, matrix._22, matrix._32, matrix._03, matrix._13, matrix._23, matrix._33);
}
public inline function setMatrix3(location: kha.graphics4.ConstantLocation, matrix: FastMatrix3): Void {
kinc_graphics_set_matrix3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._01, matrix._11,
matrix._21, matrix._02, matrix._12, matrix._22);
}
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices();
else
kinc_graphics_draw_indexed_vertices(start, count);
}
public function drawIndexedVerticesInstanced(instanceCount: Int, start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount);
else
kinc_graphics_draw_indexed_vertices_instanced(instanceCount, start, count);
}
function renderToTexture(additionalRenderTargets: Array<Canvas>): Void {
if (additionalRenderTargets != null) {
var len = additionalRenderTargets.length;
var rt0 = cast(target, Image)._renderTarget;
var rt1 = len > 0 ? cast(additionalRenderTargets[0], Image)._renderTarget : null;
var rt2 = len > 1 ? cast(additionalRenderTargets[1], Image)._renderTarget : null;
var rt3 = len > 2 ? cast(additionalRenderTargets[2], Image)._renderTarget : null;
var rt4 = len > 3 ? cast(additionalRenderTargets[3], Image)._renderTarget : null;
var rt5 = len > 4 ? cast(additionalRenderTargets[4], Image)._renderTarget : null;
var rt6 = len > 5 ? cast(additionalRenderTargets[5], Image)._renderTarget : null;
var rt7 = len > 6 ? cast(additionalRenderTargets[6], Image)._renderTarget : null;
kinc_graphics_render_to_textures(rt0, rt1, rt2, rt3, rt4, rt5, rt6, rt7, len + 1);
}
else {
kinc_graphics_render_to_texture(cast(target, Image)._renderTarget);
}
}
public function begin(additionalRenderTargets: Array<Canvas> = null): Void {
if (target == null)
kinc_graphics_restore_render_target();
else
renderToTexture(additionalRenderTargets);
}
public function beginFace(face: Int): Void {
kinc_graphics_render_to_face(cast(target, CubeMap)._renderTarget, face);
}
public function beginEye(eye: Int): Void {}
public function end(): Void {}
public function flush(): Void {
kinc_graphics_flush();
}
public function setShaderStorageBuffer(buffer: ShaderStorageBuffer, index: Int) {
// Kore::Compute::setBuffer(buffer->buffer, index);
}
public function setComputeShader(shader: ComputeShader) {
kinc_g4_set_compute_shader(shader._shader);
}
public function compute(x: Int, y: Int, z: Int) {
kinc_g4_compute(x, y, z);
}
@:hlNative("std", "kinc_graphics_clear") static function kinc_graphics_clear(flags: Int, color: Int, z: FastFloat, stencil: Int): Void {}
@:hlNative("std", "kinc_graphics_vsynced") static function kinc_graphics_vsynced(): Bool {
return false;
}
@:hlNative("std", "kinc_graphics_refreshrate") static function kinc_graphics_refreshrate(): Int {
return 0;
}
@:hlNative("std", "kinc_graphics_viewport") static function kinc_graphics_viewport(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffer") static function kinc_graphics_set_vertexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffers") static function kinc_graphics_set_vertexbuffers(b0: Pointer, b1: Pointer, b2: Pointer, b3: Pointer,
count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_indexbuffer") static function kinc_graphics_set_indexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_scissor") static function kinc_graphics_scissor(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_disable_scissor") static function kinc_graphics_disable_scissor(): Void {}
@:hlNative("std", "kinc_graphics_set_texture_parameters") static function kinc_graphics_set_texture_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture3d_parameters") static function kinc_graphics_set_texture3d_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, wAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture_compare_mode") static function kinc_graphics_set_texture_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_cube_map_compare_mode") static function kinc_graphics_set_cube_map_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_texture") static function kinc_graphics_set_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_depth") static function kinc_graphics_set_texture_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_array") static function kinc_graphics_set_texture_array(unit: Pointer, textureArray: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_render_target") static function kinc_graphics_set_render_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_texture") static function kinc_graphics_set_cubemap_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_target") static function kinc_graphics_set_cubemap_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_depth") static function kinc_graphics_set_cubemap_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_image_texture") static function kinc_graphics_set_image_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_bool") static function kinc_graphics_set_bool(location: Pointer, value: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_int") static function kinc_graphics_set_int(location: Pointer, value: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int2") static function kinc_graphics_set_int2(location: Pointer, value1: Int, value2: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int3") static function kinc_graphics_set_int3(location: Pointer, value1: Int, value2: Int, value3: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int4") static function kinc_graphics_set_int4(location: Pointer, value1: Int, value2: Int, value3: Int,
value4: Int): Void {}
@:hlNative("std", "kinc_graphics_set_ints") static function kinc_graphics_set_ints(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_float") static function kinc_graphics_set_float(location: Pointer, value: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float2") static function kinc_graphics_set_float2(location: Pointer, value1: FastFloat, value2: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float3") static function kinc_graphics_set_float3(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float4") static function kinc_graphics_set_float4(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat, value4: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_floats") static function kinc_graphics_set_floats(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_matrix") static function kinc_graphics_set_matrix(location: Pointer, _00: FastFloat, _10: FastFloat, _20: FastFloat,
_30: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _31: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat, _32: FastFloat,
_03: FastFloat, _13: FastFloat, _23: FastFloat, _33: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_matrix3") static function kinc_graphics_set_matrix3(location: Pointer, _00: FastFloat, _10: FastFloat,
_20: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_draw_all_indexed_vertices") static function kinc_graphics_draw_all_indexed_vertices(): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices") static function kinc_graphics_draw_indexed_vertices(start: Int, count: Int): Void {}
@:hlNative("std",
"kinc_graphics_draw_all_indexed_vertices_instanced") static function kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount: Int): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices_instanced") static function kinc_graphics_draw_indexed_vertices_instanced(instanceCount: Int,
start: Int, count: Int): Void {}
@:hlNative("std", "kinc_graphics_restore_render_target") static function kinc_graphics_restore_render_target(): Void {}
@:hlNative("std", "kinc_graphics_render_to_texture") static function kinc_graphics_render_to_texture(renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_render_to_textures") static function kinc_graphics_render_to_textures(rt0: Pointer, rt1: Pointer, rt2: Pointer,
rt3: Pointer, rt4: Pointer, rt5: Pointer, rt6: Pointer, rt7: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_render_to_face") static function kinc_graphics_render_to_face(renderTarget: Pointer, face: Int): Void {}
@:hlNative("std", "kinc_graphics_flush") static function kinc_graphics_flush(): Void {}
@:hlNative("std", "kinc_g4_set_compute_shader") static function kinc_g4_set_compute_shader(shader: Pointer): Void {}
@:hlNative("std", "kinc_g4_compute") static function kinc_g4_compute(x: Int, y: Int, z: Int): Void {}
}
package kha.korehl.graphics4;
import kha.arrays.Float32Array;
import kha.graphics4.ComputeShader;
import kha.graphics4.CubeMap;
import kha.graphics4.MipMapFilter;
import kha.graphics4.PipelineState;
import kha.graphics4.ShaderStorageBuffer;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.Usage;
import kha.graphics4.VertexBuffer;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.Canvas;
import kha.Image;
import kha.Video;
import kha.Color;
class Graphics implements kha.graphics4.Graphics {
var target: Canvas;
public function new(target: Canvas = null) {
this.target = target;
}
public function vsynced(): Bool {
return kinc_graphics_vsynced();
}
public function refreshRate(): Int {
return kinc_graphics_refreshrate();
}
public function clear(?color: Color, ?z: FastFloat, ?stencil: Int): Void {
var flags: Int = 0;
if (color != null)
flags |= 1;
if (z != null)
flags |= 2;
if (stencil != null)
flags |= 4;
kinc_graphics_clear(flags, color == null ? 0 : color.value, z, stencil);
}
public function viewport(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_viewport(x, y, width, height);
}
public function setVertexBuffer(vertexBuffer: kha.graphics4.VertexBuffer): Void {
kinc_graphics_set_vertexbuffer(vertexBuffer._buffer);
}
public function setVertexBuffers(vertexBuffers: Array<kha.graphics4.VertexBuffer>): Void {
kinc_graphics_set_vertexbuffers(vertexBuffers.length > 0 ? vertexBuffers[0]._buffer : null,
vertexBuffers.length > 1 ? vertexBuffers[1]._buffer : null, vertexBuffers.length > 2 ? vertexBuffers[2]._buffer : null,
vertexBuffers.length > 3 ? vertexBuffers[3]._buffer : null, vertexBuffers.length);
}
public function setIndexBuffer(indexBuffer: kha.graphics4.IndexBuffer): Void {
kinc_graphics_set_indexbuffer(indexBuffer._buffer);
}
public function maxTextureSize(): Int {
return 4096;
}
public function supportsNonPow2Textures(): Bool {
return false;
}
public function setCubeMap(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
if (cubeMap._texture != null)
kinc_graphics_set_cubemap_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._texture);
else
kinc_graphics_set_cubemap_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function setCubeMapDepth(unit: kha.graphics4.TextureUnit, cubeMap: kha.graphics4.CubeMap): Void {
if (cubeMap == null)
return;
kinc_graphics_set_cubemap_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, cubeMap._renderTarget);
}
public function scissor(x: Int, y: Int, width: Int, height: Int): Void {
kinc_graphics_scissor(x, y, width, height);
}
public function disableScissor(): Void {
kinc_graphics_disable_scissor();
}
public function instancedRenderingAvailable(): Bool {
return true;
}
public function setTextureParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTexture3DParameters(unit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void {
kinc_graphics_set_texture3d_parameters(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, uAddressing, vAddressing, wAddressing, minificationFilter,
magnificationFilter, mipmapFilter);
}
public function setTextureCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_texture_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setCubeMapCompareMode(unit: kha.graphics4.TextureUnit, enabled: Bool) {
kinc_graphics_set_cube_map_compare_mode(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, enabled);
}
public function setTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
if (texture._texture != null)
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
else
kinc_graphics_set_render_target(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setTextureArray(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_array(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._textureArray);
}
public function setTextureDepth(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
kinc_graphics_set_texture_depth(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._renderTarget);
}
public function setVideoTexture(unit: kha.graphics4.TextureUnit, texture: kha.Video): Void {
if (texture == null)
return;
kinc_graphics_set_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, Image.fromVideo(texture)._texture);
}
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
kinc_graphics_set_image_texture(cast(unit, kha.korehl.graphics4.TextureUnit)._unit, texture._texture);
}
public function maxBoundTextures(): Int {
return 8;
}
public function setPipeline(pipe: PipelineState): Void {
pipe.set();
}
public function setStencilReferenceValue(value: Int): Void {}
public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
kinc_graphics_set_bool(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt(location: kha.graphics4.ConstantLocation, value: Int): Void {
kinc_graphics_set_int(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setInt2(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int): Void {
kinc_graphics_set_int2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setInt3(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int): Void {
kinc_graphics_set_int3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setInt4(location: kha.graphics4.ConstantLocation, value1: Int, value2: Int, value3: Int, value4: Int): Void {
kinc_graphics_set_int4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setInts(location: kha.graphics4.ConstantLocation, values: kha.arrays.Int32Array): Void {
kinc_graphics_set_ints(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public function setFloat(location: kha.graphics4.ConstantLocation, value: FastFloat): Void {
kinc_graphics_set_float(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value);
}
public function setFloat2(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2);
}
public function setFloat3(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3);
}
public function setFloat4(location: kha.graphics4.ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value1, value2, value3, value4);
}
public function setVector2(location: kha.graphics4.ConstantLocation, value: FastVector2): Void {
kinc_graphics_set_float2(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y);
}
public function setVector3(location: kha.graphics4.ConstantLocation, value: FastVector3): Void {
kinc_graphics_set_float3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z);
}
public function setVector4(location: kha.graphics4.ConstantLocation, value: FastVector4): Void {
kinc_graphics_set_float4(cast(location, kha.korehl.graphics4.ConstantLocation)._location, value.x, value.y, value.z, value.w);
}
public function setFloats(location: kha.graphics4.ConstantLocation, values: Float32Array): Void {
kinc_graphics_set_floats(cast(location, kha.korehl.graphics4.ConstantLocation)._location, values.getData(), values.length);
}
public inline function setMatrix(location: kha.graphics4.ConstantLocation, matrix: FastMatrix4): Void {
kinc_graphics_set_matrix(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._30, matrix._01,
matrix._11, matrix._21, matrix._31, matrix._02, matrix._12, matrix._22, matrix._32, matrix._03, matrix._13, matrix._23, matrix._33);
}
public inline function setMatrix3(location: kha.graphics4.ConstantLocation, matrix: FastMatrix3): Void {
kinc_graphics_set_matrix3(cast(location, kha.korehl.graphics4.ConstantLocation)._location, matrix._00, matrix._10, matrix._20, matrix._01, matrix._11,
matrix._21, matrix._02, matrix._12, matrix._22);
}
public function drawIndexedVertices(start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices();
else
kinc_graphics_draw_indexed_vertices(start, count);
}
public function drawIndexedVerticesInstanced(instanceCount: Int, start: Int = 0, count: Int = -1): Void {
if (count < 0)
kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount);
else
kinc_graphics_draw_indexed_vertices_instanced(instanceCount, start, count);
}
function renderToTexture(additionalRenderTargets: Array<Canvas>): Void {
if (additionalRenderTargets != null) {
var len = additionalRenderTargets.length;
var rt0 = cast(target, Image)._renderTarget;
var rt1 = len > 0 ? cast(additionalRenderTargets[0], Image)._renderTarget : null;
var rt2 = len > 1 ? cast(additionalRenderTargets[1], Image)._renderTarget : null;
var rt3 = len > 2 ? cast(additionalRenderTargets[2], Image)._renderTarget : null;
var rt4 = len > 3 ? cast(additionalRenderTargets[3], Image)._renderTarget : null;
var rt5 = len > 4 ? cast(additionalRenderTargets[4], Image)._renderTarget : null;
var rt6 = len > 5 ? cast(additionalRenderTargets[5], Image)._renderTarget : null;
var rt7 = len > 6 ? cast(additionalRenderTargets[6], Image)._renderTarget : null;
kinc_graphics_render_to_textures(rt0, rt1, rt2, rt3, rt4, rt5, rt6, rt7, len + 1);
}
else {
kinc_graphics_render_to_texture(cast(target, Image)._renderTarget);
}
}
public function begin(additionalRenderTargets: Array<Canvas> = null): Void {
if (target == null)
kinc_graphics_restore_render_target();
else
renderToTexture(additionalRenderTargets);
}
public function beginFace(face: Int): Void {
kinc_graphics_render_to_face((target is CubeMap) ? cast(target, CubeMap)._renderTarget : cast(target, Image)._renderTarget, face);
}
public function beginEye(eye: Int): Void {}
public function end(): Void {}
public function flush(): Void {
kinc_graphics_flush();
}
public function setShaderStorageBuffer(buffer: ShaderStorageBuffer, index: Int) {
// Kore::Compute::setBuffer(buffer->buffer, index);
}
public function setComputeShader(shader: ComputeShader) {
kinc_g4_set_compute_shader(shader._shader);
}
public function compute(x: Int, y: Int, z: Int) {
kinc_g4_compute(x, y, z);
}
@:hlNative("std", "kinc_graphics_clear") static function kinc_graphics_clear(flags: Int, color: Int, z: FastFloat, stencil: Int): Void {}
@:hlNative("std", "kinc_graphics_vsynced") static function kinc_graphics_vsynced(): Bool {
return false;
}
@:hlNative("std", "kinc_graphics_refreshrate") static function kinc_graphics_refreshrate(): Int {
return 0;
}
@:hlNative("std", "kinc_graphics_viewport") static function kinc_graphics_viewport(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffer") static function kinc_graphics_set_vertexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_vertexbuffers") static function kinc_graphics_set_vertexbuffers(b0: Pointer, b1: Pointer, b2: Pointer, b3: Pointer,
count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_indexbuffer") static function kinc_graphics_set_indexbuffer(buffer: Pointer): Void {}
@:hlNative("std", "kinc_graphics_scissor") static function kinc_graphics_scissor(x: Int, y: Int, width: Int, height: Int): Void {}
@:hlNative("std", "kinc_graphics_disable_scissor") static function kinc_graphics_disable_scissor(): Void {}
@:hlNative("std", "kinc_graphics_set_texture_parameters") static function kinc_graphics_set_texture_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture3d_parameters") static function kinc_graphics_set_texture3d_parameters(unit: Pointer, uAddressing: Int,
vAddressing: Int, wAddressing: Int, minificationFilter: Int, magnificationFilter: Int, mipmapFilter: Int): Void {}
@:hlNative("std", "kinc_graphics_set_texture_compare_mode") static function kinc_graphics_set_texture_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_cube_map_compare_mode") static function kinc_graphics_set_cube_map_compare_mode(unit: Pointer, enabled: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_texture") static function kinc_graphics_set_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_depth") static function kinc_graphics_set_texture_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_texture_array") static function kinc_graphics_set_texture_array(unit: Pointer, textureArray: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_render_target") static function kinc_graphics_set_render_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_texture") static function kinc_graphics_set_cubemap_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_target") static function kinc_graphics_set_cubemap_target(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_cubemap_depth") static function kinc_graphics_set_cubemap_depth(unit: Pointer, renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_image_texture") static function kinc_graphics_set_image_texture(unit: Pointer, texture: Pointer): Void {}
@:hlNative("std", "kinc_graphics_set_bool") static function kinc_graphics_set_bool(location: Pointer, value: Bool): Void {}
@:hlNative("std", "kinc_graphics_set_int") static function kinc_graphics_set_int(location: Pointer, value: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int2") static function kinc_graphics_set_int2(location: Pointer, value1: Int, value2: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int3") static function kinc_graphics_set_int3(location: Pointer, value1: Int, value2: Int, value3: Int): Void {}
@:hlNative("std", "kinc_graphics_set_int4") static function kinc_graphics_set_int4(location: Pointer, value1: Int, value2: Int, value3: Int,
value4: Int): Void {}
@:hlNative("std", "kinc_graphics_set_ints") static function kinc_graphics_set_ints(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_float") static function kinc_graphics_set_float(location: Pointer, value: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float2") static function kinc_graphics_set_float2(location: Pointer, value1: FastFloat, value2: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float3") static function kinc_graphics_set_float3(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_float4") static function kinc_graphics_set_float4(location: Pointer, value1: FastFloat, value2: FastFloat,
value3: FastFloat, value4: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_floats") static function kinc_graphics_set_floats(location: Pointer, values: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_set_matrix") static function kinc_graphics_set_matrix(location: Pointer, _00: FastFloat, _10: FastFloat, _20: FastFloat,
_30: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _31: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat, _32: FastFloat,
_03: FastFloat, _13: FastFloat, _23: FastFloat, _33: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_set_matrix3") static function kinc_graphics_set_matrix3(location: Pointer, _00: FastFloat, _10: FastFloat,
_20: FastFloat, _01: FastFloat, _11: FastFloat, _21: FastFloat, _02: FastFloat, _12: FastFloat, _22: FastFloat): Void {}
@:hlNative("std", "kinc_graphics_draw_all_indexed_vertices") static function kinc_graphics_draw_all_indexed_vertices(): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices") static function kinc_graphics_draw_indexed_vertices(start: Int, count: Int): Void {}
@:hlNative("std",
"kinc_graphics_draw_all_indexed_vertices_instanced") static function kinc_graphics_draw_all_indexed_vertices_instanced(instanceCount: Int): Void {}
@:hlNative("std", "kinc_graphics_draw_indexed_vertices_instanced") static function kinc_graphics_draw_indexed_vertices_instanced(instanceCount: Int,
start: Int, count: Int): Void {}
@:hlNative("std", "kinc_graphics_restore_render_target") static function kinc_graphics_restore_render_target(): Void {}
@:hlNative("std", "kinc_graphics_render_to_texture") static function kinc_graphics_render_to_texture(renderTarget: Pointer): Void {}
@:hlNative("std", "kinc_graphics_render_to_textures") static function kinc_graphics_render_to_textures(rt0: Pointer, rt1: Pointer, rt2: Pointer,
rt3: Pointer, rt4: Pointer, rt5: Pointer, rt6: Pointer, rt7: Pointer, count: Int): Void {}
@:hlNative("std", "kinc_graphics_render_to_face") static function kinc_graphics_render_to_face(renderTarget: Pointer, face: Int): Void {}
@:hlNative("std", "kinc_graphics_flush") static function kinc_graphics_flush(): Void {}
@:hlNative("std", "kinc_g4_set_compute_shader") static function kinc_g4_set_compute_shader(shader: Pointer): Void {}
@:hlNative("std", "kinc_g4_compute") static function kinc_g4_compute(x: Int, y: Int, z: Int): Void {}
}

View File

@ -234,6 +234,8 @@ class Image implements Canvas implements Resource {
return 5;
case A16:
return 7;
case R32UI:
return 8;
default:
return 1; // Grey8
}

View File

@ -23,6 +23,7 @@ extern class Krom {
static function setRenderTarget(stage: kha.graphics4.TextureUnit, renderTarget: Dynamic): Void;
static function setTextureDepth(unit: kha.graphics4.TextureUnit, texture: Dynamic): Void;
static function setImageTexture(stage: kha.graphics4.TextureUnit, texture: Dynamic): Void;
static function setImageRenderTarget(stage: kha.graphics4.TextureUnit, renderTarget: Dynamic): Void;
static function setTextureParameters(texunit: kha.graphics4.TextureUnit, uAddressing: Int, vAddressing: Int, minificationFilter: Int,
magnificationFilter: Int, mipmapFilter: Int): Void;
static function setTexture3DParameters(texunit: kha.graphics4.TextureUnit, uAddressing: Int, vAddressing: Int, wAddressing: Int, minificationFilter: Int,
@ -114,6 +115,7 @@ extern class Krom {
static function windowWidth(id: Int): Int;
static function windowHeight(id: Int): Int;
static function setWindowTitle(id: Int, title: String): Void;
static function windowSetForeground(id: Int): Void;
static function screenDpi(): Int;
static function systemId(): String;
static function requestShutdown(): Void;
@ -158,4 +160,45 @@ extern class Krom {
static function getConstantLocationCompute(shader: Dynamic, name: String): Dynamic;
static function getTextureUnitCompute(shader: Dynamic, name: String): Dynamic;
static function compute(x: Int, y: Int, z: Int): Void;
static function webviewCreate(options: Dynamic): Int;
static function webviewLoadHTML(id: Int, html: String): Void;
static function webviewLoadURL(id: Int, url: String): Void;
static function webviewEvalJS(id: Int, js: String): Void;
static function webviewEvalJSAsync(id: Int, js: String, callback: String->Void): Void;
static function webviewShow(id: Int): Void;
static function webviewHide(id: Int): Void;
static function webviewDestroy(id: Int): Void;
static function webviewResize(id: Int, width: Int, height: Int): Void;
static function webviewMove(id: Int, x: Int, y: Int): Void;
static function webviewSetBounds(id: Int, x: Int, y: Int, width: Int, height: Int): Void;
static function webviewGetX(id: Int): Int;
static function webviewGetY(id: Int): Int;
static function webviewGetWidth(id: Int): Int;
static function webviewGetHeight(id: Int): Int;
static function webviewSetTransparent(id: Int, transparent: Bool): Void;
static function webviewSetClickThrough(id: Int, enabled: Bool): Void;
static function webviewSetTitle(id: Int, title: String): Void;
static function webviewSend(id: Int, message: String): Void;
static function webviewSetOnMessage(id: Int, callback: String->Void): Void;
static function webviewSetOnLoad(id: Int, callback: Void->Void): Void;
static function webviewSetOnError(id: Int, callback: String->Void): Void;
static function webviewSetOnClose(id: Int, callback: Void->Void): Void;
static function webviewCount(): Int;
static function webviewIsValid(id: Int): Bool;
static function webviewSetActiveDOM(id: Int): Void;
static function webviewGetActiveDOM(): Int;
static function webviewGoBack(id: Int): Void;
static function webviewGoForward(id: Int): Void;
static function webviewReload(id: Int): Void;
static function webviewCanGoBack(id: Int): Bool;
static function webviewCanGoForward(id: Int): Bool;
static function webviewGetURL(id: Int): String;
static function webviewGetPageTitle(id: Int): String;
static function webviewMinimize(id: Int): Void;
static function webviewMaximize(id: Int): Void;
static function webviewRestore(id: Int): Void;
static function webviewSetFullscreen(id: Int, fullscreen: Bool): Void;
static function webviewIsFullscreen(id: Int): Bool;
static function webviewEnableDevTools(id: Int, enabled: Bool): Void;
static function webviewSetContextMenu(id: Int, enabled: Bool): Void;
}

View File

@ -75,6 +75,8 @@ class Image implements Canvas implements Resource {
return 5;
case A16:
return 7;
case R32UI:
return 8;
default:
return 1; // Grey8
}
@ -200,6 +202,7 @@ class Image implements Canvas implements Resource {
case RGBA64: 8;
case A32: 4;
case A16: 2;
case R32UI: 4;
default: 4;
}
}

View File

@ -30,15 +30,15 @@ class LoaderImpl {
}
public static function loadSoundFromDescription(desc: Dynamic, done: kha.Sound->Void, failed: AssetError->Void) {
var sound = Krom.loadSound(desc.files[0]);
if (sound == null) {
var sound = new kha.krom.Sound(desc.files[0]);
if (sound.uncompressedData == null) {
failed({
url: desc.files.join(","),
error: "Could not load sound(s)",
});
}
else {
done(new kha.krom.Sound(Bytes.ofData(sound)));
done(sound);
}
}

View File

@ -106,7 +106,7 @@ class Compute {
public static function setSampledDepthTexture(unit: TextureUnit, texture: Image) {
if (texture == null)
return;
Krom.setSampledDepthTextureCompute(unit, texture);
Krom.setSampledDepthTextureCompute(unit, texture.renderTarget_);
}
public static function setSampledCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
@ -118,7 +118,7 @@ class Compute {
public static function setSampledDepthCubeMap(unit: TextureUnit, cubeMap: CubeMap) {
if (cubeMap == null)
return;
Krom.setSampledDepthTextureCompute(unit, cubeMap);
Krom.setSampledDepthTextureCompute(unit, cubeMap.renderTarget_);
}
public static function setTextureParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,

View File

@ -9,14 +9,7 @@ class ShaderStorageBuffer {
public function new(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
init(indexCount, type);
}
function init(indexCount: Int, type: VertexData) {
myCount = indexCount;
data = new Array<Int>();
data[myCount - 1] = 0;
if (myCount > 0) data[myCount - 1] = 0;
}
public function delete(): Void {}

View File

@ -1,22 +1,25 @@
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public function new(sources: Array<Blob>, files: Array<String>) {
}
public function delete(): Void {
}
public function getConstantLocation(name: String): ConstantLocation {
return null;
}
public function getTextureUnit(name: String): TextureUnit {
return null;
}
}
package kha.graphics4;
import haxe.io.Bytes;
import kha.Blob;
class ComputeShader {
public var shader_: Dynamic;
public function new(sources: Array<Blob>, files: Array<String>) {
shader_ = Krom.createShaderCompute(sources[0].toBytes().getData());
}
public function delete(): Void {
Krom.deleteShaderCompute(shader_);
shader_ = null;
}
public function getConstantLocation(name: String): ConstantLocation {
return Krom.getConstantLocationCompute(shader_, name);
}
public function getTextureUnit(name: String): TextureUnit {
return Krom.getTextureUnitCompute(shader_, name);
}
}

View File

@ -122,7 +122,12 @@ class Graphics implements kha.graphics4.Graphics {
public function setImageTexture(unit: kha.graphics4.TextureUnit, texture: kha.Image): Void {
if (texture == null)
return;
Krom.setImageTexture(unit, texture.texture_);
if (texture.texture_ != null) {
Krom.setImageTexture(unit, texture.texture_);
}
else if (texture.renderTarget_ != null) {
Krom.setImageRenderTarget(unit, texture.renderTarget_);
}
}
public function setTextureParameters(texunit: kha.graphics4.TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
@ -261,10 +266,10 @@ class Graphics implements kha.graphics4.Graphics {
}
public function setComputeShader(shader: ComputeShader) {
Krom.setShaderCompute(shader.shader_);
}
public function compute(x: Int, y: Int, z: Int) {
Krom.compute(x, y, z);
}
}

View File

@ -2,24 +2,28 @@ package kha.krom;
import haxe.io.Bytes;
using StringTools;
class Sound extends kha.Sound {
public function new(bytes: Bytes) {
public function new(filename: String) {
super();
var count = Std.int(bytes.length / 4);
uncompressedData = new kha.arrays.Float32Array(count);
for (i in 0...count) {
uncompressedData[i] = bytes.getFloat(i * 4);
}
var sound = Krom.loadSound(filename);
if (sound != null) {
var bytes = Bytes.ofData(sound.buffer);
var count = Std.int(bytes.length / 4);
uncompressedData = new kha.arrays.Float32Array(count);
for (i in 0...count) {
uncompressedData[i] = bytes.getFloat(i * 4);
}
compressedData = null;
this.sampleRate = sound.sampleRate;
this.channels = sound.channels;
this.length = sound.length;
}
}
override public function uncompress(done: Void->Void): Void {
done();
}
override public function unload(): Void {
super.unload();
}
}

View File

@ -821,8 +821,19 @@ int kinc_g4_max_bound_textures(void) {
return units;
}
static int getUnitStage(kinc_g4_texture_unit_t unit) {
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
return unit.stages[i];
}
}
return -1;
}
static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(unit);
if (stage < 0) return;
glActiveTexture(GL_TEXTURE0 + stage);
GLenum texDir;
switch (dir) {
case KINC_G4_TEXTURE_DIRECTION_U:
@ -841,39 +852,39 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
case KINC_G4_TEXTURE_ADDRESSING_CLAMP:
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesU[stage] = GL_CLAMP_TO_EDGE;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesV[stage] = GL_CLAMP_TO_EDGE;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_REPEAT:
glTexParameteri(target, texDir, GL_REPEAT);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesU[stage] = GL_REPEAT;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesV[stage] = GL_REPEAT;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_BORDER:
// unsupported
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesU[stage] = GL_CLAMP_TO_EDGE;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesV[stage] = GL_CLAMP_TO_EDGE;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_MIRROR:
// unsupported
glTexParameteri(target, texDir, GL_REPEAT);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesU[stage] = GL_REPEAT;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesV[stage] = GL_REPEAT;
}
break;
}
@ -881,11 +892,15 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
}
int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) {
return texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
int stage = getUnitStage(unit);
if (stage < 0) return GL_CLAMP_TO_EDGE;
return texModesU[stage];
}
int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit) {
return texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
int stage = getUnitStage(unit);
if (stage < 0) return GL_CLAMP_TO_EDGE;
return texModesV[stage];
}
void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
@ -899,7 +914,9 @@ void kinc_g4_set_texture3d_addressing(kinc_g4_texture_unit_t unit, kinc_g4_textu
}
static void setTextureMagnificationFilterInternal(GLenum target, kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
glActiveTexture(GL_TEXTURE0 + texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
glActiveTexture(GL_TEXTURE0 + stage);
glCheckErrors();
switch (filter) {
case KINC_G4_TEXTURE_FILTER_POINT:
@ -964,26 +981,34 @@ static void setMinMipFilters(GLenum target, int unit) {
}
void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
minFilters[stage] = filter;
setMinMipFilters(GL_TEXTURE_2D, stage);
}
void kinc_g4_set_texture3d_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
int stage = getUnitStage(texunit);
if (stage < 0) return;
minFilters[stage] = filter;
#ifndef KINC_OPENGL_ES
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
setMinMipFilters(GL_TEXTURE_3D, stage);
#endif
}
void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
mipFilters[stage] = filter;
setMinMipFilters(GL_TEXTURE_2D, stage);
}
void kinc_g4_set_texture3d_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
int stage = getUnitStage(texunit);
if (stage < 0) return;
mipFilters[stage] = filter;
#ifndef KINC_OPENGL_ES
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
setMinMipFilters(GL_TEXTURE_3D, stage);
#endif
}

View File

@ -190,6 +190,17 @@ void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) {
#endif
}
void kinc_g4_set_image_render_target(kinc_g4_texture_unit_t unit, kinc_g4_render_target_t *render_target) {
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glBindImageTexture(unit.stages[i], render_target->impl._texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalRTFormat((kinc_g4_render_target_format_t)render_target->impl.format));
}
}
glCheckErrors();
#endif
}
void kinc_g4_compute(int x, int y, int z) {
#ifdef HAS_COMPUTE
glDispatchCompute(x, y, z);

View File

@ -360,17 +360,23 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
}
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
glCheckErrors();
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
glCheckErrors();
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
glCheckErrors();
}
}
}
void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
glCheckErrors();
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
glCheckErrors();
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
glCheckErrors();
}
}
}
void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) {

View File

@ -99,6 +99,8 @@ static int convertFormat(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_A16:
case KINC_IMAGE_FORMAT_GREY8:
return GL_RED;
case KINC_IMAGE_FORMAT_R32UI:
return GL_RED_INTEGER;
}
}
@ -132,6 +134,8 @@ static int convertInternalFormat(kinc_image_format_t format) {
#else
return GL_R8;
#endif
case KINC_IMAGE_FORMAT_R32UI:
return GL_R32UI;
}
}
@ -145,6 +149,8 @@ static int convertType(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA32:
default:
return GL_UNSIGNED_BYTE;
case KINC_IMAGE_FORMAT_R32UI:
return GL_UNSIGNED_INT;
}
}
@ -483,7 +489,7 @@ void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, i
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glCheckErrors();
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), GL_UNSIGNED_BYTE, NULL);
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), convertType(format), NULL);
glCheckErrors();
#endif
}
@ -523,8 +529,8 @@ void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_uni
#else
glBindTexture(target, texture->impl.texture);
glCheckErrors();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
glTexParameteri(target, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
glTexParameteri(target, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
#endif
}
@ -532,7 +538,7 @@ void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_textur
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, convertInternalFormat(texture->format));
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalFormat(texture->format));
}
}
glCheckErrors();

View File

@ -392,6 +392,11 @@ void kinc_window_hide(int window_index) {
UpdateWindow(windows[window_index].handle);
}
void kinc_window_set_foreground(int window_index) {
SetForegroundWindow(windows[window_index].handle);
SetFocus(windows[window_index].handle);
}
void kinc_window_set_title(int window_index, const char *title) {
wchar_t buffer[1024];
MultiByteToWideChar(CP_UTF8, 0, title, -1, buffer, 1024);

View File

@ -376,6 +376,8 @@ KINC_FUNC void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_t
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture);
KINC_FUNC void kinc_g4_set_image_render_target(kinc_g4_texture_unit_t unit, struct kinc_g4_render_target *render_target);
KINC_FUNC bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery);
KINC_FUNC void kinc_g4_delete_occlusion_query(unsigned occlusionQuery);

View File

@ -30,7 +30,8 @@ typedef enum kinc_image_format {
KINC_IMAGE_FORMAT_RGBA64,
KINC_IMAGE_FORMAT_A32,
KINC_IMAGE_FORMAT_BGRA32,
KINC_IMAGE_FORMAT_A16
KINC_IMAGE_FORMAT_A16,
KINC_IMAGE_FORMAT_R32UI
} kinc_image_format_t;
typedef struct kinc_image {
@ -608,6 +609,8 @@ int kinc_image_format_sizeof(kinc_image_format_t format) {
return 1;
case KINC_IMAGE_FORMAT_RGB24:
return 3;
case KINC_IMAGE_FORMAT_R32UI:
return 4;
}
return -1;
}

View File

@ -139,6 +139,11 @@ KINC_FUNC void kinc_window_show(int window);
/// </summary>
KINC_FUNC void kinc_window_hide(int window);
/// <summary>
/// Brings a window to the foreground and sets focus to it.
/// </summary>
KINC_FUNC void kinc_window_set_foreground(int window);
/// <summary>
/// Sets the title of a window.
/// </summary>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

After

Width:  |  Height:  |  Size: 281 KiB

View File

@ -68,7 +68,7 @@ class Sound implements Resource {
var soundBytes = output.getBytes();
var count = Std.int(soundBytes.length / 4);
if (header.channel == 1) {
length = count / kha.audio2.Audio.samplesPerSecond; // header.sampleRate;
length = count / header.sampleRate;
uncompressedData = new kha.arrays.Float32Array(count * 2);
for (i in 0...count) {
uncompressedData[i * 2 + 0] = soundBytes.getFloat(i * 4);
@ -76,7 +76,7 @@ class Sound implements Resource {
}
}
else {
length = count / 2 / kha.audio2.Audio.samplesPerSecond; // header.sampleRate;
length = count / 2 / header.sampleRate;
uncompressedData = new kha.arrays.Float32Array(count);
for (i in 0...count) {
uncompressedData[i] = soundBytes.getFloat(i * 4);

View File

@ -0,0 +1,7 @@
package kha.compute;
enum abstract Access(Int) to Int {
var Read = 0;
var Write = 1;
var ReadWrite = 2;
}

View File

@ -0,0 +1,41 @@
package kha.compute;
import kha.arrays.Float32Array;
import kha.Image;
import kha.FastFloat;
import kha.math.FastMatrix3;
import kha.math.FastMatrix4;
import kha.math.FastVector2;
import kha.math.FastVector3;
import kha.math.FastVector4;
import kha.graphics4.CubeMap;
import kha.graphics4.TextureAddressing;
import kha.graphics4.TextureFilter;
import kha.graphics4.MipMapFilter;
extern class Compute {
public static function setBool(location: ConstantLocation, value: Bool): Void;
public static function setInt(location: ConstantLocation, value: Int): Void;
public static function setFloat(location: ConstantLocation, value: FastFloat): Void;
public static function setFloat2(location: ConstantLocation, value1: FastFloat, value2: FastFloat): Void;
public static function setFloat3(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat): Void;
public static function setFloat4(location: ConstantLocation, value1: FastFloat, value2: FastFloat, value3: FastFloat, value4: FastFloat): Void;
public static function setFloats(location: ConstantLocation, values: Float32Array): Void;
public static function setVector2(location: ConstantLocation, value: FastVector2): Void;
public static function setVector3(location: ConstantLocation, value: FastVector3): Void;
public static function setVector4(location: ConstantLocation, value: FastVector4): Void;
public static function setMatrix(location: ConstantLocation, value: FastMatrix4): Void;
public static function setMatrix3(location: ConstantLocation, value: FastMatrix3): Void;
public static function setBuffer(buffer: ShaderStorageBuffer, index: Int): Void;
public static function setTexture(unit: TextureUnit, texture: Image, access: Access): Void;
public static function setSampledTexture(unit: TextureUnit, texture: Image): Void;
public static function setSampledDepthTexture(unit: TextureUnit, texture: Image): Void;
public static function setSampledCubeMap(unit: TextureUnit, cubeMap: CubeMap): Void;
public static function setSampledDepthCubeMap(unit: TextureUnit, cubeMap: CubeMap): Void;
public static function setTextureParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void;
public static function setTexture3DParameters(unit: TextureUnit, uAddressing: TextureAddressing, vAddressing: TextureAddressing,
wAddressing: TextureAddressing, minificationFilter: TextureFilter, magnificationFilter: TextureFilter, mipmapFilter: MipMapFilter): Void;
public static function setShader(shader: Shader): Void;
public static function compute(x: Int, y: Int, z: Int): Void;
}

View File

@ -0,0 +1,3 @@
package kha.compute;
interface ConstantLocation {}

View File

@ -0,0 +1,10 @@
package kha.compute;
import kha.Blob;
extern class Shader {
public function new(sources: Array<Blob>, files: Array<String>);
public function delete(): Void;
public function getConstantLocation(name: String): ConstantLocation;
public function getTextureUnit(name: String): TextureUnit;
}

View File

@ -0,0 +1,12 @@
package kha.compute;
import kha.graphics4.VertexData;
extern class ShaderStorageBuffer {
public function new(indexCount: Int, type: VertexData);
public function delete(): Void;
public function lock(): Array<Int>;
public function unlock(): Void;
public function set(): Void;
public function count(): Int;
}

View File

@ -0,0 +1,3 @@
package kha.compute;
interface TextureUnit {}

View File

@ -8,4 +8,5 @@ enum abstract TextureFormat(Int) to Int {
var RGBA64 = 4; // Half floats
var A32 = 5; // Float
var A16 = 6; // Half float
var R32UI = 7; // Unsigned 32-bit integer
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,7 @@ bl_info = {
"description": "Full Stack SDK",
"author": "Leenkx.com",
"version": (2026, 5, 0),
"blender": (4, 5, 0),
"blender": (5, 2, 0),
"doc_url": "https://leenkx.com/",
"tracker_url": "https://leenkx.com/support"
}

View File

@ -379,7 +379,7 @@ void main() {
#ifdef _SSGI
vec3 ssgiColor = textureLod(ssgitex, texCoord, 0.0).rgb;
fragColor.rgb += ssgiColor * albedo;
fragColor.rgb += ssgiColor * basecolor;
#endif
#ifdef _EmissionShadeless

View File

@ -28,10 +28,12 @@ in vec2 texCoord;
out vec4 fragColor;
const float GOLDEN_ANGLE = 2.39996323;
const int RAY_STEPS = 12;
const int RAY_STEPS = 6;
const int BINARY_STEPS = 3;
vec2 getProjectedCoord(const vec3 viewPos) {
vec4 projectedCoord = P * vec4(viewPos, 1.0);
if (projectedCoord.w <= 0.0) return vec2(-1e5);
projectedCoord.xy /= projectedCoord.w;
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
#ifdef _InvY
@ -40,16 +42,12 @@ vec2 getProjectedCoord(const vec3 viewPos) {
return projectedCoord.xy;
}
vec3 cosineSampleHemisphere(vec3 n, vec2 rand) {
float phi = PI * 2.0 * rand.x;
float cosTheta = sqrt(1.0 - rand.y);
float sinTheta = sqrt(rand.y);
vec3 h = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
vec3 tangent, bitangent;
float linearZ(const float depth) {
return -P[3].z / (depth + P[2].z);
}
void buildTBN(vec3 n, out vec3 tangent, out vec3 bitangent) {
vec3 absN = abs(n);
if (absN.x <= absN.y && absN.x <= absN.z) {
tangent = normalize(cross(n, vec3(1.0, 0.0, 0.0)));
} else if (absN.y <= absN.z) {
@ -58,46 +56,70 @@ vec3 cosineSampleHemisphere(vec3 n, vec2 rand) {
tangent = normalize(cross(n, vec3(0.0, 0.0, 1.0)));
}
bitangent = cross(n, tangent);
}
vec3 sampleHemisphere(vec3 n, vec3 tangent, vec3 bitangent, float phi, float cosTheta) {
float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
vec3 h = vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
return normalize(tangent * h.x + bitangent * h.y + n * h.z);
}
vec3 traceRay(vec3 origin, vec3 dir, float maxDist, float minDist) {
vec3 traceRay(vec3 origin, vec3 dir, float maxDist, float minDist, float jitter) {
float stepSize = maxDist / float(RAY_STEPS);
vec3 pos = origin + dir * minDist;
float rayDist = minDist + stepSize * (jitter - 1.0);
vec3 pos = origin + dir * rayDist;
float prevDepthDiff = 0.0;
float hadValidPrev = 0.0;
bool hasPrev = false;
for (int i = 1; i <= RAY_STEPS; i++) {
for (int i = 0; i < RAY_STEPS; i++) {
pos += dir * stepSize;
rayDist += stepSize;
vec2 uv = getProjectedCoord(pos);
if (uv.x < -100.0) return vec3(-1.0);
uv = clamp(uv, vec2(0.001), vec2(0.999));
vec2 sampleUV = clamp(uv, vec2(0.001), vec2(0.999));
float sampleDepth = textureLod(gbufferD, sampleUV, 0.0).r * 2.0 - 1.0;
float sampleDepth = textureLod(gbufferD, uv, 0.0).r * 2.0 - 1.0;
if (sampleDepth == 1.0) {
hadValidPrev = 0.0;
hasPrev = false;
continue;
}
float depthDiff = pos.z - linearZ(sampleDepth);
float thickness = maxDist * 0.075 + rayDist * 0.125;
vec3 sampleViewPos = getPosView2(invP, sampleDepth, sampleUV);
float depthDiff = pos.z - sampleViewPos.z;
float rayDist = length(pos - origin);
float thickness = 0.15 + rayDist * 0.25;
bool crossed = hasPrev && (prevDepthDiff > 0.0) && (depthDiff <= 0.0);
bool withinThickness = (depthDiff <= 0.0) && (-depthDiff < thickness);
float crossed = hadValidPrev * step(0.0, prevDepthDiff) * step(depthDiff, 0.0);
float withinThickness = step(abs(depthDiff), thickness);
if (crossed > 0.5 || withinThickness > 0.5) {
float distWeight = 1.0 - (rayDist / maxDist);
distWeight = max(0.0, distWeight * distWeight);
if (crossed || withinThickness) {
vec3 bPos = pos;
vec3 bDir = dir * stepSize;
for (int j = 0; j < BINARY_STEPS; j++) {
bDir *= 0.5;
bPos -= bDir;
vec2 bUV = getProjectedCoord(bPos);
bUV = clamp(bUV, vec2(0.001), vec2(0.999));
float bDepth = textureLod(gbufferD, bUV, 0.0).r * 2.0 - 1.0;
if (bDepth == 1.0) {
bPos += bDir;
continue;
}
if (bPos.z - linearZ(bDepth) > 0.0) bPos += bDir;
}
return vec3(sampleUV, distWeight);
vec2 bestUV = getProjectedCoord(bPos);
if (bestUV.x < -100.0) return vec3(-1.0);
bestUV = clamp(bestUV, vec2(0.001), vec2(0.999));
float hitDist = length(bPos - origin);
float distWeight = max(0.0, 1.0 - (hitDist / maxDist));
distWeight *= distWeight;
return vec3(bestUV, distWeight);
}
prevDepthDiff = depthDiff;
hadValidPrev = 1.0;
hasPrev = true;
}
return vec3(-1.0);
@ -111,77 +133,77 @@ void main() {
}
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0);
vec2 enc = g0.rg;
vec3 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
vec3 n = getNor(g0.rg);
vec3 basecolor = textureLod(gbuffer1, texCoord, 0.0).rgb;
vec3 viewNormal = V3 * n;
vec3 viewPos = getPosView2(invP, depth, texCoord);
#ifdef _CPostprocess
float radius = PPComp12.y;
float strength = PPComp12.x;
float radius = PPComp12.y * 2.0;
float strength = PPComp12.x * 0.5;
#else
float radius = ssgiRadius;
float strength = ssgiStrength;
float radius = ssgiRadius * 2.0;
float strength = ssgiStrength * 0.5;
#endif
float noise = fract(52.9829189 * fract(0.06711056 * texCoord.x * 1000.0 + 0.00583715 * texCoord.y * 1000.0));
radius = min(radius, max(-viewPos.z / P[1].y, 0.05));
float noise = fract(52.9829189 * fract(0.06711056 * gl_FragCoord.x + 0.00583715 * gl_FragCoord.y));
vec3 gi = vec3(0.0);
int validSamples = 0;
float missWeight = 0.0;
// min distance to avoid self shadowing artiffacts
float minDist = radius * 0.05;
vec3 tangent, bitangent;
buildTBN(viewNormal, tangent, bitangent);
for (int i = 0; i < ssgiSamples; i++) {
float fi = float(i) + noise;
vec2 rand = vec2(
fract(fi * 0.7548776662 + noise),
fract(fi * 0.5698402909 + noise * 1.5)
);
float phi = float(i) * GOLDEN_ANGLE + noise * PI2;
float cosTheta = sqrt(max(0.0, 1.0 - (float(i) + 0.5) / float(ssgiSamples)));
float jitter = fract(noise + float(i) * 0.618034);
vec3 rayDir = cosineSampleHemisphere(viewNormal, rand);
vec3 hitResult = traceRay(viewPos, rayDir, radius, minDist);
vec3 rayDir = sampleHemisphere(viewNormal, tangent, bitangent, phi, cosTheta);
vec3 hitResult = traceRay(viewPos, rayDir, radius, minDist, jitter);
if (hitResult.x < 0.0) continue;
if (hitResult.x < 0.0) {
missWeight += 1.0;
continue;
}
vec2 hitUV = hitResult.xy;
float distWeight = hitResult.z;
vec3 hitAlbedo = textureLod(gbuffer1, hitUV, 1.0).rgb;
vec3 hitN = getNor(textureLod(gbuffer0, hitUV, 0.0).rg);
float emitterCos = max(0.0, dot(V3 * hitN, -rayDir));
if (emitterCos <= 0.0) {
missWeight += 1.0;
continue;
}
vec3 hitAlbedo = textureLod(gbuffer1, hitUV, 0.0).rgb;
#ifdef _Sun
vec4 hitG0 = textureLod(gbuffer0, hitUV, 0.0);
vec2 hitEnc = hitG0.rg;
vec3 hitN;
hitN.z = 1.0 - abs(hitEnc.x) - abs(hitEnc.y);
hitN.xy = hitN.z >= 0.0 ? hitEnc.xy : octahedronWrap(hitEnc.xy);
hitN = normalize(hitN);
float hitNdotL = max(0.0, dot(hitN, sunDir));
vec3 hitRadiance = hitAlbedo * sunCol * hitNdotL;
vec3 hitRadiance = hitAlbedo * (sunCol * hitNdotL + vec3(0.4));
#else
vec3 hitRadiance = hitAlbedo * 0.5;
vec3 hitRadiance = hitAlbedo * 0.4;
#endif
#ifdef _EmissionShaded
hitRadiance += textureLod(gbufferEmission, hitUV, 0.0).rgb;
#endif
gi += hitRadiance * distWeight;
validSamples++;
gi += hitRadiance * (distWeight * emitterCos);
}
if (validSamples > 0) {
gi /= float(validSamples);
}
gi *= strength;
gi += basecolor * 0.1 * missWeight;
gi *= 2.0 * strength / float(ssgiSamples);
#ifdef _EmissionShaded
gi += textureLod(gbufferEmission, texCoord, 0.0).rgb * 0.3;
gi += textureLod(gbufferEmission, texCoord, 0.0).rgb * 0.3;
#endif
fragColor = vec4(min(gi, vec3(2.0)), 1.0);

View File

@ -110,7 +110,7 @@ vec4 traceCone(const sampler3D voxels, const sampler3D voxelsSDF, const vec3 ori
float diam = max(voxelSize0, dist * coneCoefficient);
float lod = clamp(log2(diam / voxelSize0), clipmap_index0, voxelgiClipmapCount - 1);
float clipmap_index = floor(lod);
float clipmap_blend = fract(lod);
float clipmap_blend = smoothstep(0.0, 1.0, fract(lod));
vec3 p0 = start_pos + dir * dist;
samplePos = (p0 - vec3(clipmaps[int(clipmap_index * 10 + 4)], clipmaps[int(clipmap_index * 10 + 5)], clipmaps[int(clipmap_index * 10 + 6)])) / (float(clipmaps[int(clipmap_index * 10)]) * voxelgiResolution);
@ -121,11 +121,17 @@ vec4 traceCone(const sampler3D voxels, const sampler3D voxelsSDF, const vec3 ori
continue;
}
// Edge fade: blend toward coarser clipmap near boundaries
vec3 edgeDist = min(samplePos, 1.0 - samplePos);
float minEdgeDist = min(min(edgeDist.x, edgeDist.y), edgeDist.z);
float edgeBlend = 1.0 - smoothstep(0.0, 0.1, minEdgeDist);
float totalBlend = max(clipmap_blend, edgeBlend);
mipSample = sampleVoxel(voxels, p0, clipmaps, clipmap_index, step_dist, precomputed_direction, face_offset, direction_weight);
if(clipmap_blend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
if(totalBlend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
vec4 mipSampleNext = sampleVoxel(voxels, p0, clipmaps, clipmap_index + 1.0, step_dist, precomputed_direction, face_offset, direction_weight);
mipSample = mix(mipSample, mipSampleNext, clipmap_blend);
mipSample = mix(mipSample, mipSampleNext, totalBlend);
}
sampleCol += (1.0 - sampleCol.a) * mipSample;
@ -148,9 +154,8 @@ vec4 traceCone(const sampler3D voxels, const sampler3D voxelsSDF, const vec3 ori
vec4 traceDiffuse(const vec3 origin, const vec3 normal, const sampler3D voxels, const float clipmaps[voxelgiClipmapCount * 10]) {
float sum = 0.0;
vec4 amount = vec4(0.0);
mat3 TBN = makeTangentBasis(normal);
for (int i = 0; i < DIFFUSE_CONE_COUNT; ++i) {
vec3 coneDir = TBN * DIFFUSE_CONE_DIRECTIONS[i];
vec3 coneDir = DIFFUSE_CONE_DIRECTIONS[i];
const float cosTheta = dot(normal, coneDir);
if (cosTheta <= 0)
continue;
@ -159,7 +164,7 @@ vec4 traceDiffuse(const vec3 origin, const vec3 normal, const sampler3D voxels,
sum += cosTheta;
}
amount /= sum;
amount /= max(sum, 0.0001);
amount.rgb = max(amount.rgb, vec3(0.0));
amount.a = clamp(amount.a, 0.0, 1.0);
@ -215,10 +220,10 @@ float traceConeAO(const sampler3D voxels, const vec3 origin, const vec3 n, const
float diam = max(voxelSize0, dist * coneCoefficient);
float lod = clamp(log2(diam / voxelSize0), clipmap_index0, voxelgiClipmapCount - 1);
float clipmap_index = floor(lod);
float clipmap_blend = fract(lod);
float clipmap_blend = smoothstep(0.0, 1.0, fract(lod));
vec3 p0 = start_pos + dir * dist;
samplePos = (p0 - vec3(clipmaps[int(clipmap_index * 10 + 4)], clipmaps[int(clipmap_index * 10 + 5)], clipmaps[int(clipmap_index * 10 + 6)])) / (float(clipmaps[int(clipmap_index * 10)]) * voxelgiResolution.x);
samplePos = (p0 - vec3(clipmaps[int(clipmap_index * 10 + 4)], clipmaps[int(clipmap_index * 10 + 5)], clipmaps[int(clipmap_index * 10 + 6)])) / (float(clipmaps[int(clipmap_index * 10)]) * voxelgiResolution);
samplePos = samplePos * 0.5 + 0.5;
if ((any(notEqual(clamp(samplePos, 0.0, 1.0), samplePos)))) {
@ -226,11 +231,17 @@ float traceConeAO(const sampler3D voxels, const vec3 origin, const vec3 n, const
continue;
}
// Edge fade: blend toward coarser clipmap near boundaries
vec3 edgeDist = min(samplePos, 1.0 - samplePos);
float minEdgeDist = min(min(edgeDist.x, edgeDist.y), edgeDist.z);
float edgeBlend = 1.0 - smoothstep(0.0, 0.1, minEdgeDist);
float totalBlend = max(clipmap_blend, edgeBlend);
mipSample = sampleVoxel(voxels, p0, clipmaps, clipmap_index, step_dist, precomputed_direction, face_offset, direction_weight);
if(clipmap_blend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
if(totalBlend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
float mipSampleNext = sampleVoxel(voxels, p0, clipmaps, clipmap_index + 1.0, step_dist, precomputed_direction, face_offset, direction_weight);
mipSample = mix(mipSample, mipSampleNext, clipmap_blend);
mipSample = mix(mipSample, mipSampleNext, totalBlend);
}
sampleCol += (1.0 - sampleCol) * mipSample;
@ -254,7 +265,7 @@ float traceAO(const vec3 origin, const vec3 normal, const sampler3D voxels, cons
amount += traceConeAO(voxels, origin, normal, coneDir, precomputed_direction, DIFFUSE_CONE_APERTURE, 1.0, clipmaps) * cosTheta;
sum += cosTheta;
}
amount /= sum;
amount /= max(sum, 0.0001);
amount = clamp(amount, 0.0, 1.0);
return amount * voxelgiOcc;
}
@ -284,7 +295,7 @@ float traceConeShadow(const sampler3D voxels, const sampler3D voxelsSDF, const v
float diam = max(voxelSize0, dist * coneCoefficient);
float lod = clamp(log2(diam / voxelSize0), clipmap_index0, voxelgiClipmapCount - 1);
float clipmap_index = floor(lod);
float clipmap_blend = fract(lod);
float clipmap_blend = smoothstep(0.0, 1.0, fract(lod));
vec3 p0 = start_pos + dir * dist;
samplePos = (p0 - vec3(clipmaps[int(clipmap_index * 10 + 4)], clipmaps[int(clipmap_index * 10 + 5)], clipmaps[int(clipmap_index * 10 + 6)])) / (float(clipmaps[int(clipmap_index * 10)]) * voxelgiResolution);
@ -295,19 +306,25 @@ float traceConeShadow(const sampler3D voxels, const sampler3D voxelsSDF, const v
continue;
}
// Edge fade: blend toward coarser clipmap near boundaries
vec3 edgeDist = min(samplePos, 1.0 - samplePos);
float minEdgeDist = min(min(edgeDist.x, edgeDist.y), edgeDist.z);
float edgeBlend = 1.0 - smoothstep(0.0, 0.1, minEdgeDist);
float totalBlend = max(clipmap_blend, edgeBlend);
#ifdef _VoxelAOvar
mipSample = sampleVoxel(voxels, p0, clipmaps, clipmap_index, step_dist, 0, face_offset, direction_weight);
#else
mipSample = sampleVoxel(voxels, p0, clipmaps, clipmap_index, step_dist, 0, face_offset, direction_weight).a;
#endif
if(clipmap_blend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
if(totalBlend > 0.0 && clipmap_index < voxelgiClipmapCount - 1) {
#ifdef _VoxelAOvar
float mipSampleNext = sampleVoxel(voxels, p0, clipmaps, clipmap_index + 1.0, step_dist, 0, face_offset, direction_weight);
#else
float mipSampleNext = sampleVoxel(voxels, p0, clipmaps, clipmap_index + 1.0, step_dist, 0, face_offset, direction_weight).a;
#endif
mipSample = mix(mipSample, mipSampleNext, clipmap_blend);
mipSample = mix(mipSample, mipSampleNext, totalBlend);
}
sampleCol += (1.0 - sampleCol) * mipSample;

View File

@ -24,42 +24,25 @@ const int DIFFUSE_CONE_COUNT = 16;
const float SHADOW_CONE_APERTURE = radians(15.0);
const float DIFFUSE_CONE_APERTURE = 0.872665;
const float DIFFUSE_CONE_APERTURE = 1.0;
mat3 makeTangentBasis(const vec3 normal) {
// Create a tangent basis from normal vector
vec3 tangent;
vec3 bitangent;
// Compute tangent (Frisvad's method)
if (abs(normal.z) < 0.999) {
tangent = normalize(cross(vec3(0, 1, 0), normal));
} else {
tangent = normalize(cross(normal, vec3(1, 0, 0)));
}
bitangent = cross(normal, tangent);
return mat3(tangent, bitangent, normal);
}
// 16 optimized cone directions for hemisphere sampling (Z-up, normalized)
const vec3 DIFFUSE_CONE_DIRECTIONS[16] = vec3[](
vec3(0.707107, 0.000000, 0.707107), // Front
vec3(-0.707107, 0.000000, 0.707107), // Back
vec3(0.000000, 0.707107, 0.707107), // Right
vec3(0.000000, -0.707107, 0.707107), // Left
vec3(0.500000, 0.500000, 0.707107), // Front-right
vec3(-0.500000, 0.500000, 0.707107), // Back-right
vec3(0.500000, -0.500000, 0.707107), // Front-left
vec3(-0.500000, -0.500000, 0.707107),// Back-left
vec3(0.353553, 0.000000, 0.935414), // Narrow front
vec3(-0.353553, 0.000000, 0.935414), // Narrow back
vec3(0.000000, 0.353553, 0.935414), // Narrow right
vec3(0.000000, -0.353553, 0.935414), // Narrow left
vec3(0.270598, 0.270598, 0.923880), // Narrow front-right
vec3(-0.270598, 0.270598, 0.923880), // Narrow back-right
vec3(0.270598, -0.270598, 0.923880), // Narrow front-left
vec3(-0.270598, -0.270598, 0.923880) // Narrow back-left
vec3( 0.3480, 0.0000, 0.9375),
vec3(-0.4299, 0.3938, 0.8125),
vec3( 0.0635, -0.7234, 0.6875),
vec3( 0.5031, 0.6561, 0.5625),
vec3(-0.8855, -0.1566, 0.4375),
vec3( 0.8015, -0.5098, 0.3125),
vec3(-0.2550, 0.9486, 0.1875),
vec3(-0.4600, -0.8857, 0.0625),
vec3( 0.9375, 0.3424, -0.0625),
vec3(-0.9080, 0.3748, -0.1875),
vec3( 0.4026, -0.8604, -0.3125),
vec3( 0.2691, 0.8580, -0.4375),
vec3(-0.7154, -0.4146, -0.5625),
vec3( 0.7092, -0.1559, -0.6875),
vec3(-0.3353, 0.4769, -0.8125),
vec3(-0.0447, -0.3451, -0.9375)
);
// TO DO - Disabled momentarily instead of changing formulas

View File

@ -1,11 +1,11 @@
/* Various sky functions
* =====================
*
* Nishita model is based on https://github.com/wwwtyro/glsl-atmosphere (Unlicense License)
* Single scattering model is based on https://github.com/wwwtyro/glsl-atmosphere (Unlicense License)
*
* Changes to the original implementation:
* - r and pSun parameters of nishita_atmosphere() are already normalized
* - Some original parameters of nishita_atmosphere() are replaced with pre-defined values
* - r and pSun parameters of single_scatter_atmosphere() are already normalized
* - Some original parameters of single_scatter_atmosphere() are replaced with pre-defined values
* - Implemented air, dust and ozone density node parameters (see Blender source)
* - Replaced the inner integral calculation with a LUT lookup
*
@ -22,8 +22,8 @@
#include "std/math.glsl"
uniform sampler2D nishitaLUT;
uniform vec2 nishitaDensity;
uniform sampler2D singleScatterLUT;
uniform vec2 skyDensity;
#ifndef PI
#define PI 3.141592
@ -32,33 +32,33 @@ uniform vec2 nishitaDensity;
#define HALF_PI 1.570796
#endif
#define nishita_iSteps 16
#define single_scatter_iSteps 16
// These values are taken from Cycles code if they
// exist there, otherwise they are taken from the example
// in the glsl-atmosphere repo
#define nishita_sun_intensity 22.0
#define nishita_atmo_radius 6420e3
#define nishita_rayleigh_scale 8e3
#define nishita_rayleigh_coeff vec3(5.5e-6, 13.0e-6, 22.4e-6)
#define nishita_mie_scale 1.2e3
#define nishita_mie_coeff 2e-5
#define nishita_mie_dir 0.76 // Aerosols anisotropy ("direction")
#define nishita_mie_dir_sq 0.5776 // Squared aerosols anisotropy
#define single_scatter_sun_intensity 22.0
#define single_scatter_atmo_radius 6420e3
#define single_scatter_rayleigh_scale 8e3
#define single_scatter_rayleigh_coeff vec3(5.5e-6, 13.0e-6, 22.4e-6)
#define single_scatter_mie_scale 1.2e3
#define single_scatter_mie_coeff 2e-5
#define single_scatter_mie_dir 0.76 // Aerosols anisotropy ("direction")
#define single_scatter_mie_dir_sq 0.5776 // Squared aerosols anisotropy
// Values from [Hill: 60]
#define sun_limb_darkening_col vec3(0.397, 0.503, 0.652)
vec3 nishita_lookupLUT(const float height, const float sunTheta) {
vec3 single_scatter_lookupLUT(const float height, const float sunTheta) {
vec2 coords = vec2(
sqrt(height * (1 / nishita_atmo_radius)),
sqrt(height * (1 / single_scatter_atmo_radius)),
0.5 + 0.5 * sign(sunTheta - HALF_PI) * sqrt(abs(sunTheta * (1 / HALF_PI) - 1))
);
return textureLod(nishitaLUT, coords, 0.0).rgb;
return textureLod(singleScatterLUT, coords, 0.0).rgb;
}
/* See raySphereIntersection() in leenkx/Sources/renderpath/Nishita.hx */
vec2 nishita_rsi(const vec3 r0, const vec3 rd, const float sr) {
/* See raySphereIntersection() in leenkx/Sources/renderpath/Sky.hx */
vec2 single_scatter_rsi(const vec3 r0, const vec3 rd, const float sr) {
float a = dot(rd, rd);
float b = 2.0 * dot(rd, r0);
float c = dot(r0, r0) - (sr * sr);
@ -74,12 +74,12 @@ vec2 nishita_rsi(const vec3 r0, const vec3 rd, const float sr) {
* pSun: normalized sun direction
* rPlanet: planet radius
*/
vec3 nishita_atmosphere(const vec3 r, const vec3 r0, const vec3 pSun, const float rPlanet) {
vec3 single_scatter_atmosphere(const vec3 r, const vec3 r0, const vec3 pSun, const float rPlanet) {
// Calculate the step size of the primary ray
vec2 p = nishita_rsi(r0, r, nishita_atmo_radius);
vec2 p = single_scatter_rsi(r0, r, single_scatter_atmo_radius);
if (p.x > p.y) return vec3(0.0);
p.y = min(p.y, nishita_rsi(r0, r, rPlanet).x);
float iStepSize = (p.y - p.x) / float(nishita_iSteps);
p.y = min(p.y, single_scatter_rsi(r0, r, rPlanet).x);
float iStepSize = (p.y - p.x) / float(single_scatter_iSteps);
// Primary ray time
float iTime = 0.0;
@ -96,18 +96,18 @@ vec3 nishita_atmosphere(const vec3 r, const vec3 r0, const vec3 pSun, const floa
float mu = dot(r, pSun);
float mumu = mu * mu;
float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);
float pMie = 3.0 / (8.0 * PI) * ((1.0 - nishita_mie_dir_sq) * (mumu + 1.0)) / (pow(1.0 + nishita_mie_dir_sq - 2.0 * mu * nishita_mie_dir, 1.5) * (2.0 + nishita_mie_dir_sq));
float pMie = 3.0 / (8.0 * PI) * ((1.0 - single_scatter_mie_dir_sq) * (mumu + 1.0)) / (pow(1.0 + single_scatter_mie_dir_sq - 2.0 * mu * single_scatter_mie_dir, 1.5) * (2.0 + single_scatter_mie_dir_sq));
// Sample the primary ray
for (int i = 0; i < nishita_iSteps; i++) {
for (int i = 0; i < single_scatter_iSteps; i++) {
// Calculate the primary ray sample position and height
vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);
float iHeight = length(iPos) - rPlanet;
// Calculate the optical depth of the Rayleigh and Mie scattering for this step
float odStepRlh = exp(-iHeight / nishita_rayleigh_scale) * nishitaDensity.x * iStepSize;
float odStepMie = exp(-iHeight / nishita_mie_scale) * nishitaDensity.y * iStepSize;
float odStepRlh = exp(-iHeight / single_scatter_rayleigh_scale) * skyDensity.x * iStepSize;
float odStepMie = exp(-iHeight / single_scatter_mie_scale) * skyDensity.y * iStepSize;
// Accumulate optical depth
iOdRlh += odStepRlh;
@ -116,12 +116,12 @@ vec3 nishita_atmosphere(const vec3 r, const vec3 r0, const vec3 pSun, const floa
// Idea behind this: "Rotate" everything by iPos (-> iPos is the new zenith) and then all calculations for the
// inner integral only depend on the sample height (iHeight) and sunTheta (angle between sun and new zenith).
float sunTheta = safe_acos(dot(normalize(iPos), normalize(pSun)));
vec3 jAttn = nishita_lookupLUT(iHeight, sunTheta);
vec3 jAttn = single_scatter_lookupLUT(iHeight, sunTheta);
// Calculate attenuation
vec3 iAttn = exp(-(
nishita_mie_coeff * iOdMie
+ nishita_rayleigh_coeff * iOdRlh
single_scatter_mie_coeff * iOdMie
+ single_scatter_rayleigh_coeff * iOdRlh
// + 0 for ozone
));
vec3 attn = iAttn * jAttn;
@ -136,7 +136,7 @@ vec3 nishita_atmosphere(const vec3 r, const vec3 r0, const vec3 pSun, const floa
iTime += iStepSize;
}
return nishita_sun_intensity * (pRlh * nishita_rayleigh_coeff * totalRlh + pMie * nishita_mie_coeff * totalMie);
return single_scatter_sun_intensity * (pRlh * single_scatter_rayleigh_coeff * totalRlh + pMie * single_scatter_mie_coeff * totalMie);
}
vec3 sun_disk(const vec3 n, const vec3 light_dir, const float disk_size, const float intensity) {
@ -149,7 +149,83 @@ vec3 sun_disk(const vec3 n, const vec3 light_dir, const float disk_size, const f
float mu = sqrt(invDist * invDist);
vec3 limb_darkening = 1.0 - (1.0 - pow(vec3(mu), sun_limb_darkening_col));
return 1 + (1.0 - step(1.0, dist)) * nishita_sun_intensity * intensity * limb_darkening;
return 1 + (1.0 - step(1.0, dist)) * single_scatter_sun_intensity * intensity * limb_darkening;
}
uniform sampler2D multiScatterLUT;
uniform vec4 multiScatterParams; // x=elevation, y=rotation, z=angular_diameter, w=intensity
uniform vec4 multiScatterSunBottom; // xyz=sun_bottom, w=earth_intersection_angle
uniform vec3 multiScatterSunTop;
// XYZ to sRGB/Rec.709 conversion (D65 white point)
vec3 xyz_to_rgb(vec3 xyz) {
return vec3(
3.2406 * xyz.x - 1.5372 * xyz.y - 0.4986 * xyz.z,
-0.9689 * xyz.x + 1.8758 * xyz.y + 0.0415 * xyz.z,
0.0557 * xyz.x - 0.2040 * xyz.y + 1.0570 * xyz.z
);
}
float sky_elevation_to_v(float elevation) {
float abs_el = abs(elevation);
float l = sign(elevation) * sqrt(abs_el / 1.5707963);
float v = (l + 1.0) * 0.5;
return clamp(v, 0.0, 1.0);
}
vec3 multi_scatter_sample_lut(vec3 dir, float sun_rotation) {
float azimuth = atan(dir.x, dir.y);
float elevation = asin(clamp(dir.z, -1.0, 1.0));
azimuth -= sun_rotation;
float u = fract(azimuth / (2.0 * PI));
float v = sky_elevation_to_v(elevation);
return textureLod(multiScatterLUT, vec2(u, v), 0.0).rgb;
}
vec3 multi_scatter_sun_disc(vec3 dir, vec3 sun_dir, float angular_diameter, float intensity) {
float half_diameter = max(angular_diameter * 0.5, 0.0005);
float dist = distance(dir, sun_dir) / half_diameter;
float edge = smoothstep(1.0, 0.95, dist);
if (edge <= 0.0) return vec3(0.0);
float horizon = multiScatterSunBottom.w;
float dir_elev = asin(clamp(dir.z, -1.0, 1.0));
float horizon_fade = smoothstep(horizon - half_diameter * 0.1, horizon + half_diameter * 0.1, dir_elev);
edge *= horizon_fade;
if (edge <= 0.0) return vec3(0.0);
float invDist = 1.0 - dist;
float mu = sqrt(invDist * invDist);
vec3 limb_darkening = 1.0 - (1.0 - pow(vec3(mu), sun_limb_darkening_col));
float sun_elev = multiScatterParams.x;
float t = clamp((dir_elev - (sun_elev - half_diameter)) / (2.0 * half_diameter), 0.0, 1.0);
vec3 sun_color = mix(multiScatterSunBottom.rgb, multiScatterSunTop, t) * intensity * limb_darkening;
return xyz_to_rgb(sun_color) * edge;
}
vec3 multi_scatter_atmosphere(vec3 dir) {
float sun_elevation = multiScatterParams.x;
float sun_rotation = multiScatterParams.y;
float angular_diameter = multiScatterParams.z;
float sun_intensity = multiScatterParams.w;
vec3 xyz = multi_scatter_sample_lut(dir, sun_rotation);
vec3 radiance = xyz_to_rgb(xyz);
if (sun_intensity > 0.0) {
vec3 computed_sun_dir = vec3(
sin(sun_rotation) * cos(sun_elevation),
cos(sun_rotation) * cos(sun_elevation),
sin(sun_elevation)
);
radiance += multi_scatter_sun_disc(dir, computed_sun_dir, angular_diameter, sun_intensity);
}
return radiance;
}
#endif

View File

@ -1,136 +0,0 @@
#version 450
layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
#include "compiled.inc"
#include "std/math.glsl"
#include "std/gbuffer.glsl"
#include "std/imageatomic.glsl"
#ifdef _VoxelShadow
#include "std/conetrace.glsl"
#endif
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform int lightType;
uniform vec3 lightDir;
uniform vec2 spotData;
#ifdef _ShadowMap
uniform int lightShadow;
uniform vec2 lightProj;
uniform float shadowsBias;
uniform mat4 LVP;
#ifdef _ShadowMapAtlas
uniform int index;
uniform vec4 pointLightDataArray[maxLightsCluster * 6];
#endif
#endif
uniform float clipmaps[voxelgiClipmapCount * 10];
uniform int clipmapLevel;
uniform layout(r32ui) uimage3D voxelsLight;
#ifdef _ShadowMap
uniform sampler2DShadow shadowMap;
uniform sampler2D shadowMapTransparent;
uniform sampler2DShadow shadowMapSpot;
#ifdef _ShadowMapAtlas
uniform sampler2DShadow shadowMapPoint;
#else
uniform samplerCubeShadow shadowMapPoint;
#endif
#endif
#ifdef _ShadowMapAtlas
// https://www.khronos.org/registry/OpenGL/specs/gl/glspec20.pdf // p:168
// https://www.gamedev.net/forums/topic/687535-implementing-a-cube-map-lookup-function/5337472/
vec2 sampleCube(vec3 dir, out int faceIndex) {
vec3 dirAbs = abs(dir);
float ma;
vec2 uv;
if(dirAbs.z >= dirAbs.x && dirAbs.z >= dirAbs.y) {
faceIndex = dir.z < 0.0 ? 5 : 4;
ma = 0.5 / dirAbs.z;
uv = vec2(dir.z < 0.0 ? -dir.x : dir.x, -dir.y);
}
else if(dirAbs.y >= dirAbs.x) {
faceIndex = dir.y < 0.0 ? 3 : 2;
ma = 0.5 / dirAbs.y;
uv = vec2(dir.x, dir.y < 0.0 ? -dir.z : dir.z);
}
else {
faceIndex = dir.x < 0.0 ? 1 : 0;
ma = 0.5 / dirAbs.x;
uv = vec2(dir.x < 0.0 ? dir.z : -dir.z, -dir.y);
}
// downscale uv a little to hide seams
// transform coordinates from clip space to texture space
#ifndef _FlipY
return uv * 0.9976 * ma + 0.5;
#else
#ifdef HLSL
return uv * 0.9976 * ma + 0.5;
#else
return vec2(uv.x * ma, uv.y * -ma) * 0.9976 + 0.5;
#endif
#endif
}
#endif
float lpToDepth(vec3 lp, const vec2 lightProj) {
lp = abs(lp);
float zcomp = max(lp.x, max(lp.y, lp.z));
zcomp = lightProj.x - lightProj.y / zcomp;
return zcomp * 0.5 + 0.5;
}
void main() {
int res = voxelgiResolution.x;
ivec3 dst = ivec3(gl_GlobalInvocationID.xyz);
vec3 wposition = (gl_GlobalInvocationID.xyz + 0.5) / voxelgiResolution.x;
wposition = wposition * 2.0 - 1.0;
wposition *= float(clipmaps[int(clipmapLevel * 10)]);
wposition *= voxelgiResolution.x;
wposition += vec3(clipmaps[clipmapLevel * 10 + 4], clipmaps[clipmapLevel * 10 + 5], clipmaps[clipmapLevel * 10 + 6]);
float visibility;
vec3 lp = lightPos - wposition;
vec3 l;
if (lightType == 0) { l = lightDir; visibility = 1.0; }
else { l = normalize(lp); visibility = attenuate(distance(wposition, lightPos)); }
#ifdef _ShadowMap
if (lightShadow == 1) {
vec4 lightPosition = LVP * vec4(wposition, 1.0);
vec3 lPos = lightPosition.xyz / lightPosition.w;
visibility *= texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;
}
else if (lightShadow == 2) {
vec4 lightPosition = LVP * vec4(wposition, 1.0);
vec3 lPos = lightPosition.xyz / lightPosition.w;
visibility *= texture(shadowMapSpot, vec3(lPos.xy, lPos.z - shadowsBias)).r;
}
else if (lightShadow == 3) {
#ifdef _ShadowMapAtlas
int faceIndex = 0;
const int lightIndex = index * 6;
const vec2 uv = sampleCube(-l, faceIndex);
vec4 pointLightTile = pointLightDataArray[lightIndex + faceIndex]; // x: tile X offset, y: tile Y offset, z: tile size relative to atlas
vec2 uvtiled = pointLightTile.z * uv + pointLightTile.xy;
#ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif
visibility *= texture(shadowMapPoint, vec3(uvtiled, lpToDepth(lp, lightProj) - shadowsBias)).r;
#else
visibility *= texture(shadowMapPoint, vec4(-l, lpToDepth(lp, lightProj) - shadowsBias)).r;
#endif
}
#endif
vec3 light = visibility * lightColor;
imageAtomicAdd(voxelsLight, dst, uint(light.r * 255));
imageAtomicAdd(voxelsLight, dst + ivec3(0, 0, voxelgiResolution.x), uint(light.g * 255));
imageAtomicAdd(voxelsLight, dst + ivec3(0, 0, voxelgiResolution.x * 2), uint(light.b * 255));
}

View File

@ -43,7 +43,6 @@ uniform mat4 LVP;
#endif
uniform sampler3D voxelsSampler;
uniform layout(r32ui) uimage3D voxels;
uniform layout(r32ui) uimage3D voxelsLight;
uniform layout(rgba8) image3D voxelsB;
uniform layout(rgba8) image3D voxelsOut;
uniform layout(r8) image3D SDF;
@ -75,21 +74,13 @@ void main() {
#endif
#ifdef _VoxelGI
vec3 light = vec3(0.0);
light.r = float(imageLoad(voxelsLight, ivec3(gl_GlobalInvocationID.xyz)).r) / 255;
light.g = float(imageLoad(voxelsLight, ivec3(gl_GlobalInvocationID.xyz) + ivec3(0, 0, voxelgiResolution.x)).r) / 255;
light.b = float(imageLoad(voxelsLight, ivec3(gl_GlobalInvocationID.xyz) + ivec3(0, 0, voxelgiResolution.x * 2)).r) / 255;
light /= 3;
vec4 aniso_colors[6];
#else
float aniso_colors[6];
#endif
for (int i = 0; i < 6 + DIFFUSE_CONE_COUNT; i++)
{
#ifdef _VoxelGI
vec4 aniso_colors[6];
#else
float aniso_colors[6];
#endif
ivec3 src = ivec3(gl_GlobalInvocationID.xyz);
src.x += i * res;
ivec3 dst = src;
@ -103,30 +94,37 @@ void main() {
if (i < 6) {
#ifdef _VoxelGI
uint count = imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 15)).r;
if (count > 0) {
vec4 basecol = vec4(0.0);
basecol.r = float(imageLoad(voxels, src)) / 255;
basecol.g = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x))) / 255;
basecol.b = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 2))) / 255;
basecol.a = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 3))) / 255;
basecol /= 4;
basecol /= count;
vec3 emission = vec3(0.0);
emission.r = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 4))) / 255;
emission.g = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 5))) / 255;
emission.b = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 6))) / 255;
emission /= 3;
emission /= count;
vec3 N = vec3(0.0);
N.r = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 7))) / 255;
N.g = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 8))) / 255;
N /= 2;
N /= count;
vec3 wnormal = decode_oct(N.rg * 2 - 1);
vec3 envl = vec3(0.0);
envl.r = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 9))) / 255;
envl.g = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 10))) / 255;
envl.b = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 11))) / 255;
envl /= 3;
envl /= count;
#ifdef _HOSEK
envl *= 100;
#endif
vec3 light = vec3(0.0);
light.r = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 12))) / 255;
light.g = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 13))) / 255;
light.b = float(imageLoad(voxels, src + ivec3(0, 0, voxelgiResolution.x * 14))) / 255;
light /= count;
//clipmap to world
vec3 wposition = (gl_GlobalInvocationID.xyz + 0.5) / voxelgiResolution.x;
@ -140,6 +138,7 @@ void main() {
vec3 indirect = trace.rgb + envl.rgb * (1.0 - trace.a);
radiance.rgb *= light.rgb + indirect.rgb;
radiance.rgb += emission.rgb;
}
#else
opac = float(imageLoad(voxels, src)) / 255;

View File

@ -88,58 +88,103 @@ vec4 rayCast(vec3 dir) {
}
#endif //SSR
vec3 sampleWaterNormals(vec2 hitXY, float speed, out vec2 tcnor0, out vec2 tcnor1) {
tcnor0 = hitXY / 3.0;
vec3 n0 = textureLod(sdetail, tcnor0 + vec2(speed / 60.0, speed / 120.0), 0.0).rgb;
tcnor1 = hitXY / 6.0 + n0.xy / 20.0;
vec3 n1 = textureLod(sbase, tcnor1 + vec2(speed / 40.0, speed / 80.0), 0.0).rgb;
return normalize(n0 + n1 - 1.0);
}
void main() {
float gdepth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
if (gdepth == 1.0) {
fragColor = vec4(0.0);
return;
}
// Eye below water
if (eye.z < waterLevel) {
fragColor = vec4(0.0);
return;
}
// Displace surface
vec3 vray = normalize(viewRay);
vec3 p = getPos(eye, eyeLook, vray, gdepth, cameraProj);
float speed = time * 2.0 * waterSpeed;
p.z += sin(p.x * 10.0 / waterDisplace + speed) * cos(p.y * 10.0 / waterDisplace + speed) / 50.0 * waterDisplace;
bool isSky = (gdepth == 1.0);
// Ray-plane intersection with water surface (z = waterLevel)
float denom = dot(vray, vec3(0.0, 0.0, 1.0));
float tWater = (waterLevel - eye.z) / denom;
bool hasWaterHit = (abs(denom) > 0.0001) && (tWater > 0.0);
if (eye.z < waterLevel) {
vec2 tc = texCoord;
float fogFactor;
if (hasWaterHit && denom > 0.0) {
// Looking up at water surface - apply normal distortion
vec3 hit = eye + tWater * vray;
vec2 tc0, tc1;
vec3 n2 = sampleWaterNormals(hit.xy * waterFreq, speed, tc0, tc1);
tc = texCoord + (n2.xy * n2.z) / 30.0 * waterRefract;
fogFactor = clamp(tWater * waterDensity, 0.0, 0.95);
} else {
// Looking forward/down - distort via water surface above fragment
vec3 p = getPos(eye, eyeLook, vray, gdepth, cameraProj);
vec2 wxy = isSky ? (eye.xy + vray.xy * 50.0) : p.xy;
vec2 tc0, tc1;
vec3 n2 = sampleWaterNormals(wxy * waterFreq, speed, tc0, tc1);
tc = texCoord + (n2.xy * n2.z) / 30.0 * waterRefract;
float waterDist = isSky ? 50.0 : length(p - eye);
fogFactor = clamp(waterDist * waterDensity, 0.0, 0.95);
}
vec3 refracted = textureLod(tex, tc, 0.0).rgb;
fragColor.rgb = mix(refracted, waterColor, fogFactor);
fragColor.a = 1.0;
return;
}
// Above water
if (p.z > waterLevel) {
if (!hasWaterHit || denom >= 0.0) {
fragColor = vec4(0.0);
return;
}
if (isSky) tWater = min(tWater, 100.0); // Clamp to prevent aliasing at horizon
vec3 p = isSky ? (eye + tWater * vray) : getPos(eye, eyeLook, vray, gdepth, cameraProj);
float horizonFactor = clamp(1.0 - tWater / 60.0, 0.0, 1.0);
if (!isSky && p.z > waterLevel) {
fragColor = vec4(0.0);
return;
}
// Displace surface
p.z += (sin(p.x * 10.0 / waterDisplace + speed) * cos(p.y * 10.0 / waterDisplace + speed)
+ sin(p.x * 20.0 / waterDisplace + speed * 1.3) * cos(p.y * 20.0 / waterDisplace + speed * 1.3) * 0.5)
/ 50.0 * waterDisplace;
// Hit plane to determine uvs
vec3 v = normalize(eye - p.xyz);
float t = -(dot(eye, vec3(0.0, 0.0, 1.0)) - waterLevel) / dot(v, vec3(0.0, 0.0, 1.0));
vec3 v = normalize(eye - p);
float t = (waterLevel - eye.z) / dot(v, vec3(0.0, 0.0, 1.0));
vec3 hit = eye + t * v;
hit.xy *= waterFreq;
hit.z += waterLevel;
// Sample normal maps
vec2 tcnor0 = hit.xy / 3.0;
vec3 n0 = textureLod(sdetail, tcnor0 + vec2(speed / 60.0, speed / 120.0), 0.0).rgb;
vec2 tcnor0, tcnor1;
vec3 n2 = sampleWaterNormals(hit.xy * waterFreq, speed, tcnor0, tcnor1);
vec2 tcnor1 = hit.xy / 6.0 + n0.xy / 20.0;
vec3 n1 = textureLod(sbase, tcnor1 + vec2(speed / 40.0, speed / 80.0), 0.0).rgb;
vec3 n2 = normalize(((n1 + n0) / 2.0) * 2.0 - 1.0);
float ddepth = textureLod(gbufferD, texCoord + (n2.xy * n2.z) / 40.0, 0.0).r * 2.0 - 1.0;
vec3 p2 = getPos(eye, eyeLook, vray, ddepth, cameraProj);
vec2 tc = p2.z > waterLevel ? texCoord : texCoord + (n2.xy * n2.z) / 30.0 * waterRefract;
// Refraction
vec2 tc;
if (isSky) {
tc = texCoord + (n2.xy * n2.z) / 30.0 * waterRefract;
} else {
float ddepth = textureLod(gbufferD, texCoord + (n2.xy * n2.z) / 40.0, 0.0).r * 2.0 - 1.0;
vec3 p2 = getPos(eye, eyeLook, vray, ddepth, cameraProj);
tc = p2.z > waterLevel ? texCoord : texCoord + (n2.xy * n2.z) / 30.0 * waterRefract;
}
// Light
float fresnel = 1.0 - max(dot(n2, v), 0.0);
fresnel = pow(fresnel, 30.0) * 0.45;
fresnel = 0.02 + 0.98 * pow(fresnel, 5.0);
vec3 r = reflect(-v, n2);
#ifdef _Rad
vec3 reflectedEnv = textureLod(senvmapRadiance, envMapEquirect(r), 0).rgb;
vec3 reflectedEnv = textureLod(senvmapRadiance, envMapEquirect(r), 0).rgb;
#else
const vec3 reflectedEnv = vec3(0.5);
#endif
vec3 refracted = textureLod(tex, tc, 0.0).rgb;
#ifdef _SSR
float roughness = 0.1;//unpackFloat(g0.b).y;
//if (roughness == 1.0) { fragColor.rgb = vec3(0.0); return; }
@ -147,8 +192,8 @@ void main() {
float spec = 0.9;//fract(textureLod(gbuffer1, texCoord, 0.0).a);
//if (spec == 0.0) { fragColor.rgb = vec3(0.0); return; }
vec3 viewNormal = n2;
vec3 viewPos = getPosView(viewRay, gdepth, cameraProj);
vec3 viewNormal = V3 * n2;
vec3 viewPos = isSky ? vec3(0.0) : getPosView(viewRay, gdepth, cameraProj);
vec3 reflected = reflect(normalize(viewPos), viewNormal);
hitCoord = viewPos;
@ -158,7 +203,6 @@ void main() {
vec3 dir = reflected * (1.0 - rand(texCoord) * ssrJitter * roughness) * 2.0;
#endif
// * max(ssrMinRayStep, -viewPos.z)
vec4 coords = rayCast(dir);
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
@ -177,20 +221,32 @@ void main() {
#else
fragColor.rgb = mix(refracted, reflectedEnv, waterReflect * fresnel);
#endif
fragColor.rgb *= waterColor;
fragColor.rgb += clamp(pow(max(dot(r, ld), 0.0), 200.0) * (200.0 + 8.0) / (PI * 8.0), 0.0, 2.0);
fragColor.rgb *= 1.0 - (clamp(-(p.z - waterLevel) * waterDensity, 0.0, 0.9));
fragColor.a = clamp(abs(p.z - waterLevel) * 5.0, 0.0, 1.0);
// Water color tint - blend rather than multiply to preserve brightness
float colorMix = isSky ? 0.7 : 0.5;
fragColor.rgb = mix(fragColor.rgb, fragColor.rgb * waterColor, colorMix * horizonFactor);
// Blinn-Phong specular using half-vector, faded at horizon
vec3 h = normalize(v + ld);
float specAmount = pow(max(dot(n2, h), 0.0), 200.0) * (200.0 + 8.0) / (PI * 8.0);
fragColor.rgb += specAmount * (isSky ? 0.3 : 1.0) * horizonFactor;
// Depth fog - blend toward waterColor with depth, faded at horizon
float depthFog = clamp(-(p.z - waterLevel) * waterDensity, 0.0, 0.9);
fragColor.rgb = mix(fragColor.rgb, waterColor, depthFog * horizonFactor);
// Alpha fades smoothly at horizon instead of hard cut
fragColor.a = isSky ? horizonFactor : clamp(abs(p.z - waterLevel) * 5.0, 0.0, 1.0);
// Foam
float fd = abs(p.z - waterLevel);
// Foam - based on actual geometry depth below water surface
float fd = isSky ? 1.0 : abs(p.z - waterLevel);
if (fd < 0.1) {
// Based on foam by Owen Deery
// http://fire-face.com/personal/water
vec3 foamMask0 = textureLod(sfoam, tcnor0 * 10, 0.0).rgb;
vec3 foamMask1 = textureLod(sfoam, tcnor1 * 11, 0.0).rgb;
vec3 foam = vec3(1.0) - foamMask0.rrr - foamMask1.bbb;
float fac = 1.0 - (fd * (1.0 / 0.1));
fragColor.rgb = mix(fragColor.rgb, clamp(foam, 0.0, 1.0), clamp(fac, 0.0, 1.0));
// Distance-based LOD blurs foam at range to reduce noise
float foamLod = clamp(tWater / 15.0, 0.0, 5.0);
vec2 foamUV0 = tcnor0 * 3.0 + vec2(speed / 30.0, speed / 50.0);
vec2 foamUV1 = tcnor1 * 4.0 + vec2(-speed / 35.0, speed / 45.0);
vec3 foamMask0 = textureLod(sfoam, foamUV0, foamLod).rgb;
vec3 foamMask1 = textureLod(sfoam, foamUV1, foamLod).rgb;
float foamStrength = clamp(1.0 - foamMask0.r * 0.5 - foamMask1.b * 0.5, 0.0, 1.0);
float fac = (1.0 - (fd * (1.0 / 0.1))) * horizonFactor;
fragColor.rgb = mix(fragColor.rgb, mix(fragColor.rgb, waterColor + 0.2, foamStrength), clamp(fac, 0.0, 1.0) * 0.5);
}
}

View File

@ -672,7 +672,7 @@ class RenderPath {
}
#if (rp_voxels != "Off")
public function getComputeShader(handle: String): kha.compute.Shader {
public function getComputeShader(handle: String): kha.graphics4.ComputeShader {
return Reflect.field(kha.Shaders, handle + "_comp");
}
#end

View File

@ -55,6 +55,8 @@ class Geometry {
// Skinned
#if lnx_skin
public var skeletonTransformsI: Array<Mat4> = null;
public var actions: Map<String, Array<iron.data.SceneFormat.TObj>> = new Map();
public var mats: Map<String, Array<Mat4>> = new Map();
#end
public function new(data: MeshData, indices: Array<Uint32Array>, materialIndices: Array<Int>, usage: Usage = null) {

View File

@ -348,7 +348,13 @@ typedef TWorldData = {
@:optional public var turbidity: Null<FastFloat>;
@:optional public var ground_albedo: Null<FastFloat>;
@:optional public var envmap: String;
@:optional public var nishita_density: Float32Array; // Rayleigh, Mie, ozone
@:optional public var sky_density: Float32Array; // Air, dust/aerosol, ozone density
@:optional public var sky_sun_elevation: Null<FastFloat>;
@:optional public var sky_sun_rotation: Null<FastFloat>;
@:optional public var sky_sun_size: Null<FastFloat>;
@:optional public var sky_sun_intensity: Null<FastFloat>;
@:optional public var sky_altitude: Null<FastFloat>;
@:optional public var sky_sun_disc: Null<Int>; // 0 or 1
}
#if js

View File

@ -318,9 +318,9 @@ class MeshObject extends Object {
if (scontext.pipeState != lastPipeline) {
g.setPipeline(scontext.pipeState);
lastPipeline = scontext.pipeState;
// Uniforms.setContextConstants(g, scontext, bindParams);
Uniforms.setContextConstants(g, scontext, bindParams);
}
Uniforms.setContextConstants(g, scontext, bindParams); //
//Uniforms.setContextConstants(g, scontext, bindParams); //
Uniforms.setObjectConstants(g, scontext, this);
if (materialContexts.length > mi) {
Uniforms.setMaterialConstants(g, scontext, materialContexts[mi]);

View File

@ -394,7 +394,7 @@ class ParticleSystemCPU {
if (physics.hasScaleRamp && physics.rampPositions.length > 1) {
var normalizedAge: FastFloat = physics.age / physics.lifetime;
var scaleMultiplier: FastFloat = interpolateRampValue(normalizedAge, physics.rampPositions, physics.rampColors);
var finalScale: FastFloat = scale * (particleScale * (1 - physics.scaleRampSizeFactor) + scaleMultiplier * physics.scaleRampSizeFactor);
var finalScale: FastFloat = 1 + (scaleMultiplier - 1) * physics.scaleRampSizeFactor;
particle.transform.scale.setFrom(physics.baseScale.clone().mult(finalScale));
}

View File

@ -8,7 +8,7 @@ class AlertNode extends LogicNode {
override function run(from: Int) {
#if kha_html5
#if js
js.Browser.window.alert(inputs[1].get());
#end

View File

@ -2,19 +2,31 @@ package leenkx.logicnode;
class ConfirmNode extends LogicNode {
var result: Dynamic;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_html5
var answer: Bool = js.Browser.window.confirm(inputs[1].get());
if(answer)
return runOutput(0);
else
return runOutput(1);
#if js
result = js.Browser.window.confirm(inputs[1].get());
if (Reflect.field(result, "loaded") != null) {
tree.notifyOnUpdate(poll);
} else {
if (result) runOutput(0);
else runOutput(1);
}
#end
}
function poll() {
#if js
if (result.loaded) {
tree.removeUpdate(poll);
if (result.data) runOutput(0);
else runOutput(1);
}
#end
}
}

View File

@ -11,12 +11,11 @@ class GetElementPropertyNode extends LogicNode {
override function get(from: Int): Dynamic {
return switch (from) {
case 0:
var object: Dynamic = inputs[0].get();
var property = inputs[1].get();
value = Reflect.field(object, property);
//value = object.getAttribute(property.toString());
#if js
var element: Dynamic = inputs[0].get();
var property = inputs[1].get();
value = Reflect.field(element, property);
#end
default: throw "Unreachable";
}
}

View File

@ -1,27 +0,0 @@
package leenkx.logicnode;
import iron.math.Vec4;
class GetHosekWilkiePropertiesNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var world = iron.Scene.active.world.raw;
return switch (from) {
case 0:
world.turbidity;
case 1:
world.ground_albedo;
case 2:
new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]);
default:
null;
}
return null;
}
}

View File

@ -1,29 +0,0 @@
package leenkx.logicnode;
import iron.math.Vec4;
class GetNishitaPropertiesNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var world = iron.Scene.active.world.raw;
return switch (from) {
case 0:
world.nishita_density[0];
case 1:
world.nishita_density[1];
case 2:
world.nishita_density[2];
case 3:
new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]);
default:
null;
}
return null;
}
}

View File

@ -0,0 +1,15 @@
package leenkx.logicnode;
import iron.math.Vec4;
class GetWorldColorNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var col = iron.Scene.active.world.raw.background_color;
return new Vec4(((col >> 16) & 0xff) / 255, ((col >> 8) & 0xff) / 255, (col & 0xff) / 255, 1.0);
}
}

View File

@ -0,0 +1,50 @@
package leenkx.logicnode;
import iron.math.Vec4;
class GetWorldSkyNode extends LogicNode {
public var property0:String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var world = iron.Scene.active.world.raw;
if (property0 == 'hosek') {
return switch (from) {
case 0: world.turbidity != null ? world.turbidity : 1.0;
case 1: world.ground_albedo != null ? world.ground_albedo : 0.0;
case 2: world.sun_direction != null ? new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]) : new Vec4(0, 0, 1);
default: null;
}
}
else if (property0 == 'single') {
return switch (from) {
case 0: world.sky_density != null ? world.sky_density[0] : 1.0;
case 1: world.sky_density != null ? world.sky_density[1] : 1.0;
case 2: world.sky_density != null ? world.sky_density[2] : 1.0;
case 3: world.sky_altitude != null ? world.sky_altitude : 0.0;
case 4: world.sun_direction != null ? new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]) : new Vec4(0, 0, 1);
default: null;
}
}
else { // multi
return switch (from) {
case 0: world.sky_density != null ? world.sky_density[0] : 1.0;
case 1: world.sky_density != null ? world.sky_density[1] : 1.0;
case 2: world.sky_density != null ? world.sky_density[2] : 1.0;
case 3: world.sky_sun_elevation != null ? world.sky_sun_elevation : 0.0;
case 4: world.sky_sun_rotation != null ? world.sky_sun_rotation : 0.0;
case 5: world.sky_sun_size != null ? world.sky_sun_size : 0.545;
case 6: world.sky_sun_intensity != null ? world.sky_sun_intensity : 1.0;
case 7: world.sky_altitude != null ? world.sky_altitude : 0.0;
case 8: world.sky_sun_disc != null ? world.sky_sun_disc : 1;
case 9: world.sun_direction != null ? new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]) : new Vec4(0, 0, 1);
default: null;
}
}
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class GetWorldTextureNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var world = iron.Scene.active.world;
return switch (from) {
case 0: world.probe != null ? world.probe.raw.strength : 1.0;
case 1: world.raw.envmap != null ? world.raw.envmap : '';
default: null;
}
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromCopyToClipboardNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var text: String = inputs[1].get();
js.Syntax.code("Krom.copyToClipboard({0})", text);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,15 @@
package leenkx.logicnode;
class KromDelayIdleSleepNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
js.Syntax.code("Krom.delayIdleSleep()");
#end
runOutput(0);
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromDeleteFileNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var path: String = inputs[1].get();
js.Syntax.code("Krom.deleteFile({0})", path);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class KromFileExistsNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var path: String = inputs[0].get();
return js.Syntax.code("Krom.fileExists({0})", path);
#else
return false;
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromGetArgCountNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.getArgCount();
#else
return 0;
#end
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class KromGetArgNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var index: Int = inputs[0].get();
return Krom.getArg(index);
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromGetFilesLocationNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.getFilesLocation();
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromSavePathNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.savePath();
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromSetApplicationNameNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var name: String = inputs[1].get();
js.Syntax.code("Krom.setApplicationName({0})", name);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromShowKeyboardNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var show: Bool = inputs[1].get();
js.Syntax.code("Krom.showKeyboard({0})", show);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,28 @@
package leenkx.logicnode;
class KromSysCommandNode extends LogicNode {
var exitCode: Int = 0;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var cmd: String = inputs[1].get();
var args: Dynamic = inputs[2].get();
if (args != null) {
exitCode = Krom.sysCommand(cmd, args);
} else {
exitCode = Krom.sysCommand(cmd);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
if (from == 1) return exitCode;
return null;
}
}

View File

@ -20,6 +20,7 @@ class LeenkxSendMessageNode extends LogicNode {
}
override function run(from:Int) {
#if js
var connection = inputs[1].get();
if (connection == null) return;
var api: String = inputs[2].get();
@ -348,6 +349,7 @@ class LeenkxSendMessageNode extends LogicNode {
return;
}
}
#end
}
}

View File

@ -13,7 +13,7 @@ class LoadUrlNode extends LogicNode {
override function run(from: Int) {
//System.loadUrl(inputs[1].get());
#if kha_html5
#if js
if (inputs[2].get()){
var window = inputs[3].get() ? js.Browser.window.open(inputs[1].get(), "_blank", "width="+inputs[4].get()+",height="+inputs[5].get()+",left="+inputs[6].get()+",top="+inputs[7].get())
: js.Browser.window.open(inputs[1].get(), "_blank");

View File

@ -1,193 +0,0 @@
package leenkx.logicnode;
import iron.object.Animation;
import iron.object.Object;
import iron.Scene;
import kha.arrays.Float32Array;
import iron.object.ObjectAnimation;
class PlayActionFromNode extends LogicNode {
var animation: Animation;
var startFrame: Int;
var endFrame: Int = -1;
var loop: Bool;
var reverse: Bool;
var action: String;
var actionR: String;
public function new(tree: LogicTree) {
super(tree);
tree.notifyOnUpdate(update);
}
function update() {
if (animation != null && action == animation.action) {
if (animation.currentFrame() == endFrame-1) {
if (loop) animation.setFrame(startFrame);
else {
if (!animation.paused) {
animation.pause();
runOutput(1);
}
}
}
}
}
override function run(from: Int) {
var object: Object = inputs[1].get();
action = inputs[2].get();
startFrame = inputs[3].get();
endFrame = inputs[4].get();
var blendTime: Float = inputs[5].get();
var speed: Float = inputs[6].get();
loop = inputs[7].get();
reverse = inputs[8].get();
if (object == null) return;
animation = object.animation;
if (animation == null) animation = object.getParentArmature(object.name);
if (reverse){
var isnew = true;
actionR = action+'Reverse';
if (animation.isSkinned){
for(a in animation.armature.actions)
if (a.name == actionR) isnew = false;
if (isnew){
for(a in animation.armature.actions)
if(a.name == action){
var bones = [];
var cn = [];
for(bone in a.bones){
var v = bone.anim.tracks[0];
var len: Int = v.values.length;
var val = new Float32Array(len);
var l = Std.int(len/16);
for(i in 0...l)
for(j in 0...16){
val[i*16+j] = v.values[(l-i)*16+j-16];
}
if (bone.children != null){
var cdn = [];
for (child in bone.children)
cdn.push(child.name);
cn.push(cdn);
} else cn.push(null);
var a: iron.data.SceneFormat.TObj = {
type : bone.type,
name : bone.name,
transform : {
//target : null,
values : bone.transform.values
},
anim : {
tracks : [{
target : v.target,
frames : v.frames,
values : val,
ref_values : null
}]//,
//begin : null,
//end : null,
//has_delta : null,
//marker_frames : null,
//marker_names : null
},
children : bone.children,
data_ref : null
}
if (bone.parent != null){
a.parent = bone.parent;
}
bones.push(a);
}
for (i in 0...bones.length){
var cd = [];
if (cn[i] != null)
for (name in cn[i])
for (bone in bones)
if (bone.name == name)
cd.push(bone);
bones[i].children = cd;
}
for (i in 0...bones.length){
if (bones[i].parent != null)
for (bone in bones)
if (bone.name == bones[i].parent.name)
bones[i].parent = bone;
}
animation.armature.actions.push({
name: actionR,
bones: bones,
mats: null});
var mats: Array<iron.math.Mat4> = [];
for (bone in a.bones) mats.push(iron.math.Mat4.fromFloat32Array(bone.transform.values));
var castBoneAnim = cast(animation, iron.object.BoneAnimation);
castBoneAnim.data.geom.actions.set(actionR, bones);
castBoneAnim.data.geom.mats.set(actionR, mats);
for(o in iron.Scene.active.raw.objects)
if (o.name == object.name) o.bone_actions.push('action_'+o.bone_actions[0].split('_')[1]+'_'+actionR);
}
}
}
else {
var oaction = null;
var tracks: Array<iron.data.SceneFormat.TTrack> = [];
var oactions = cast(animation, ObjectAnimation).oactions;
for (a in oactions)
if (a != null && a.objects[0].name == actionR) isnew = false;
if (isnew){
for (a in oactions){
if (a != null && a.objects[0].name == action){
oaction = a.objects[0];
for(b in a.objects[0].anim.tracks){
var val: Array<Float> = [];
for(c in b.values) val.unshift(c);
var vali = new Float32Array(val.length);
for(i in 0...val.length) vali[i] = val[i];
tracks.push({target: b.target, frames: b.frames, values: vali});
}
oactions.push({
objects: [{name: actionR,
anim: {begin: oaction.anim.begin, end: oaction.anim.end, tracks: tracks},
type: 'object',
data_ref: '',
transform: null}]});
for(o in iron.Scene.active.raw.objects)
if (o.name == object.name) o.object_actions.push('action_'+actionR);
}
}
}
}
}
animation.play(reverse ? actionR : action, function() {
runOutput(1);
}, blendTime, speed, loop);
animation.update(startFrame * Scene.active.raw.frame_time);
runOutput(0);
}
}

View File

@ -3,18 +3,32 @@ package leenkx.logicnode;
class PromptNode extends LogicNode {
var input: String = null;
var result: Dynamic;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_html5
input = js.Browser.window.prompt(inputs[1].get(), inputs[2].get());
runOutput(0);
#if js
result = js.Browser.window.prompt(inputs[1].get(), inputs[2].get());
if (Reflect.field(result, "loaded") != null) {
tree.notifyOnUpdate(poll);
} else {
input = result;
runOutput(0);
}
#end
}
function poll() {
#if js
if (result.loaded) {
tree.removeUpdate(poll);
input = result.data;
runOutput(0);
}
#end
}
override function get(from: Int): Dynamic {

View File

@ -40,12 +40,14 @@ class RenderElementNode extends LogicNode {
tarElem.prepend(element);
runOutput(0);
case "innerHTML":
var tarElem = js.Browser.document.querySelector(selector);
tarElem.innerHTML = element.innerHTML;
var html: String = inputs[2].get();
if (html == null) { return; }
element.innerHTML = html;
runOutput(0);
case "innerText":
var tarElem = js.Browser.document.querySelector(selector);
tarElem.innerText = element.innerText;
var html: String = inputs[2].get();
if (html == null){ return; }
element.innerText = html;
runOutput(0);
case "insertAdjacentHTML":
var tarElem = js.Browser.document.querySelector(selector);

View File

@ -12,28 +12,7 @@ class RunJavascriptNode extends LogicNode {
#if js
var script = inputs[1].get();
js.Syntax.code('(1, eval)({0})', script.toString());
var promise:Dynamic = null;//js.Syntax.code('(1, eval)({0})', script.toString());
if (promise != null) {
promise.then(
function(_) {
//if(leenkx.network.Leenkx.data.get(element) != 'undefined'){return}
haxe.Timer.delay(function () {
//promiseResult(element,html);
return;
}, 100);
return;
}).then(null, function(error) {
trace("JS SYNTAX ERROR:" + error.toString());
haxe.Timer.delay(function () {
//promiseResult(element,html);
return;
}, 100);
}
);
}
runOutput(0);
runOutput(0);
#end
}

View File

@ -10,6 +10,7 @@ class SetFirstPersonControllerNode extends LogicNode {
}
override function run(from: Int): Void {
#if lnx_physics
// Control de las var de FirstPersonController...
// Control FirstPersonController var
@ -60,6 +61,7 @@ class SetFirstPersonControllerNode extends LogicNode {
// Alert the user if they do not have the trait assigning to the object.
trace("ERROR: The object '" + object.name + "' does not have the FirstPersonController script assigning(assign it from (Object->add trait->bundle)).");
}
#end
runOutput(0);
}

View File

@ -1,41 +0,0 @@
package leenkx.logicnode;
import leenkx.renderpath.HosekWilkie;
import iron.math.Vec4;
class SetHosekWilkiePropertiesNode extends LogicNode {
public var property0:String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var world = iron.Scene.active.world;
if(property0 == 'Turbidity/Ground Albedo'){
world.raw.turbidity = inputs[1].get();
world.raw.ground_albedo = inputs[2].get();
}
if(property0 == 'Turbidity')
world.raw.turbidity = inputs[1].get();
if(property0 == 'Ground Albedo')
world.raw.ground_albedo = inputs[1].get();
if(property0 == 'Sun Direction'){
var vec:Vec4 = inputs[1].get();
world.raw.sun_direction[0] = vec.x;
world.raw.sun_direction[1] = vec.y;
world.raw.sun_direction[2] = vec.z;
}
HosekWilkie.recompute(world);
runOutput(0);
}
}

View File

@ -1,45 +0,0 @@
package leenkx.logicnode;
import leenkx.renderpath.Nishita;
import iron.math.Vec4;
class SetNishitaPropertiesNode extends LogicNode {
public var property0:String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var world = iron.Scene.active.world;
if(property0 == 'Density'){
world.raw.nishita_density[0] = inputs[1].get();
world.raw.nishita_density[1] = inputs[2].get();
world.raw.nishita_density[2] = inputs[3].get();
}
if(property0 == 'Air')
world.raw.nishita_density[0] = inputs[1].get();
if(property0 == 'Dust')
world.raw.nishita_density[1] = inputs[1].get();
if(property0 == 'Ozone')
world.raw.nishita_density[2] = inputs[1].get();
if(property0 == 'Sun Direction'){
var vec:Vec4 = inputs[1].get();
world.raw.sun_direction[0] = vec.x;
world.raw.sun_direction[1] = vec.y;
world.raw.sun_direction[2] = vec.z;
}
Nishita.recompute(world);
runOutput(0);
}
}

View File

@ -10,6 +10,7 @@ class SetOverheadPersonControllerNode extends LogicNode {
}
override function run(from: Int): Void {
#if lnx_physics
// Control de las var de OverheadPersonController...
// Control OverheadPersonController var
@ -58,6 +59,7 @@ class SetOverheadPersonControllerNode extends LogicNode {
// Alert the user if they do not have the trait assigning to the object..
trace("ERROR: The object '" + objectTrait.name + "' does not have the OverheadPersonController script assigning(assign it from (Object->add trait->bundle)).");
}
#end
runOutput(0);
}

View File

@ -0,0 +1,23 @@
package leenkx.logicnode;
import iron.math.Vec4;
class SetWorldColorNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var world = iron.Scene.active.world;
var raw = world.raw;
var vec:Vec4 = inputs[1].get();
var r = Std.int(Math.max(0, Math.min(1, vec.x)) * 255);
var g = Std.int(Math.max(0, Math.min(1, vec.y)) * 255);
var b = Std.int(Math.max(0, Math.min(1, vec.z)) * 255);
raw.background_color = (r << 16) | (g << 8) | b;
runOutput(0);
}
}

View File

@ -0,0 +1,63 @@
package leenkx.logicnode;
import leenkx.renderpath.Sky;
import leenkx.renderpath.HosekWilkie;
import iron.math.Vec4;
class SetWorldSkyNode extends LogicNode {
public var property0:String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var world = iron.Scene.active.world;
var raw = world.raw;
if (property0 == 'hosek') {
raw.turbidity = inputs[1].get();
raw.ground_albedo = inputs[2].get();
var vec:Vec4 = inputs[3].get();
if (raw.sun_direction == null) raw.sun_direction = new kha.arrays.Float32Array(3);
raw.sun_direction[0] = vec.x;
raw.sun_direction[1] = vec.y;
raw.sun_direction[2] = vec.z;
HosekWilkie.recompute(world);
}
else if (property0 == 'single') {
if (raw.sky_density == null) raw.sky_density = new kha.arrays.Float32Array(3);
raw.sky_density[0] = inputs[1].get();
raw.sky_density[1] = inputs[2].get();
raw.sky_density[2] = inputs[3].get();
raw.sky_altitude = inputs[4].get();
var vec:Vec4 = inputs[5].get();
if (raw.sun_direction == null) raw.sun_direction = new kha.arrays.Float32Array(3);
raw.sun_direction[0] = vec.x;
raw.sun_direction[1] = vec.y;
raw.sun_direction[2] = vec.z;
Sky.recomputeSingleScatter(world);
}
else if (property0 == 'multi') {
if (raw.sky_density == null) raw.sky_density = new kha.arrays.Float32Array(3);
raw.sky_density[0] = inputs[1].get();
raw.sky_density[1] = inputs[2].get();
raw.sky_density[2] = inputs[3].get();
raw.sky_sun_elevation = inputs[4].get();
raw.sky_sun_rotation = inputs[5].get();
raw.sky_sun_size = inputs[6].get();
raw.sky_sun_intensity = inputs[7].get();
raw.sky_altitude = inputs[8].get();
raw.sky_sun_disc = inputs[9].get() ? 1 : 0;
var vec:Vec4 = inputs[10].get();
if (raw.sun_direction == null) raw.sun_direction = new kha.arrays.Float32Array(3);
raw.sun_direction[0] = vec.x;
raw.sun_direction[1] = vec.y;
raw.sun_direction[2] = vec.z;
Sky.recomputeMultiScatter(world);
}
runOutput(0);
}
}

View File

@ -0,0 +1,25 @@
package leenkx.logicnode;
class SetWorldTextureNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var world = iron.Scene.active.world;
var raw = world.raw;
if (world.probe != null) {
world.probe.raw.strength = inputs[1].get();
}
var envmap:String = inputs[2].get();
if (envmap != null && envmap != '' && envmap != raw.envmap) {
raw.envmap = envmap;
world.loadEnvmap(function(w) {});
}
runOutput(0);
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class WebviewCountNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.webviewCount();
#else
return 0;
#end
}
}

View File

@ -0,0 +1,50 @@
package leenkx.logicnode;
class WebviewCreateNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var parentWindow: Int = (property0 == "embedded") ? 0 : -1;
var x: Int = inputs[1].get();
var y: Int = inputs[2].get();
var width: Int = inputs[3].get();
var height: Int = inputs[4].get();
var transparent: Bool = inputs[5].get();
var title: String = inputs[6].get();
var html: String = inputs[7].get();
var url: String = inputs[8].get();
var show: Bool = inputs[9].get();
#if kha_krom
var options: Dynamic = {
parentWindow: parentWindow,
x: x,
y: y,
width: width,
height: height,
transparent: transparent,
title: title
};
var id: Int = Krom.webviewCreate(options);
if (html != null && html != "") Krom.webviewLoadHTML(id, html);
if (url != null && url != "") Krom.webviewLoadURL(id, url);
if (show) Krom.webviewShow(id);
#else
var id: Int = -1;
#end
this.id = id;
runOutput(0);
}
var id: Int = -1;
override function get(from: Int): Dynamic {
return id;
}
}

View File

@ -0,0 +1,31 @@
package leenkx.logicnode;
class WebviewDOMNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
if (property0 == "set") {
var id: Int = inputs[1].get();
Krom.webviewSetActiveDOM(id);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
#if kha_krom
if (property0 == "get") {
return Krom.webviewGetActiveDOM();
}
#else
return -1;
#end
return -1;
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class WebviewDestroyNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
Krom.webviewDestroy(id);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,24 @@
package leenkx.logicnode;
class WebviewDevSettingsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
var enabled: Bool = inputs[2].get();
if (property0 == "devtools") {
Krom.webviewEnableDevTools(id, enabled);
}
else {
Krom.webviewSetContextMenu(id, enabled);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class WebviewEvalJSNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
var jsCode: String = inputs[2].get();
Krom.webviewEvalJS(id, jsCode);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,31 @@
package leenkx.logicnode;
class WebviewFullscreenNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
if (property0 == "set") {
var id: Int = inputs[1].get();
var fullscreen: Bool = inputs[2].get();
Krom.webviewSetFullscreen(id, fullscreen);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
#if kha_krom
if (property0 == "get") {
var id: Int = inputs[0].get();
return Krom.webviewIsFullscreen(id);
}
#end
return false;
}
}

View File

@ -0,0 +1,26 @@
package leenkx.logicnode;
class WebviewGetDimensionsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
if (property0 == "position") {
if (from == 0) return Krom.webviewGetX(id);
else return Krom.webviewGetY(id);
}
else {
if (from == 0) return Krom.webviewGetWidth(id);
else return Krom.webviewGetHeight(id);
}
#else
return 0;
#end
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class WebviewIsValidNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
return Krom.webviewIsValid(id);
#else
return false;
#end
}
}

View File

@ -0,0 +1,25 @@
package leenkx.logicnode;
class WebviewLoadNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
if (property0 == "html") {
var html: String = inputs[2].get();
Krom.webviewLoadHTML(id, html);
}
else {
var url: String = inputs[2].get();
Krom.webviewLoadURL(id, url);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,22 @@
package leenkx.logicnode;
class WebviewNavigationNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
switch (property0) {
case "go_back": Krom.webviewGoBack(id);
case "go_forward": Krom.webviewGoForward(id);
case "reload": Krom.webviewReload(id);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,20 @@
package leenkx.logicnode;
class WebviewNavigationStateNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
if (property0 == "can_go_back") return Krom.webviewCanGoBack(id);
else return Krom.webviewCanGoForward(id);
#else
return false;
#end
}
}

Some files were not shown because too many files have changed in this diff Show More