From 912563c29b821ebb81c2f246923752e85980bdd5 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 11 Nov 2019 17:14:51 +0100 Subject: [PATCH] Separate painter shaders --- Shaders/{voxel_hlsl/src => bin}/build.md | 0 Shaders/{voxel_hlsl/src => bin}/hlslbin.exe | Bin Shaders/painter/glsl/cursor.frag.glsl | 8 + Shaders/painter/glsl/cursor.vert.glsl | 49 ++ Shaders/painter/glsl/layer_merge.frag.glsl | 90 ++++ Shaders/painter/glsl/layer_merge.vert.glsl | 8 + Shaders/painter/glsl/layer_view.frag.glsl | 12 + Shaders/painter/glsl/layer_view.vert.glsl | 8 + Shaders/painter/glsl/mask_merge.frag.glsl | 10 + Shaders/painter/hlsl/cursor.frag.glsl | Bin 0 -> 702 bytes Shaders/painter/hlsl/cursor.vert.glsl | Bin 0 -> 4923 bytes Shaders/painter/hlsl/layer_merge.frag.glsl | Bin 0 -> 10457 bytes Shaders/painter/hlsl/layer_merge.vert.glsl | Bin 0 -> 640 bytes Shaders/painter/hlsl/layer_view.frag.glsl | Bin 0 -> 726 bytes Shaders/painter/hlsl/layer_view.vert.glsl | Bin 0 -> 1163 bytes Shaders/painter/hlsl/mask_merge.frag.glsl | Bin 0 -> 897 bytes Shaders/painter/hlsl/src/cursor.frag.glsl | 6 + Shaders/painter/hlsl/src/cursor.vert.glsl | 53 +++ .../painter/hlsl/src/layer_merge.frag.glsl | 95 ++++ .../painter/hlsl/src/layer_merge.vert.glsl | 10 + Shaders/painter/hlsl/src/layer_view.frag.glsl | 5 + Shaders/painter/hlsl/src/layer_view.vert.glsl | 10 + Shaders/painter/hlsl/src/mask_merge.frag.glsl | 12 + Sources/arm/Layers.hx | 16 +- Sources/arm/data/ConstData.hx | 422 ------------------ Sources/arm/ui/TabBrowser.hx | 1 + Sources/arm/ui/UIFiles.hx | 1 + Sources/arm/ui/UIView2D.hx | 4 +- khafile.js | 6 + 29 files changed, 394 insertions(+), 432 deletions(-) rename Shaders/{voxel_hlsl/src => bin}/build.md (100%) rename Shaders/{voxel_hlsl/src => bin}/hlslbin.exe (100%) create mode 100644 Shaders/painter/glsl/cursor.frag.glsl create mode 100644 Shaders/painter/glsl/cursor.vert.glsl create mode 100644 Shaders/painter/glsl/layer_merge.frag.glsl create mode 100644 Shaders/painter/glsl/layer_merge.vert.glsl create mode 100644 Shaders/painter/glsl/layer_view.frag.glsl create mode 100644 Shaders/painter/glsl/layer_view.vert.glsl create mode 100644 Shaders/painter/glsl/mask_merge.frag.glsl create mode 100644 Shaders/painter/hlsl/cursor.frag.glsl create mode 100644 Shaders/painter/hlsl/cursor.vert.glsl create mode 100644 Shaders/painter/hlsl/layer_merge.frag.glsl create mode 100644 Shaders/painter/hlsl/layer_merge.vert.glsl create mode 100644 Shaders/painter/hlsl/layer_view.frag.glsl create mode 100644 Shaders/painter/hlsl/layer_view.vert.glsl create mode 100644 Shaders/painter/hlsl/mask_merge.frag.glsl create mode 100644 Shaders/painter/hlsl/src/cursor.frag.glsl create mode 100644 Shaders/painter/hlsl/src/cursor.vert.glsl create mode 100644 Shaders/painter/hlsl/src/layer_merge.frag.glsl create mode 100644 Shaders/painter/hlsl/src/layer_merge.vert.glsl create mode 100644 Shaders/painter/hlsl/src/layer_view.frag.glsl create mode 100644 Shaders/painter/hlsl/src/layer_view.vert.glsl create mode 100644 Shaders/painter/hlsl/src/mask_merge.frag.glsl diff --git a/Shaders/voxel_hlsl/src/build.md b/Shaders/bin/build.md similarity index 100% rename from Shaders/voxel_hlsl/src/build.md rename to Shaders/bin/build.md diff --git a/Shaders/voxel_hlsl/src/hlslbin.exe b/Shaders/bin/hlslbin.exe similarity index 100% rename from Shaders/voxel_hlsl/src/hlslbin.exe rename to Shaders/bin/hlslbin.exe diff --git a/Shaders/painter/glsl/cursor.frag.glsl b/Shaders/painter/glsl/cursor.frag.glsl new file mode 100644 index 00000000..075134e6 --- /dev/null +++ b/Shaders/painter/glsl/cursor.frag.glsl @@ -0,0 +1,8 @@ +#version 330 +uniform sampler2D tex; +in vec2 texCoord; +out vec4 FragColor; +void main() { + vec4 col = texture(tex, texCoord); + FragColor = vec4(col.rgb / col.a, col.a); +} diff --git a/Shaders/painter/glsl/cursor.vert.glsl b/Shaders/painter/glsl/cursor.vert.glsl new file mode 100644 index 00000000..430ec8a2 --- /dev/null +++ b/Shaders/painter/glsl/cursor.vert.glsl @@ -0,0 +1,49 @@ +#version 330 +uniform mat4 VP; +uniform mat4 invVP; +uniform vec2 mouse; +uniform vec2 step; +uniform float radius; +uniform sampler2D gbufferD; +uniform sampler2D gbuffer0; +in vec4 pos; +in vec2 nor; +in vec2 tex; +out vec2 texCoord; +vec2 octahedronWrap(const vec2 v) { return (1.0 - abs(v.yx)) * (vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0)); } +mat3 rotAxis(vec3 axis, float a) { + float c = cos(a); + vec3 as = axis * sin(a); + mat3 p = mat3(axis.x * axis, axis.y * axis, axis.z * axis); + mat3 q = mat3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c); + return p * (1.0 - c) + q; +} +vec3 getNormal(vec2 uv) { + vec2 g0 = textureLod(gbuffer0, mouse, 0.0).rg; + vec3 n; + n.z = 1.0 - abs(g0.x) - abs(g0.y); + n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy); + return n; +} +void main() { + texCoord = tex; + float depth = textureLod(gbufferD, mouse, 0.0).r; + vec4 wpos = vec4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); + wpos = invVP * wpos; + wpos.xyz /= wpos.w; + vec3 n = normalize( + getNormal(mouse + vec2(step.x, step.y)) + + getNormal(mouse + vec2(-step.x, step.y)) + + getNormal(mouse + vec2(-step.x, -step.y)) + + getNormal(mouse + vec2(step.x, -step.y)) + + getNormal(mouse) + ); + float ax = acos(dot(vec3(1,0,0), vec3(n.x,0,0))); + float az = acos(dot(vec3(0,0,1), vec3(0,0,n.z))); + float sy = -sign(n.y); + wpos.xyz += + rotAxis(vec3(1,0,0), -az * sy + 3.14/2) * + rotAxis(vec3(0,0,1), ax + 3.14/2) * + (pos.xyz * radius); + gl_Position = VP * vec4(wpos.xyz, 1.0); +} diff --git a/Shaders/painter/glsl/layer_merge.frag.glsl b/Shaders/painter/glsl/layer_merge.frag.glsl new file mode 100644 index 00000000..ba7d9b05 --- /dev/null +++ b/Shaders/painter/glsl/layer_merge.frag.glsl @@ -0,0 +1,90 @@ +#version 330 +uniform sampler2D tex0; +uniform sampler2D tex1; +uniform sampler2D tex2; +uniform sampler2D texa; +uniform sampler2D texb; +uniform sampler2D texc; +uniform float opac; +uniform int blending; +in vec2 texCoord; +out vec4 FragColor[3]; +vec3 hsv_to_rgb(const vec3 c) { + const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} +vec3 rgb_to_hsv(const vec3 c) { + const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} +void main() { + vec4 col0 = textureLod(tex0, texCoord, 0); + vec4 col1 = textureLod(tex1, texCoord, 0); + vec4 col2 = textureLod(tex2, texCoord, 0); + vec4 cola = textureLod(texa, texCoord, 0); + vec4 colb = textureLod(texb, texCoord, 0); + vec4 colc = textureLod(texc, texCoord, 0); + float str = col0.a * opac; + if (blending == 0) { // Mix + FragColor[0] = vec4(mix(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 1) { // Darken + FragColor[0] = vec4(mix(cola.rgb, min(cola.rgb, col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 2) { // Multiply + FragColor[0] = vec4(mix(cola.rgb, cola.rgb * col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 3) { // Burn + FragColor[0] = vec4(mix(cola.rgb, vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - cola.rgb) / col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 4) { // Lighten + FragColor[0] = vec4(max(cola.rgb, col0.rgb * str), max(col0.a, cola.a)); + } + else if (blending == 5) { // Screen + FragColor[0] = vec4((vec3(1.0, 1.0, 1.0) - (vec3(1.0 - str, 1.0 - str, 1.0 - str) + str * (vec3(1.0, 1.0, 1.0) - col0.rgb)) * (vec3(1.0, 1.0, 1.0) - cola.rgb)), max(col0.a, cola.a)); + } + else if (blending == 6) { // Dodge + FragColor[0] = vec4(mix(cola.rgb, cola.rgb / (vec3(1.0, 1.0, 1.0) - col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 7) { // Add + FragColor[0] = vec4(mix(cola.rgb, cola.rgb + col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 8) { // Overlay + //FragColor[0] = vec4(mix(cola.rgb, (cola.rgb < vec3(0.5, 0.5, 0.5) ? vec3(2.0, 2.0, 2.0) * cola.rgb * col0.rgb : vec3(1.0, 1.0, 1.0) - vec3(2.0, 2.0, 2.0) * (vec3(1.0, 1.0, 1.0) - col0.rgb) * (vec3(1.0, 1.0, 1.0) - cola.rgb)), str), max(col0.a, cola.a)); // TODO + FragColor[0] = vec4(mix(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 9) { // Soft Light + FragColor[0] = vec4(((1.0 - str) * cola.rgb + str * ((vec3(1.0, 1.0, 1.0) - cola.rgb) * col0.rgb * cola.rgb + cola.rgb * (vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - col0.rgb) * (vec3(1.0, 1.0, 1.0) - cola.rgb)))), max(col0.a, cola.a)); + } + else if (blending == 10) { // Linear Light + FragColor[0] = vec4((cola.rgb + str * (vec3(2.0, 2.0, 2.0) * (col0.rgb - vec3(0.5, 0.5, 0.5)))), max(col0.a, cola.a)); + } + else if (blending == 11) { // Difference + FragColor[0] = vec4(mix(cola.rgb, abs(cola.rgb - col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 12) { // Subtract + FragColor[0] = vec4(mix(cola.rgb, cola.rgb - col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 13) { // Divide + FragColor[0] = vec4(vec3(1.0 - str, 1.0 - str, 1.0 - str) * cola.rgb + vec3(str, str, str) * cola.rgb / col0.rgb, max(col0.a, cola.a)); + } + else if (blending == 14) { // Hue + FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else if (blending == 15) { // Saturation + FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else if (blending == 16) { // Color + FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else { // Value + FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(col0.rgb).b)), str), max(col0.a, cola.a)); + } + FragColor[1] = vec4(mix(colb, col1, str)); + FragColor[2] = vec4(mix(colc, col2, str)); +} diff --git a/Shaders/painter/glsl/layer_merge.vert.glsl b/Shaders/painter/glsl/layer_merge.vert.glsl new file mode 100644 index 00000000..e6f07bcc --- /dev/null +++ b/Shaders/painter/glsl/layer_merge.vert.glsl @@ -0,0 +1,8 @@ +#version 330 +in vec2 pos; +out vec2 texCoord; +void main() { + gl_Position = vec4(pos.xy, 0.0, 1.0); + const vec2 madd = vec2(0.5, 0.5); + texCoord = pos.xy * madd + madd; +} diff --git a/Shaders/painter/glsl/layer_view.frag.glsl b/Shaders/painter/glsl/layer_view.frag.glsl new file mode 100644 index 00000000..c35e8db8 --- /dev/null +++ b/Shaders/painter/glsl/layer_view.frag.glsl @@ -0,0 +1,12 @@ +#version 330 +in vec3 pos; +in vec2 tex; +in vec4 col; +uniform mat4 projectionMatrix; +out vec2 texCoord; +out vec4 color; +void main() { + gl_Position = projectionMatrix * vec4(pos, 1.0); + texCoord = tex; + color = col; +} diff --git a/Shaders/painter/glsl/layer_view.vert.glsl b/Shaders/painter/glsl/layer_view.vert.glsl new file mode 100644 index 00000000..fb5ca02a --- /dev/null +++ b/Shaders/painter/glsl/layer_view.vert.glsl @@ -0,0 +1,8 @@ +#version 330 +uniform sampler2D tex; +in vec2 texCoord; +in vec4 color; +out vec4 FragColor; +void main() { + FragColor = textureLod(tex, texCoord, 0) * color; +} diff --git a/Shaders/painter/glsl/mask_merge.frag.glsl b/Shaders/painter/glsl/mask_merge.frag.glsl new file mode 100644 index 00000000..d598edca --- /dev/null +++ b/Shaders/painter/glsl/mask_merge.frag.glsl @@ -0,0 +1,10 @@ +#version 330 +uniform sampler2D tex0; +uniform sampler2D texa; +in vec2 texCoord; +out vec4 FragColor; +void main() { + vec4 col0 = textureLod(tex0, texCoord, 0); + float mask = textureLod(texa, texCoord, 0).r; + FragColor = vec4(col0.rgb, col0.a * mask); +} diff --git a/Shaders/painter/hlsl/cursor.frag.glsl b/Shaders/painter/hlsl/cursor.frag.glsl new file mode 100644 index 0000000000000000000000000000000000000000..002e62ef7237aa7a2800dfb8bd851a9cfbcfed6f GIT binary patch literal 702 zcmb7BO-lk%6uoMa3rPtAmv0ea5z#~xNJKRs8Cb^57()bRHK~y(<1AW4M7t1I^&^$E*P-syX&fIg){g`*(qj1r8uZqo5t#RpkLzMn7mD*gd{{Eb%7 literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/cursor.vert.glsl b/Shaders/painter/hlsl/cursor.vert.glsl new file mode 100644 index 0000000000000000000000000000000000000000..e0cbdca99984d9d97773522bd35d182c7fcc1199 GIT binary patch literal 4923 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 W#!*8f;9m~k62h9IpE>D)zCQ<@z)&Ip literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/layer_merge.vert.glsl b/Shaders/painter/hlsl/layer_merge.vert.glsl new file mode 100644 index 0000000000000000000000000000000000000000..64937e0e4c669e40aa9b28db1bf122f73075b039 GIT binary patch literal 640 zcmb_Yu}Z^G6un7X=pdNU@gag$ikKqeptdz>tq@H}f^;jzR*k5yG#wnpZ*XyQ6!H;* zgSfbL5nTNNKR`V<%`2{g7tXuqo%_y7-qQv$CY0UYv7SGiWb5YDSe&=-#&6vh4f>T% zR6t(??tw8-#^4?B?MAbQ{qNf3P2uaCFlX-DrpbK{5I_l70A>KL{pe^YV|hFhC4Wh@ zoWK#mX}8xO3QJxLqH_>)b;YE;VE3Sm^N6J)AOKaljO0MVM%!{--=-u730v_gP??6&!Xv8Aqc?UUF{GYP26P_i%C<{j5k@2iA&VU`NzvE++hh zDE|r0nT!ge)vTGF*J~IMRe{HpVbNb0c%Q?ymt@xB_dM!Ps7Wl5K+xTn{ X*27z-_f!&R{-yX$|D%2YL99Q7 literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/layer_view.frag.glsl b/Shaders/painter/hlsl/layer_view.frag.glsl new file mode 100644 index 0000000000000000000000000000000000000000..e732fbcf778890d9dde5e88e8a0967e53dff4262 GIT binary patch literal 726 zcmah_u}%U(5FJ1wg%KJPDzgOz8e=>|VWCF7->|Ha1}AyDZ{F;@-C2s(0`I!kt+zUto==2?hzxf}w?BF>UwSFG zahnJ~dsmeR^tUKc9D5G<2DTsuKnA*HOoOuMb3{7J#4G16$WPllf z;|7Qg+4zF?VLV`EUw*?B5F)U#{m^4<79OS4Jn`Gz_E{jZ)`BP$?V_+7^;6Fmdb`zW zVq~GMENj&7_xJ4GeFHx1p8(bX73xjNq}0`WSZ5vsaq_NSE?WkBmEpBCs1ea6W#08IU10xnWOXOoy^reku5YJF#ojjF=t0T^K#$B*tWCnJmH-B1Md0D PIp@14#eelly_0G`?}}3Q literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/layer_view.vert.glsl b/Shaders/painter/hlsl/layer_view.vert.glsl new file mode 100644 index 0000000000000000000000000000000000000000..f9fe5d88eb7af6959edf6b14d91b01218698f90e GIT binary patch literal 1163 zcmb_bO=}ZT6upy~nj&IjSK>m3(nUoOQ-Zh<9h+oYAvGZrBtoH#X=>JPA)|0=PZ^WZ~BtH$OqUjcS$Jb-)MKfK}iMK-&9g6XY$tih~?p_|C@;1lUEY(@JHwC(po{pL`vha|{{d>lpHNaK^ku3hIpE9iK#G>${Km4WrpO-HYg6jPHCeEHvw7j-UNM#8pMT$Gs2W{GQl9?UKQ4g9l^( K#rVDd5Bm)w26$Tl literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/mask_merge.frag.glsl b/Shaders/painter/hlsl/mask_merge.frag.glsl new file mode 100644 index 0000000000000000000000000000000000000000..044dac2199a7d5787c3a9284e6230d1b760d23a0 GIT binary patch literal 897 zcma)4O-lk{5T5meB!nagJiZ4H1`%#VL`9fiZD1Mh8qy&%+tNss)kE|}bnn)+U*M%< zhfW>)1$OAtPw*c0%I0x>52MTYA0eAsOlkfB* zFw(_jE|*V1(#icpGlnMmR>>$^hh`fhT}v1Fk(BZQ6HZ*k>Ueh=(ajUlRkAQa8o3ruZWJ1}1y?(VPi(nd#^dx`hEz9Jj9b+4f0Xaa#-8U%8;oUc O&`X`n4Xc-R!~6%WU27u% literal 0 HcmV?d00001 diff --git a/Shaders/painter/hlsl/src/cursor.frag.glsl b/Shaders/painter/hlsl/src/cursor.frag.glsl new file mode 100644 index 00000000..876b8a9d --- /dev/null +++ b/Shaders/painter/hlsl/src/cursor.frag.glsl @@ -0,0 +1,6 @@ +Texture2D tex; +SamplerState _tex_sampler; +float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 { + float4 col = tex.Sample(_tex_sampler, texCoord); + return float4(col.rgb / col.a, col.a); +} diff --git a/Shaders/painter/hlsl/src/cursor.vert.glsl b/Shaders/painter/hlsl/src/cursor.vert.glsl new file mode 100644 index 00000000..ba42de51 --- /dev/null +++ b/Shaders/painter/hlsl/src/cursor.vert.glsl @@ -0,0 +1,53 @@ +uniform float4x4 VP; +uniform float4x4 invVP; +uniform float2 mouse; +uniform float2 step; +uniform float radius; +Texture2D texa; // direct3d12 unit align +SamplerState _texa_sampler; // direct3d12 unit align +Texture2D gbufferD; +SamplerState _gbufferD_sampler; +Texture2D gbuffer0; +SamplerState _gbuffer0_sampler; +float2 octahedronWrap(float2 v) { return (1.0 - abs(v.yx)) * (float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0)); } +float3x3 rotAxis(float3 axis, float a) { + float c = cos(a); + float3 as = axis * sin(a).xxx; + float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis); + float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c); + return p * (1.0 - c) + q; +} +float3 getNormal(float2 uv) { + float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, uv, 0.0).rg; + float3 n; + n.z = 1.0 - abs(g0.x) - abs(g0.y); + n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy); + return n; +} +struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; }; +SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 tex : TEXCOORD2) { + SPIRV_Cross_Output stage_output; + stage_output.texCoord = tex; + float2 mouseinv = float2(mouse.x, 1.0 - mouse.y); + float depth = gbufferD.SampleLevel(_gbufferD_sampler, mouseinv, 0).r; + float keep = texa.SampleLevel(_texa_sampler, mouseinv, 0).r; // direct3d12 unit align + depth += keep * 0.0; // direct3d12 unit align + float4 wpos = float4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); + wpos = mul(wpos, invVP); + wpos.xyz /= wpos.w; + float3 n = normalize( + getNormal(mouseinv + float2(step.x, step.y)) + + getNormal(mouseinv + float2(-step.x, step.y)) + + getNormal(mouseinv + float2(-step.x, -step.y)) + + getNormal(mouseinv + float2(step.x, -step.y)) + + getNormal(mouseinv) + ); + float ax = acos(dot(float3(1,0,0), float3(n.x,0,0))); + float az = acos(dot(float3(0,0,1), float3(0,0,n.z))); + float sy = -sign(n.y); + wpos.xyz += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)), + rotAxis(float3(1,0,0), -az * sy + 3.14/2)); + stage_output.gl_Position = mul(float4(wpos.xyz, 1.0), VP); + stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; + return stage_output; +} diff --git a/Shaders/painter/hlsl/src/layer_merge.frag.glsl b/Shaders/painter/hlsl/src/layer_merge.frag.glsl new file mode 100644 index 00000000..5fa50bd5 --- /dev/null +++ b/Shaders/painter/hlsl/src/layer_merge.frag.glsl @@ -0,0 +1,95 @@ +Texture2D tex0; +SamplerState _tex0_sampler; +Texture2D tex1; +SamplerState _tex1_sampler; +Texture2D tex2; +SamplerState _tex2_sampler; +Texture2D texa; +SamplerState _texa_sampler; +Texture2D texb; +SamplerState _texb_sampler; +Texture2D texc; +SamplerState _texc_sampler; +uniform float opac; +uniform int blending; +float3 hsv_to_rgb(const float3 c) { + const float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} +float3 rgb_to_hsv(const float3 c) { + const float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g)); + float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r)); + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} +struct SPIRV_Cross_Output { float4 color0 : SV_Target0; float4 color1 : SV_Target1; float4 color2 : SV_Target2; }; +SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) { + float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0); + float4 col1 = tex1.SampleLevel(_tex1_sampler, texCoord, 0); + float4 col2 = tex2.SampleLevel(_tex2_sampler, texCoord, 0); + float4 cola = texa.SampleLevel(_texa_sampler, texCoord, 0); + float4 colb = texb.SampleLevel(_texb_sampler, texCoord, 0); + float4 colc = texc.SampleLevel(_texc_sampler, texCoord, 0); + float str = col0.a * opac; + SPIRV_Cross_Output stage_output; + if (blending == 0) { // Mix + stage_output.color0 = float4(lerp(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 1) { // Darken + stage_output.color0 = float4(lerp(cola.rgb, min(cola.rgb, col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 2) { // Multiply + stage_output.color0 = float4(lerp(cola.rgb, cola.rgb * col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 3) { // Burn + stage_output.color0 = float4(lerp(cola.rgb, float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - cola.rgb) / col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 4) { // Lighten + stage_output.color0 = float4(max(cola.rgb, col0.rgb * str), max(col0.a, cola.a)); + } + else if (blending == 5) { // Screen + stage_output.color0 = float4((float3(1.0, 1.0, 1.0) - (float3(1.0 - str, 1.0 - str, 1.0 - str) + str * (float3(1.0, 1.0, 1.0) - col0.rgb)) * (float3(1.0, 1.0, 1.0) - cola.rgb)), max(col0.a, cola.a)); + } + else if (blending == 6) { // Dodge + stage_output.color0 = float4(lerp(cola.rgb, cola.rgb / (float3(1.0, 1.0, 1.0) - col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 7) { // Add + stage_output.color0 = float4(lerp(cola.rgb, cola.rgb + col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 8) { // Overlay + stage_output.color0 = float4(lerp(cola.rgb, (cola.rgb < float3(0.5, 0.5, 0.5) ? float3(2.0, 2.0, 2.0) * cola.rgb * col0.rgb : float3(1.0, 1.0, 1.0) - float3(2.0, 2.0, 2.0) * (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)), str), max(col0.a, cola.a)); + } + else if (blending == 9) { // Soft Light + stage_output.color0 = float4(((1.0 - str) * cola.rgb + str * ((float3(1.0, 1.0, 1.0) - cola.rgb) * col0.rgb * cola.rgb + cola.rgb * (float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)))), max(col0.a, cola.a)); + } + else if (blending == 10) { // Linear Light + stage_output.color0 = float4((cola.rgb + str * (float3(2.0, 2.0, 2.0) * (col0.rgb - float3(0.5, 0.5, 0.5)))), max(col0.a, cola.a)); + } + else if (blending == 11) { // Difference + stage_output.color0 = float4(lerp(cola.rgb, abs(cola.rgb - col0.rgb), str), max(col0.a, cola.a)); + } + else if (blending == 12) { // Subtract + stage_output.color0 = float4(lerp(cola.rgb, cola.rgb - col0.rgb, str), max(col0.a, cola.a)); + } + else if (blending == 13) { // Divide + stage_output.color0 = float4(float3(1.0 - str, 1.0 - str, 1.0 - str) * cola.rgb + float3(str, str, str) * cola.rgb / col0.rgb, max(col0.a, cola.a)); + } + else if (blending == 14) { // Hue + stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else if (blending == 15) { // Saturation + stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else if (blending == 16) { // Color + stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); + } + else { // Value + stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(col0.rgb).b)), str), max(col0.a, cola.a)); + } + stage_output.color1 = float4(lerp(colb, col1, str)); + stage_output.color2 = float4(lerp(colc, col2, str)); + return stage_output; +} diff --git a/Shaders/painter/hlsl/src/layer_merge.vert.glsl b/Shaders/painter/hlsl/src/layer_merge.vert.glsl new file mode 100644 index 00000000..1cd347f6 --- /dev/null +++ b/Shaders/painter/hlsl/src/layer_merge.vert.glsl @@ -0,0 +1,10 @@ +struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; }; +SPIRV_Cross_Output main(float2 pos : TEXCOORD0) { + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = float4(pos.xy, 0.0, 1.0); + stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; + const float2 madd = float2(0.5, 0.5); + stage_output.texCoord = pos.xy * madd + madd; + stage_output.texCoord.y = 1.0 - stage_output.texCoord.y; + return stage_output; +} diff --git a/Shaders/painter/hlsl/src/layer_view.frag.glsl b/Shaders/painter/hlsl/src/layer_view.frag.glsl new file mode 100644 index 00000000..efc657af --- /dev/null +++ b/Shaders/painter/hlsl/src/layer_view.frag.glsl @@ -0,0 +1,5 @@ +Texture2D tex; +SamplerState _tex_sampler; +float4 main(float4 color : TEXCOORD0, float2 texCoord : TEXCOORD1) : SV_Target0 { + return tex.SampleLevel(_tex_sampler, texCoord, 0) * color; +} diff --git a/Shaders/painter/hlsl/src/layer_view.vert.glsl b/Shaders/painter/hlsl/src/layer_view.vert.glsl new file mode 100644 index 00000000..f07c6cee --- /dev/null +++ b/Shaders/painter/hlsl/src/layer_view.vert.glsl @@ -0,0 +1,10 @@ +uniform float4x4 projectionMatrix; +struct SPIRV_Cross_Output { float4 color : TEXCOORD0; float2 texCoord : TEXCOORD1; float4 gl_Position : SV_Position; }; +SPIRV_Cross_Output main(float4 col : TEXCOORD0, float3 pos : TEXCOORD1, float2 tex : TEXCOORD2) { + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = mul(float4(pos, 1.0f), projectionMatrix); + stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; + stage_output.texCoord = tex; + stage_output.color = col; + return stage_output; +} diff --git a/Shaders/painter/hlsl/src/mask_merge.frag.glsl b/Shaders/painter/hlsl/src/mask_merge.frag.glsl new file mode 100644 index 00000000..96ad14a2 --- /dev/null +++ b/Shaders/painter/hlsl/src/mask_merge.frag.glsl @@ -0,0 +1,12 @@ +Texture2D tex0; +SamplerState _tex0_sampler; +Texture2D texa; +SamplerState _texa_sampler; +struct SPIRV_Cross_Output { float4 color0 : SV_Target0; }; +SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) { + float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0); + float mask = texa.SampleLevel(_texa_sampler, texCoord, 0).r; + SPIRV_Cross_Output stage_output; + stage_output.color0 = float4(col0.rgb, col0.a * mask); + return stage_output; +} diff --git a/Sources/arm/Layers.hx b/Sources/arm/Layers.hx index b4b1a90b..9471c2f7 100644 --- a/Sources/arm/Layers.hx +++ b/Sources/arm/Layers.hx @@ -121,8 +121,8 @@ class Layers { public static function makePipe() { pipe = new PipelineState(); - pipe.vertexShader = VertexShader.fromSource(ConstData.layerMergeVert); - pipe.fragmentShader = FragmentShader.fromSource(ConstData.layerMergeFrag); + pipe.vertexShader = Reflect.field(kha.Shaders, "layer_merge_vert"); + pipe.fragmentShader = Reflect.field(kha.Shaders, "layer_merge_frag"); var vs = new VertexStructure(); vs.add("pos", VertexData.Float2); pipe.inputLayout = [vs]; @@ -137,8 +137,8 @@ class Layers { blending = pipe.getConstantLocation("blending"); pipeCopy = new PipelineState(); - pipeCopy.vertexShader = VertexShader.fromSource(ConstData.layerViewVert); - pipeCopy.fragmentShader = FragmentShader.fromSource(ConstData.layerViewFrag); + pipeCopy.vertexShader = Reflect.field(kha.Shaders, "layer_view_vert"); + pipeCopy.fragmentShader = Reflect.field(kha.Shaders, "layer_view_frag"); var vs = new VertexStructure(); vs.add("pos", VertexData.Float3); vs.add("tex", VertexData.Float2); @@ -147,8 +147,8 @@ class Layers { pipeCopy.compile(); pipeMask = new PipelineState(); - pipeMask.vertexShader = VertexShader.fromSource(ConstData.layerMergeVert); - pipeMask.fragmentShader = FragmentShader.fromSource(ConstData.maskMergeFrag); + pipeMask.vertexShader = Reflect.field(kha.Shaders, "layer_merge_vert"); + pipeMask.fragmentShader = Reflect.field(kha.Shaders, "mask_merge_frag"); var vs = new VertexStructure(); vs.add("pos", VertexData.Float2); pipeMask.inputLayout = [vs]; @@ -159,8 +159,8 @@ class Layers { public static function makeCursorPipe() { pipeCursor = new PipelineState(); - pipeCursor.vertexShader = VertexShader.fromSource(ConstData.cursorVert); - pipeCursor.fragmentShader = FragmentShader.fromSource(ConstData.cursorFrag); + pipeCursor.vertexShader = Reflect.field(kha.Shaders, "cursor_vert"); + pipeCursor.fragmentShader = Reflect.field(kha.Shaders, "cursor_frag"); var vs = new VertexStructure(); vs.add("pos", VertexData.Short4Norm); vs.add("nor", VertexData.Short2Norm); diff --git a/Sources/arm/data/ConstData.hx b/Sources/arm/data/ConstData.hx index d9011cd1..501edd58 100644 --- a/Sources/arm/data/ConstData.hx +++ b/Sources/arm/data/ConstData.hx @@ -8,428 +8,6 @@ import iron.system.ArmPack; class ConstData { - // 2D layer view - #if (kha_direct3d11 || kha_direct3d12) - - public static var layerViewVert = " -uniform float4x4 projectionMatrix; -struct SPIRV_Cross_Output { float4 color : TEXCOORD0; float2 texCoord : TEXCOORD1; float4 gl_Position : SV_Position; }; -SPIRV_Cross_Output main(float3 pos : TEXCOORD0, float2 tex : TEXCOORD1, float4 col : TEXCOORD2) { - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = mul(float4(pos, 1.0f), projectionMatrix); - stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; - stage_output.texCoord = tex; - stage_output.color = col; - return stage_output; -} -"; - public static var layerViewFrag = " -Texture2D tex; -SamplerState _tex_sampler; -float4 main(float4 color : TEXCOORD0, float2 texCoord : TEXCOORD1) : SV_Target0 { - return tex.SampleLevel(_tex_sampler, texCoord, 0) * color; -} -"; - - #else // kha_opengl - - public static var layerViewVert = "#version 330 -in vec3 pos; -in vec2 tex; -in vec4 col; -uniform mat4 projectionMatrix; -out vec2 texCoord; -out vec4 color; -void main() { - gl_Position = projectionMatrix * vec4(pos, 1.0); - texCoord = tex; - color = col; -} -"; - public static var layerViewFrag = "#version 330 -uniform sampler2D tex; -in vec2 texCoord; -in vec4 color; -out vec4 FragColor; -void main() { - FragColor = textureLod(tex, texCoord, 0) * color; -} -"; - #end - - - // 2D layer merge - #if (kha_direct3d11 || kha_direct3d12) - - public static var layerMergeVert = " -struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; }; -SPIRV_Cross_Output main(float2 pos : TEXCOORD0) { - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = float4(pos.xy, 0.0, 1.0); - stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; - const float2 madd = float2(0.5, 0.5); - stage_output.texCoord = pos.xy * madd + madd; - stage_output.texCoord.y = 1.0 - stage_output.texCoord.y; - return stage_output; -} -"; - public static var layerMergeFrag = " -Texture2D tex0; -SamplerState _tex0_sampler; -Texture2D tex1; -SamplerState _tex1_sampler; -Texture2D tex2; -SamplerState _tex2_sampler; -Texture2D texa; -SamplerState _texa_sampler; -Texture2D texb; -SamplerState _texb_sampler; -Texture2D texc; -SamplerState _texc_sampler; -uniform float opac; -uniform int blending; -float3 hsv_to_rgb(const float3 c) { - const float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} -float3 rgb_to_hsv(const float3 c) { - const float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g)); - float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r)); - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; - return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); -} -struct SPIRV_Cross_Output { float4 color0 : SV_Target0; float4 color1 : SV_Target1; float4 color2 : SV_Target2; }; -SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) { - float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0); - float4 col1 = tex1.SampleLevel(_tex1_sampler, texCoord, 0); - float4 col2 = tex2.SampleLevel(_tex2_sampler, texCoord, 0); - float4 cola = texa.SampleLevel(_texa_sampler, texCoord, 0); - float4 colb = texb.SampleLevel(_texb_sampler, texCoord, 0); - float4 colc = texc.SampleLevel(_texc_sampler, texCoord, 0); - float str = col0.a * opac; - SPIRV_Cross_Output stage_output; - if (blending == 0) { // Mix - stage_output.color0 = float4(lerp(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 1) { // Darken - stage_output.color0 = float4(lerp(cola.rgb, min(cola.rgb, col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 2) { // Multiply - stage_output.color0 = float4(lerp(cola.rgb, cola.rgb * col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 3) { // Burn - stage_output.color0 = float4(lerp(cola.rgb, float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - cola.rgb) / col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 4) { // Lighten - stage_output.color0 = float4(max(cola.rgb, col0.rgb * str), max(col0.a, cola.a)); - } - else if (blending == 5) { // Screen - stage_output.color0 = float4((float3(1.0, 1.0, 1.0) - (float3(1.0 - str, 1.0 - str, 1.0 - str) + str * (float3(1.0, 1.0, 1.0) - col0.rgb)) * (float3(1.0, 1.0, 1.0) - cola.rgb)), max(col0.a, cola.a)); - } - else if (blending == 6) { // Dodge - stage_output.color0 = float4(lerp(cola.rgb, cola.rgb / (float3(1.0, 1.0, 1.0) - col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 7) { // Add - stage_output.color0 = float4(lerp(cola.rgb, cola.rgb + col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 8) { // Overlay - stage_output.color0 = float4(lerp(cola.rgb, (cola.rgb < float3(0.5, 0.5, 0.5) ? float3(2.0, 2.0, 2.0) * cola.rgb * col0.rgb : float3(1.0, 1.0, 1.0) - float3(2.0, 2.0, 2.0) * (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)), str), max(col0.a, cola.a)); - } - else if (blending == 9) { // Soft Light - stage_output.color0 = float4(((1.0 - str) * cola.rgb + str * ((float3(1.0, 1.0, 1.0) - cola.rgb) * col0.rgb * cola.rgb + cola.rgb * (float3(1.0, 1.0, 1.0) - (float3(1.0, 1.0, 1.0) - col0.rgb) * (float3(1.0, 1.0, 1.0) - cola.rgb)))), max(col0.a, cola.a)); - } - else if (blending == 10) { // Linear Light - stage_output.color0 = float4((cola.rgb + str * (float3(2.0, 2.0, 2.0) * (col0.rgb - float3(0.5, 0.5, 0.5)))), max(col0.a, cola.a)); - } - else if (blending == 11) { // Difference - stage_output.color0 = float4(lerp(cola.rgb, abs(cola.rgb - col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 12) { // Subtract - stage_output.color0 = float4(lerp(cola.rgb, cola.rgb - col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 13) { // Divide - stage_output.color0 = float4(float3(1.0 - str, 1.0 - str, 1.0 - str) * cola.rgb + float3(str, str, str) * cola.rgb / col0.rgb, max(col0.a, cola.a)); - } - else if (blending == 14) { // Hue - stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else if (blending == 15) { // Saturation - stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else if (blending == 16) { // Color - stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else { // Value - stage_output.color0 = float4(lerp(cola.rgb, hsv_to_rgb(float3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(col0.rgb).b)), str), max(col0.a, cola.a)); - } - stage_output.color1 = float4(lerp(colb, col1, str)); - stage_output.color2 = float4(lerp(colc, col2, str)); - return stage_output; -} -"; - public static var maskMergeFrag = " -Texture2D tex0; -SamplerState _tex0_sampler; -Texture2D texa; -SamplerState _texa_sampler; -struct SPIRV_Cross_Output { float4 color0 : SV_Target0; }; -SPIRV_Cross_Output main(float2 texCoord : TEXCOORD0) { - float4 col0 = tex0.SampleLevel(_tex0_sampler, texCoord, 0); - float mask = texa.SampleLevel(_texa_sampler, texCoord, 0).r; - SPIRV_Cross_Output stage_output; - stage_output.color0 = float4(col0.rgb, col0.a * mask); - return stage_output; -} -"; - - #else // kha_opengl - - public static var layerMergeVert = "#version 330 -in vec2 pos; -out vec2 texCoord; -void main() { - gl_Position = vec4(pos.xy, 0.0, 1.0); - const vec2 madd = vec2(0.5, 0.5); - texCoord = pos.xy * madd + madd; -} -"; - public static var layerMergeFrag = "#version 330 -uniform sampler2D tex0; -uniform sampler2D tex1; -uniform sampler2D tex2; -uniform sampler2D texa; -uniform sampler2D texb; -uniform sampler2D texc; -uniform float opac; -uniform int blending; -in vec2 texCoord; -out vec4 FragColor[3]; -vec3 hsv_to_rgb(const vec3 c) { - const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} -vec3 rgb_to_hsv(const vec3 c) { - const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); - vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; - return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); -} -void main() { - vec4 col0 = textureLod(tex0, texCoord, 0); - vec4 col1 = textureLod(tex1, texCoord, 0); - vec4 col2 = textureLod(tex2, texCoord, 0); - vec4 cola = textureLod(texa, texCoord, 0); - vec4 colb = textureLod(texb, texCoord, 0); - vec4 colc = textureLod(texc, texCoord, 0); - float str = col0.a * opac; - if (blending == 0) { // Mix - FragColor[0] = vec4(mix(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 1) { // Darken - FragColor[0] = vec4(mix(cola.rgb, min(cola.rgb, col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 2) { // Multiply - FragColor[0] = vec4(mix(cola.rgb, cola.rgb * col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 3) { // Burn - FragColor[0] = vec4(mix(cola.rgb, vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - cola.rgb) / col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 4) { // Lighten - FragColor[0] = vec4(max(cola.rgb, col0.rgb * str), max(col0.a, cola.a)); - } - else if (blending == 5) { // Screen - FragColor[0] = vec4((vec3(1.0, 1.0, 1.0) - (vec3(1.0 - str, 1.0 - str, 1.0 - str) + str * (vec3(1.0, 1.0, 1.0) - col0.rgb)) * (vec3(1.0, 1.0, 1.0) - cola.rgb)), max(col0.a, cola.a)); - } - else if (blending == 6) { // Dodge - FragColor[0] = vec4(mix(cola.rgb, cola.rgb / (vec3(1.0, 1.0, 1.0) - col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 7) { // Add - FragColor[0] = vec4(mix(cola.rgb, cola.rgb + col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 8) { // Overlay - //FragColor[0] = vec4(mix(cola.rgb, (cola.rgb < vec3(0.5, 0.5, 0.5) ? vec3(2.0, 2.0, 2.0) * cola.rgb * col0.rgb : vec3(1.0, 1.0, 1.0) - vec3(2.0, 2.0, 2.0) * (vec3(1.0, 1.0, 1.0) - col0.rgb) * (vec3(1.0, 1.0, 1.0) - cola.rgb)), str), max(col0.a, cola.a)); // TODO - FragColor[0] = vec4(mix(cola.rgb, col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 9) { // Soft Light - FragColor[0] = vec4(((1.0 - str) * cola.rgb + str * ((vec3(1.0, 1.0, 1.0) - cola.rgb) * col0.rgb * cola.rgb + cola.rgb * (vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - col0.rgb) * (vec3(1.0, 1.0, 1.0) - cola.rgb)))), max(col0.a, cola.a)); - } - else if (blending == 10) { // Linear Light - FragColor[0] = vec4((cola.rgb + str * (vec3(2.0, 2.0, 2.0) * (col0.rgb - vec3(0.5, 0.5, 0.5)))), max(col0.a, cola.a)); - } - else if (blending == 11) { // Difference - FragColor[0] = vec4(mix(cola.rgb, abs(cola.rgb - col0.rgb), str), max(col0.a, cola.a)); - } - else if (blending == 12) { // Subtract - FragColor[0] = vec4(mix(cola.rgb, cola.rgb - col0.rgb, str), max(col0.a, cola.a)); - } - else if (blending == 13) { // Divide - FragColor[0] = vec4(vec3(1.0 - str, 1.0 - str, 1.0 - str) * cola.rgb + vec3(str, str, str) * cola.rgb / col0.rgb, max(col0.a, cola.a)); - } - else if (blending == 14) { // Hue - FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else if (blending == 15) { // Saturation - FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else if (blending == 16) { // Color - FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(col0.rgb).r, rgb_to_hsv(col0.rgb).g, rgb_to_hsv(cola.rgb).b)), str), max(col0.a, cola.a)); - } - else { // Value - FragColor[0] = vec4(mix(cola.rgb, hsv_to_rgb(vec3(rgb_to_hsv(cola.rgb).r, rgb_to_hsv(cola.rgb).g, rgb_to_hsv(col0.rgb).b)), str), max(col0.a, cola.a)); - } - FragColor[1] = vec4(mix(colb, col1, str)); - FragColor[2] = vec4(mix(colc, col2, str)); -} -"; - public static var maskMergeFrag = "#version 330 -uniform sampler2D tex0; -uniform sampler2D texa; -in vec2 texCoord; -out vec4 FragColor; -void main() { - vec4 col0 = textureLod(tex0, texCoord, 0); - float mask = textureLod(texa, texCoord, 0).r; - FragColor = vec4(col0.rgb, col0.a * mask); -} -"; - #end - - #if (kha_direct3d11 || kha_direct3d12) - - public static var cursorVert = " -uniform float4x4 VP; -uniform float4x4 invVP; -uniform float2 mouse; -uniform float2 step; -uniform float radius; -Texture2D texa; // direct3d12 unit align -SamplerState _texa_sampler; // direct3d12 unit align -Texture2D gbufferD; -SamplerState _gbufferD_sampler; -Texture2D gbuffer0; -SamplerState _gbuffer0_sampler; -float2 octahedronWrap(float2 v) { return (1.0 - abs(v.yx)) * (float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0)); } -float3x3 rotAxis(float3 axis, float a) { - float c = cos(a); - float3 as = axis * sin(a).xxx; - float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis); - float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c); - return p * (1.0 - c) + q; -} -float3 getNormal(float2 uv) { - float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, uv, 0.0).rg; - float3 n; - n.z = 1.0 - abs(g0.x) - abs(g0.y); - n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy); - return n; -} -struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; }; -SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 tex : TEXCOORD2) { - SPIRV_Cross_Output stage_output; - stage_output.texCoord = tex; - float2 mouseinv = float2(mouse.x, 1.0 - mouse.y); - float depth = gbufferD.SampleLevel(_gbufferD_sampler, mouseinv, 0).r; - float keep = texa.SampleLevel(_texa_sampler, mouseinv, 0).r; // direct3d12 unit align - depth += keep * 0.0; // direct3d12 unit align - float4 wpos = float4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); - wpos = mul(wpos, invVP); - wpos.xyz /= wpos.w; - float3 n = normalize( - getNormal(mouseinv + float2(step.x, step.y)) + - getNormal(mouseinv + float2(-step.x, step.y)) + - getNormal(mouseinv + float2(-step.x, -step.y)) + - getNormal(mouseinv + float2(step.x, -step.y)) + - getNormal(mouseinv) - ); - float ax = acos(dot(float3(1,0,0), float3(n.x,0,0))); - float az = acos(dot(float3(0,0,1), float3(0,0,n.z))); - float sy = -sign(n.y); - wpos.xyz += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)), - rotAxis(float3(1,0,0), -az * sy + 3.14/2)); - stage_output.gl_Position = mul(float4(wpos.xyz, 1.0), VP); - stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; - return stage_output; -} -"; - public static var cursorFrag = " -Texture2D tex; -SamplerState _tex_sampler; -float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 { - float4 col = tex.Sample(_tex_sampler, texCoord); - return float4(col.rgb / col.a, col.a); -} -"; - - #else // kha_opengl - - public static var cursorVert = "#version 330 -uniform mat4 VP; -uniform mat4 invVP; -uniform vec2 mouse; -uniform vec2 step; -uniform float radius; -uniform sampler2D gbufferD; -uniform sampler2D gbuffer0; -in vec4 pos; -in vec2 nor; -in vec2 tex; -out vec2 texCoord; -vec2 octahedronWrap(const vec2 v) { return (1.0 - abs(v.yx)) * (vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0)); } -mat3 rotAxis(vec3 axis, float a) { - float c = cos(a); - vec3 as = axis * sin(a); - mat3 p = mat3(axis.x * axis, axis.y * axis, axis.z * axis); - mat3 q = mat3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c); - return p * (1.0 - c) + q; -} -vec3 getNormal(vec2 uv) { - vec2 g0 = textureLod(gbuffer0, mouse, 0.0).rg; - vec3 n; - n.z = 1.0 - abs(g0.x) - abs(g0.y); - n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy); - return n; -} -void main() { - texCoord = tex; - float depth = textureLod(gbufferD, mouse, 0.0).r; - vec4 wpos = vec4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); - wpos = invVP * wpos; - wpos.xyz /= wpos.w; - vec3 n = normalize( - getNormal(mouse + vec2(step.x, step.y)) + - getNormal(mouse + vec2(-step.x, step.y)) + - getNormal(mouse + vec2(-step.x, -step.y)) + - getNormal(mouse + vec2(step.x, -step.y)) + - getNormal(mouse) - ); - float ax = acos(dot(vec3(1,0,0), vec3(n.x,0,0))); - float az = acos(dot(vec3(0,0,1), vec3(0,0,n.z))); - float sy = -sign(n.y); - wpos.xyz += - rotAxis(vec3(1,0,0), -az * sy + 3.14/2) * - rotAxis(vec3(0,0,1), ax + 3.14/2) * - (pos.xyz * radius); - gl_Position = VP * vec4(wpos.xyz, 1.0); -} -"; - public static var cursorFrag = "#version 330 -uniform sampler2D tex; -in vec2 texCoord; -out vec4 FragColor; -void main() { - vec4 col = texture(tex, texCoord); - FragColor = vec4(col.rgb / col.a, col.a); -} -"; - - #end - public static var font_x0 = [1,2,6,10,18,25,34,42,45,50,55,61,68,71,75,79,85,92,97,104,111,118,1,8,15,22,29,32,35,41,48,55,61,72,81,89,97,105,112,119,1,9,13,20,28,35,45,53,61,69,77,85,93,101,109,1,12,20,28,36,40,46,50,56,62,66,73,80,87,94,101,106,113,120,123,1,8,11,21,28,35,42,49,54,61,66,73,80,90,97,104,111,116,119,1]; public static var font_y0 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,62]; public static var font_x1 = [1,5,9,17,24,33,41,44,49,54,60,67,70,74,78,84,91,96,103,110,117,124,7,14,21,28,31,34,40,47,54,60,71,80,88,96,104,111,118,126,8,12,19,27,34,44,52,60,68,76,84,92,100,108,116,11,19,27,35,39,45,49,55,61,65,72,79,86,93,100,105,112,119,122,126,7,10,20,27,34,41,48,53,60,65,72,79,89,96,103,110,115,118,123,8]; diff --git a/Sources/arm/ui/TabBrowser.hx b/Sources/arm/ui/TabBrowser.hx index e36689f8..1ef712c3 100644 --- a/Sources/arm/ui/TabBrowser.hx +++ b/Sources/arm/ui/TabBrowser.hx @@ -12,6 +12,7 @@ class TabBrowser { if (ui.tab(UITrait.inst.htab2, "Browser")) { var h = Id.handle(); h.text = ui.textInput(h, "Path"); + Ext.dataPath = iron.data.Data.dataPath; Ext.fileBrowser(ui, h); } } diff --git a/Sources/arm/ui/UIFiles.hx b/Sources/arm/ui/UIFiles.hx index 3b77695c..3f54831b 100644 --- a/Sources/arm/ui/UIFiles.hx +++ b/Sources/arm/ui/UIFiles.hx @@ -63,6 +63,7 @@ class UIFiles { filesDone((known || isSave) ? path : path + sep + filename); if (known) pathHandle.text = pathHandle.text.substr(0, pathHandle.text.lastIndexOf(sep)); } + zui.Ext.dataPath = iron.data.Data.dataPath; path = zui.Ext.fileBrowser(ui, pathHandle, false); if (pathHandle.changed) ui.currentWindow.redraws = 3; } diff --git a/Sources/arm/ui/UIView2D.hx b/Sources/arm/ui/UIView2D.hx index af72a41d..cdd84275 100644 --- a/Sources/arm/ui/UIView2D.hx +++ b/Sources/arm/ui/UIView2D.hx @@ -38,8 +38,8 @@ class UIView2D { inst = this; pipe = new PipelineState(); - pipe.vertexShader = VertexShader.fromSource(ConstData.layerViewVert); - pipe.fragmentShader = FragmentShader.fromSource(ConstData.layerViewFrag); + pipe.vertexShader = Reflect.field(kha.Shaders, "layer_view_vert"); + pipe.fragmentShader = Reflect.field(kha.Shaders, "layer_view_frag"); var vs = new VertexStructure(); vs.add("pos", VertexData.Float3); vs.add("tex", VertexData.Float2); diff --git a/khafile.js b/khafile.js index 3d723e62..d4e8adcf 100644 --- a/khafile.js +++ b/khafile.js @@ -91,6 +91,12 @@ else { // painter, creator if (build === 'painter') { project.addAssets("Bundled/painter/*", { notinlist: true, destination: "data/{name}" }); project.addShaders("Shaders/painter/*.glsl", { noembed: false}); + if (process.platform === 'win32') { + project.addShaders("Shaders/painter/hlsl/*.glsl", { noprocessing: true, noembed: false }); + } + else { + project.addShaders("Shaders/painter/glsl/*.glsl", { noembed: false }); + } project.addDefine('kha_no_ogg'); } else {