From 4668cde2fdfc1b4f559ecba984fc1300f7e5d868 Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:51:05 +0200 Subject: [PATCH] GLSL node now use HLSL --- PixelComposer.resource_order | 1 - PixelComposer.yyp | 2 - scripts/d3d_object/d3d_object.gml | 1 + scripts/luaHighlight/luaHighlight.gml | 7 ++-- scripts/node_hlsl/node_hlsl.gml | 60 ++++++++++++++++++++------- scripts/textArea/textArea.gml | 15 ++++++- scripts/textBox/textBox.gml | 3 +- shaders/sh_dummy_0/sh_dummy_0.fsh | 28 ------------- shaders/sh_dummy_0/sh_dummy_0.vsh | 35 ---------------- shaders/sh_dummy_0/sh_dummy_0.yy | 10 ----- 10 files changed, 64 insertions(+), 98 deletions(-) delete mode 100644 shaders/sh_dummy_0/sh_dummy_0.fsh delete mode 100644 shaders/sh_dummy_0/sh_dummy_0.vsh delete mode 100644 shaders/sh_dummy_0/sh_dummy_0.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 9d211e17b..9e6d8b952 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -171,7 +171,6 @@ {"name":"color picker","order":56,"path":"folders/shader/color picker.yy",}, {"name":"color selector","order":51,"path":"folders/shader/color selector.yy",}, {"name":"draw","order":39,"path":"folders/shader/draw.yy",}, - {"name":"dummy","order":57,"path":"folders/shader/dummy.yy",}, {"name":"filter","order":30,"path":"folders/shader/filter.yy",}, {"name":"color","order":53,"path":"folders/shader/filter/color.yy",}, {"name":"shadow caster","order":46,"path":"folders/shader/filter/shadow caster.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index e0653b6de..7d0335b42 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -205,7 +205,6 @@ {"resourceType":"GMFolder","resourceVersion":"1.0","name":"color picker","folderPath":"folders/shader/color picker.yy",}, {"resourceType":"GMFolder","resourceVersion":"1.0","name":"color selector","folderPath":"folders/shader/color selector.yy",}, {"resourceType":"GMFolder","resourceVersion":"1.0","name":"draw","folderPath":"folders/shader/draw.yy",}, - {"resourceType":"GMFolder","resourceVersion":"1.0","name":"dummy","folderPath":"folders/shader/dummy.yy",}, {"resourceType":"GMFolder","resourceVersion":"1.0","name":"filter","folderPath":"folders/shader/filter.yy",}, {"resourceType":"GMFolder","resourceVersion":"1.0","name":"color","folderPath":"folders/shader/filter/color.yy",}, {"resourceType":"GMFolder","resourceVersion":"1.0","name":"shadow caster","folderPath":"folders/shader/filter/shadow caster.yy",}, @@ -1127,7 +1126,6 @@ {"id":{"name":"s_node_pack_sprite","path":"sprites/s_node_pack_sprite/s_node_pack_sprite.yy",},}, {"id":{"name":"surface_valid","path":"scripts/surface_valid/surface_valid.yy",},}, {"id":{"name":"steam_ugc_collection","path":"scripts/steam_ugc_collection/steam_ugc_collection.yy",},}, - {"id":{"name":"sh_dummy_0","path":"shaders/sh_dummy_0/sh_dummy_0.yy",},}, {"id":{"name":"sh_blur_zoom","path":"shaders/sh_blur_zoom/sh_blur_zoom.yy",},}, {"id":{"name":"node_VFX_renderer","path":"scripts/node_VFX_renderer/node_VFX_renderer.yy",},}, {"id":{"name":"s_node_pb_fx_stack","path":"sprites/s_node_pb_fx_stack/s_node_pb_fx_stack.yy",},}, diff --git a/scripts/d3d_object/d3d_object.gml b/scripts/d3d_object/d3d_object.gml index efd44fe77..54a52a247 100644 --- a/scripts/d3d_object/d3d_object.gml +++ b/scripts/d3d_object/d3d_object.gml @@ -82,6 +82,7 @@ function __3dObject() constructor { } } vertex_end(_buffer); + vertex_freeze(_buffer); return _buffer; } #endregion diff --git a/scripts/luaHighlight/luaHighlight.gml b/scripts/luaHighlight/luaHighlight.gml index 9d86ed1b3..fb11ff7b4 100644 --- a/scripts/luaHighlight/luaHighlight.gml +++ b/scripts/luaHighlight/luaHighlight.gml @@ -6,17 +6,18 @@ var reserved = ["and", "break", "do", "else", "elseif", "end", "false", for( var i = 0, n = array_length(reserved); i < n; i++ ) global.lua_reserved[? reserved[i]] = 1; +global.CODE_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ",", ";", "+", "-", "*", "/", "^", "="]; + function token_splice(str) { var st = []; var ss = str; var sp; var cc; - var tk = [" ", "(", ")", "[", "]", "{", "}", ",", ";", "+", "-", "*", "/", "^", "="]; do { sp = 999999; - for( var i = 0, n = array_length(tk); i < n; i++ ) { - var _pos = string_pos(tk[i], ss); + for( var i = 0, n = array_length(global.CODE_BREAK_TOKEN); i < n; i++ ) { + var _pos = string_pos(global.CODE_BREAK_TOKEN[i], ss); if(_pos != 0) sp = min(sp, _pos); } diff --git a/scripts/node_hlsl/node_hlsl.gml b/scripts/node_hlsl/node_hlsl.gml index efb8ef5be..d855dd525 100644 --- a/scripts/node_hlsl/node_hlsl.gml +++ b/scripts/node_hlsl/node_hlsl.gml @@ -1,3 +1,30 @@ +#region vb + vertex_format_begin(); + vertex_format_add_position(); + vertex_format_add_color(); + vertex_format_add_texcoord(); + global.HLSL_VB_FORMAT = vertex_format_end(); + + global.HLSL_VB = vertex_create_buffer(); + vertex_begin(global.HLSL_VB, global.HLSL_VB_FORMAT); + vertex_position(global.HLSL_VB, 0, 0); + vertex_color(global.HLSL_VB, c_white, 1); + vertex_texcoord(global.HLSL_VB, 0, 0); + + vertex_position(global.HLSL_VB, 0, 1); + vertex_color(global.HLSL_VB, c_white, 1); + vertex_texcoord(global.HLSL_VB, 0, 1); + + vertex_position(global.HLSL_VB, 1, 0); + vertex_color(global.HLSL_VB, c_white, 1); + vertex_texcoord(global.HLSL_VB, 1, 0); + + vertex_position(global.HLSL_VB, 1, 1); + vertex_color(global.HLSL_VB, c_white, 1); + vertex_texcoord(global.HLSL_VB, 1, 1); + vertex_end(global.HLSL_VB); +#endregion + function Node_HLSL(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { name = "HLSL"; shader = { vs: -1, fs: -1 }; @@ -7,8 +34,8 @@ function Node_HLSL(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons .rejectArray(); inputs[| 1] = nodeValue("Fragment", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, -@"float4 combinedColour = gm_BaseTextureObject.Sample(gm_BaseTexture, input.uv); -return combinedColour;") +@"float4 surfaceColor = gm_BaseTextureObject.Sample(gm_BaseTexture, input.uv); +output.color = surfaceColor;") .setDisplay(VALUE_DISPLAY.codeHLSL) .rejectArray(); @@ -61,7 +88,7 @@ cbuffer Matrices : register(b0) { struct VertexShaderInput { float3 pos : POSITION; - float4 color : COLOR0; + float3 color : COLOR0; float2 uv : TEXCOORD0; }; @@ -70,13 +97,9 @@ struct VertexShaderOutput { float2 uv : TEXCOORD0; }; -VertexShaderOutput main(VertexShaderInput input) { - VertexShaderOutput output; - +void main(in VertexShaderInput input, out VertexShaderOutput output) { output.pos = mul(gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION], float4(input.pos, 1.0f)); output.uv = input.uv; - - return output; }"; file_text_write_all(_dir + "vout.shader", vs); @@ -84,10 +107,14 @@ VertexShaderOutput main(VertexShaderInput input) { Texture2D gm_BaseTextureObject : register(t0); SamplerState gm_BaseTexture : register(s0); -struct PixelShaderInput { +struct VertexShaderOutput { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; }; + +struct PixelShaderOutput { + float4 color : SV_Target0; +}; " var fs_param = ""; var sampler_slot = 1; @@ -111,18 +138,18 @@ struct PixelShaderInput { } } - var fs_pos = "float4 main(PixelShaderInput input) : SV_TARGET {" + fs + "}"; + var fs_pos = "\nvoid main(in VertexShaderOutput input, out PixelShaderOutput output) {\n" + fs + "\n}"; fs = fs_pre + fs_param + fs_pos; file_text_write_all(_dir + "fout.shader", fs); shader.vs = d3d11_shader_compile_vs(_dir + "vout.shader", "main", "vs_4_0"); if (!d3d11_shader_exists(shader.vs)) - print(d3d11_get_error_string()); + noti_warning(d3d11_get_error_string()); shader.fs = d3d11_shader_compile_ps(_dir + "fout.shader", "main", "ps_4_0"); if (!d3d11_shader_exists(shader.fs)) - print(d3d11_get_error_string()); + noti_warning(d3d11_get_error_string()); } static onValueUpdate = function(index) { @@ -132,6 +159,7 @@ struct PixelShaderInput { static processData = function(_output, _data, _output_index, _array_index = 0) { var _surf = _data[2]; + if(!is_surface(_surf)) return; _output = surface_verify(_output, surface_get_width(_surf), surface_get_height(_surf)); surface_set_target(_output); @@ -158,7 +186,9 @@ struct PixelShaderInput { } } - draw_surface_safe(_surf); + matrix_set(matrix_world, matrix_build(0, 0, 0, 0, 0, 0, surface_get_width(_surf), surface_get_height(_surf), 1)); + vertex_submit(global.HLSL_VB, pr_trianglestrip, surface_get_texture(_surf)); + matrix_set(matrix_world, matrix_build_identity()); d3d11_shader_override_vs(-1); d3d11_shader_override_ps(-1); @@ -167,7 +197,5 @@ struct PixelShaderInput { return _output; } - static postConnect = function() { - refreshShader(); - } + static postConnect = function() { refreshShader(); } } \ No newline at end of file diff --git a/scripts/textArea/textArea.gml b/scripts/textArea/textArea.gml index c19c62e6d..b06ddd65f 100644 --- a/scripts/textArea/textArea.gml +++ b/scripts/textArea/textArea.gml @@ -143,6 +143,16 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod } } #endregion + static breakCharacter = function(ch) { #region + switch(format) { + case TEXT_AREA_FORMAT.codeHLSL : + case TEXT_AREA_FORMAT.codeLUA : + return ch == "\n" || array_exists(global.CODE_BREAK_TOKEN, ch); + default : + return ch == " " || ch == "\n"; + } + } #endregion + static onKey = function(key) { #region if(key == vk_left) { if(key_mod_press(SHIFT)) { @@ -155,7 +165,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod if(key_mod_press(CTRL)) { while(cursor > 0) { var ch = string_char_at(_input_text, cursor); - if(ch == " " || ch == "\n") break; + if(breakCharacter(ch)) break; cursor--; } } @@ -171,7 +181,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod if(key_mod_press(CTRL)) { while(cursor < string_length(_input_text)) { var ch = string_char_at(_input_text, cursor); - if(ch == " " || ch == "\n") break; + if(breakCharacter(ch)) break; cursor++; } } @@ -585,6 +595,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod if(target != -999) { if(mouse_press(mb_left, active) || click_block == 1) { cursor_select = target; + cursor = target; click_block = 0; } else if(mouse_click(mb_left, active) && cursor != target) cursor = target; diff --git a/scripts/textBox/textBox.gml b/scripts/textBox/textBox.gml index f11d5a86f..2b3ddfd95 100644 --- a/scripts/textBox/textBox.gml +++ b/scripts/textBox/textBox.gml @@ -273,7 +273,8 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi if(target != -999) { if(mouse_press(mb_left, active) || click_block == 1) { cursor_select = target; - click_block = 0; + cursor = target; + click_block = 0; } else if(mouse_click(mb_left, active) && cursor != target) cursor = target; } diff --git a/shaders/sh_dummy_0/sh_dummy_0.fsh b/shaders/sh_dummy_0/sh_dummy_0.fsh deleted file mode 100644 index a19c75703..000000000 --- a/shaders/sh_dummy_0/sh_dummy_0.fsh +++ /dev/null @@ -1,28 +0,0 @@ -varying vec2 v_vTexcoord; - -uniform float u_float_0, u_float_1, u_float_2, u_float_3, u_float_4, u_float_5, u_float_6, u_float_7; -uniform float u_float_8, u_float_9, u_float_10, u_float_11, u_float_12, u_float_13, u_float_14, u_float_15; - -uniform int u_int_0, u_int_1, u_int_2, u_int_3, u_int_4, u_int_5, u_int_6, u_int_7; -uniform int u_int_8, u_int_9, u_int_10, u_int_11, u_int_12, u_int_13, u_int_14, u_int_15; - -uniform vec2 u_vec2_0, u_vec2_1, u_vec2_2, u_vec2_3, u_vec2_4, u_vec2_5, u_vec2_6, u_vec2_7; -uniform vec2 u_vec2_8, u_vec2_9, u_vec2_10, u_vec2_11, u_vec2_12, u_vec2_13, u_vec2_14, u_vec2_15; - -uniform vec3 u_vec3_0, u_vec3_1, u_vec3_2, u_vec3_3, u_vec3_4, u_vec3_5, u_vec3_6, u_vec3_7; -uniform vec3 u_vec3_8, u_vec3_9, u_vec3_10, u_vec3_11, u_vec3_12, u_vec3_13, u_vec3_14, u_vec3_15; - -uniform vec4 u_vec4_0, u_vec4_1, u_vec4_2, u_vec4_3, u_vec4_4, u_vec4_5, u_vec4_6, u_vec4_7; -uniform vec4 u_vec4_8, u_vec4_9, u_vec4_10, u_vec4_11, u_vec4_12, u_vec4_13, u_vec4_14, u_vec4_15; - -uniform mat3 u_mat3_0, u_mat3_1, u_mat3_2, u_mat3_3, u_mat3_4, u_mat3_5, u_mat3_6, u_mat3_7; -uniform mat3 u_mat3_8, u_mat3_9, u_mat3_10, u_mat3_11, u_mat3_12, u_mat3_13, u_mat3_14, u_mat3_15; - -uniform mat4 u_mat4_0, u_mat4_1, u_mat4_2, u_mat4_3, u_mat4_4, u_mat4_5, u_mat4_6, u_mat4_7; -uniform mat4 u_mat4_8, u_mat4_9, u_mat4_10, u_mat4_11, u_mat4_12, u_mat4_13, u_mat4_14, u_mat4_15; - -uniform sampler2D u_sampler2D_0, u_sampler2D_1, u_sampler2D_2, u_sampler2D_3, u_sampler2D_4, u_sampler2D_5, u_sampler2D_6; - -void main() { - gl_FragColor = texture2D( gm_BaseTexture, v_vTexcoord ); -} diff --git a/shaders/sh_dummy_0/sh_dummy_0.vsh b/shaders/sh_dummy_0/sh_dummy_0.vsh deleted file mode 100644 index 394c01ae4..000000000 --- a/shaders/sh_dummy_0/sh_dummy_0.vsh +++ /dev/null @@ -1,35 +0,0 @@ -attribute vec3 in_Position; -attribute vec4 in_Colour; -attribute vec2 in_TextureCoord; - -varying vec2 v_vTexcoord; - -uniform float u_float_0, u_float_1, u_float_2, u_float_3, u_float_4, u_float_5, u_float_6, u_float_7; -uniform float u_float_8, u_float_9, u_float_10, u_float_11, u_float_12, u_float_13, u_float_14, u_float_15; - -uniform int u_int_0, u_int_1, u_int_2, u_int_3, u_int_4, u_int_5, u_int_6, u_int_7; -uniform int u_int_8, u_int_9, u_int_10, u_int_11, u_int_12, u_int_13, u_int_14, u_int_15; - -uniform vec2 u_vec2_0, u_vec2_1, u_vec2_2, u_vec2_3, u_vec2_4, u_vec2_5, u_vec2_6, u_vec2_7; -uniform vec2 u_vec2_8, u_vec2_9, u_vec2_10, u_vec2_11, u_vec2_12, u_vec2_13, u_vec2_14, u_vec2_15; - -uniform vec3 u_vec3_0, u_vec3_1, u_vec3_2, u_vec3_3, u_vec3_4, u_vec3_5, u_vec3_6, u_vec3_7; -uniform vec3 u_vec3_8, u_vec3_9, u_vec3_10, u_vec3_11, u_vec3_12, u_vec3_13, u_vec3_14, u_vec3_15; - -uniform vec4 u_vec4_0, u_vec4_1, u_vec4_2, u_vec4_3, u_vec4_4, u_vec4_5, u_vec4_6, u_vec4_7; -uniform vec4 u_vec4_8, u_vec4_9, u_vec4_10, u_vec4_11, u_vec4_12, u_vec4_13, u_vec4_14, u_vec4_15; - -uniform mat3 u_mat3_0, u_mat3_1, u_mat3_2, u_mat3_3, u_mat3_4, u_mat3_5, u_mat3_6, u_mat3_7; -uniform mat3 u_mat3_8, u_mat3_9, u_mat3_10, u_mat3_11, u_mat3_12, u_mat3_13, u_mat3_14, u_mat3_15; - -uniform mat4 u_mat4_0, u_mat4_1, u_mat4_2, u_mat4_3, u_mat4_4, u_mat4_5, u_mat4_6, u_mat4_7; -uniform mat4 u_mat4_8, u_mat4_9, u_mat4_10, u_mat4_11, u_mat4_12, u_mat4_13, u_mat4_14, u_mat4_15; - -uniform sampler2D u_sampler2D_0, u_sampler2D_1, u_sampler2D_2, u_sampler2D_3, u_sampler2D_4, u_sampler2D_5, u_sampler2D_6; - -void main() { - vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); - gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; - - v_vTexcoord = in_TextureCoord; -} diff --git a/shaders/sh_dummy_0/sh_dummy_0.yy b/shaders/sh_dummy_0/sh_dummy_0.yy deleted file mode 100644 index a8cc96c68..000000000 --- a/shaders/sh_dummy_0/sh_dummy_0.yy +++ /dev/null @@ -1,10 +0,0 @@ -{ - "resourceType": "GMShader", - "resourceVersion": "1.0", - "name": "sh_dummy_0", - "parent": { - "name": "dummy", - "path": "folders/shader/dummy.yy", - }, - "type": 1, -} \ No newline at end of file