From d2e1826865d745dbf8eb7670b49d5c88d4ecc297 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 19:58:06 -0800 Subject: [PATCH 01/11] Update universeclient.lua --- assets/opensb/scripts/opensb/universeclient/universeclient.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/opensb/scripts/opensb/universeclient/universeclient.lua b/assets/opensb/scripts/opensb/universeclient/universeclient.lua index cad342b..a534c25 100644 --- a/assets/opensb/scripts/opensb/universeclient/universeclient.lua +++ b/assets/opensb/scripts/opensb/universeclient/universeclient.lua @@ -1,2 +1,2 @@ require "/scripts/opensb/util/modules.lua" -modules("/scripts/opensb/universeclient/", {"voicemanager"}) \ No newline at end of file +modules("/scripts/opensb/universeclient/", {"voicemanager","loadconfig"}) From d63501aa07821ba79ae0b0ebf9e9f53b714a25c8 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 19:58:18 -0800 Subject: [PATCH 02/11] Add files via upload --- .../opensb/universeclient/loadconfig.lua | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 assets/opensb/scripts/opensb/universeclient/loadconfig.lua diff --git a/assets/opensb/scripts/opensb/universeclient/loadconfig.lua b/assets/opensb/scripts/opensb/universeclient/loadconfig.lua new file mode 100644 index 0000000..2bb3ef8 --- /dev/null +++ b/assets/opensb/scripts/opensb/universeclient/loadconfig.lua @@ -0,0 +1,22 @@ +-- Meant to manage loading various miscellaneous things from configuration, such as shader parameters. + +local module = {} +modules.config_loader = module + +function module.init() + local shaderConfig = root.getConfiguration("postProcessGroups") or {} + local postProcessGroups = renderer.postProcessGroups() + local changes = false + for k,v in next, shaderConfig do + local group = postProcessGroups[k] + if v.parameters then + for k2,v2 in next, group.parameters do + if v.parameters[k2] ~= nil then + for _,e in next, v2.effects do + renderer.setEffectParameter(e,k2,v.parameters[k2]) + end + end + end + end + end +end From e33d260e6d30a8b6d08c174fd9b315b9a10d6490 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:02:00 -0800 Subject: [PATCH 03/11] Add files via upload --- .../opensb/interface/opensb/shaders/select.png | Bin 0 -> 4583 bytes .../interface/opensb/shaders/selectend.png | Bin 0 -> 4094 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/opensb/interface/opensb/shaders/select.png create mode 100644 assets/opensb/interface/opensb/shaders/selectend.png diff --git a/assets/opensb/interface/opensb/shaders/select.png b/assets/opensb/interface/opensb/shaders/select.png new file mode 100644 index 0000000000000000000000000000000000000000..dc649b4e39a5fce11b972ded4b4f4c74f1b0d3da GIT binary patch literal 4583 zcmeHKd2ka|7~cxm8d?uPKn`8D9w2V^=x&l-leUl)8rwi9Efy8w?e5!lZITViwn-Uh zaN2@{!oc8o6hR%-swg1iP(?YEQ~$7D+=Cnnq6i}5bVd&K?WU(X<8%c7YG#t%_ulvY z-uL~!-?uNjAUJ7amTi~~!>}xWp|1p8Ys~wMzUX&vQOR@YvTaUjxlsZVcr>P~S_tAs zZ4}}#si_#2JQxl>IA9x|ap~kBPn~;Za>Q5r8xOyVRqm58uNEG4@*8RO>-9b3NQ%iDKI1H4O1HugE|qnhgR zWLAr6z!|zKf8QO(UgbguZqLL-xc)RyLo?O*#>aO@OS(CQFsY&ewll6`{ZxF z9=#~@`5AeErelknHZ%>a7;>^{?V+6~8m78K6N(#`1ivWzbhoe*Oy2Vs|%!J_3SCT+p68*(*N{PIAtDC=Q6 zP;?2}li?^*1%|ovl2IU6K?9dyg%0@!E(1l4K;FZ9=3l zd@wG@w5Xx!5!}QCl3s0i2m-C+?eT@9fj|d*B;LjX;)6vWOa+pT(Q#W8VGXl!0l$;p1Wm?tO5bir_0r5cz&OUF!vV~UDg!Q zx>X@VJAsQKT@EKhax5p166>T%nr0jlFUu^H*e+21NZbGs8JbWC+^!)U1*$@h#4;p= zoScGiaf(9b2&y6j7cEE(>;f@4rXf{=P}itTCuL*XS0N|D70dMpf3IkhmTfK)V6VJ(=1i{pZR55d~$&Y55c7%Fn`5XD-gI@!5U zs)gZH1DI?w&K#cOIDvN1PDWsuPNQis7Dq}nF&WyPr5wf5hv z&E~<~sgf6JakPJ}HI?e9sc?2`lp2OKtCeuvY6=m^sTAU%1}avZ2rIQDSAs|dL{E=4 zxwg-1|0D$diZ)lU)1NGCv%Ng47A$vL4)3Jd@w3mk&v zU}=SCUEPEJ?ZPkk z4D`sjS6#hy^@xEU8TYE|iqU23d?|(z^j|iCUU@=i$1I=$5wru%OG?{Mr0|n{dXO8TfW`C+-$HQof@%zS=7VbK;m$?bUGPmY`zh?`4 zWaaP$^+&$(@vDyyJN^3Tw`YA+*RTKJd-kuLak}x_KCAEQGvZLcQI8^L%wI6cw`TmT Gx<3Jaqd!pq literal 0 HcmV?d00001 diff --git a/assets/opensb/interface/opensb/shaders/selectend.png b/assets/opensb/interface/opensb/shaders/selectend.png new file mode 100644 index 0000000000000000000000000000000000000000..99908d61a2e3fb1a2badb9b1c0e756fc24b4382e GIT binary patch literal 4094 zcmeHKYitx%6kbXrrBEbDERs^jDU?@c=drV|p$oLT+jg-F+jh}{5twH?ba!XjnRa&z zLdv5R6jMMW6beE}QP6?{8o+=;3ci5wh!QAZs60b7G!l6T_0DXcfy6YCf8Atv?mhQA z-#O>I=icnB@J!1|N*tc3)9I32xsC$x?4yno;=%8c%RfiK~_+ z(I5};5mC_TA{YD~|DdB#!sAop%H!krMp6zQ;LPXmR%flfuxi=y<7w05AKrMpFDdHp18*ve`;~&ZqB?jA%FB= z_tG7y5g*x76hAKkx313m_`%n^y_Xv1oS)cG{|7cjdF#>k%Xcbrz6!7VL}o}%e@ORY z@^3=?D?@fBr8n$JtBSs#KKc8@6YE}>17**g8ah;Y02Bv{cDu)Ax3?DqO4wLe^TpJo zo}pET_ilwxJLeBxKCofLiQnhWNXS|~Y(i1pnQe{C5c`^fg?+C$M%FKd?hibfc=Cyv zvaD+yP~F-bJlT3>!Io>I@@MH&rqs?@o~-oyXz7IFTS*&6T=G6ZP^-EI_J*G9ZkDeuDZA=IBL=0iSuh4ua3DJ*m$h!M4%@9 z?9Jn6n~tUO$v5hET{zaftZ-pURo?m<&*{~|?Ud#($J`s6uz&lgHRGk={b|4{vKBqw889&wgatY5x2~H1%cr(!8Csn(=QYAGxjj zWix&4z^kPX{=PU|XsWorS^6igX`g5I$Y9!H&;}6^Y<-bCk76aip5`Qm*GK$8&=Wdc z#^gwlW=nYmV)$Y)V1xfWco>F6&IZ3>bYt$Ioi7n{D?)r>#WXKlQOa65c=Dvgj0gn? z{JcU#5x*}WQxO}i@ls%{no$_iAWEqXE^>PyyAlo8?ts=$%m zMge9vxI|Hc6pDt!VSU)3mqNuTZnaubj6ewj0SH8n1{6Ai1mrZ8BF5q1Wi})R6;TR6 zDksfIWr_`k!8+8QpFik!chCpqHWh##XoL=;xE@3OezdEHtT@X7Nn1kC^pL&a1fd1I zER}^=-dWBEl(eoC9NXa^EDQOxayS;{eY_t)We^qb7Ba`>_H=lt5)_O6pyma{?uJxE zp;N4Gxv48!Ib9P0?j5|{(CxKrV1RPFDTl8 z86jE1idc9OLky&aHPEb)r3I!7l`9}Cbb#emDnPCm0T0fa%@{`D2ySJp2+5E%LbE0T zp)Cvn>;}PXv38-D9uh%U(!Q=)sZ<=GG7)Bjkr9jtV-`q+G#D|&$}%c5XEibmW-$<$ zM#ZsIwiNQyU^_)WUCg7wK(V%<3QlEuTsD}{$Do?Uw^BGs8BGXgp|CD^i4%qBf1%aG17*av zJXe%K{HSJ%ov1>7ery(-`b6z0L6CMRD4LCxAk*bMr{xK_VoPiZ9Vq6(?a|h*?RN1Q ztzaey+$fkV2u@fC1T>Zzu?n04!D$o8S~wmzl7{Z=vLq;BI>cud108`@pglFMpt0IU zjq8pMm+Ub%YZ>X8CH0{3=TuUtJ+phw`|?)u;4O6+`{;sfAcP#C-{eY+=9 z0WVr{%xgIgoo>gfGy=@}2Xkl2I^BSm)NdbM?Z#oi*iUh}o&9bO9MN}> Date: Sat, 28 Dec 2024 20:02:37 -0800 Subject: [PATCH 04/11] Update shaders.config --- assets/opensb/interface/opensb/shaders/shaders.config | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/opensb/interface/opensb/shaders/shaders.config b/assets/opensb/interface/opensb/shaders/shaders.config index 5154831..864574e 100644 --- a/assets/opensb/interface/opensb/shaders/shaders.config +++ b/assets/opensb/interface/opensb/shaders/shaders.config @@ -3,7 +3,10 @@ "scriptDelta" : 0, "scriptWidgetCallbacks" : [ "selectGroup", - "toggleGroupEnabled" + "toggleGroupEnabled", + "sliderOptionModified", + "textboxOptionModified", + "selectOptionPressed" ], "gui" : { From ebabc7bf8e872b7659bb189c1e45b31dfd2f48ab Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:02:52 -0800 Subject: [PATCH 05/11] Update shaders.lua --- .../interface/opensb/shaders/shaders.lua | 152 +++++++++++++++++- 1 file changed, 147 insertions(+), 5 deletions(-) diff --git a/assets/opensb/interface/opensb/shaders/shaders.lua b/assets/opensb/interface/opensb/shaders/shaders.lua index 0030b5c..0c2d19c 100644 --- a/assets/opensb/interface/opensb/shaders/shaders.lua +++ b/assets/opensb/interface/opensb/shaders/shaders.lua @@ -17,6 +17,14 @@ local groups = {} local widgetsToGroups = {} local allSettings = {} +local shaderConfig + +function displayed() + shaderConfig = root.getConfiguration("postProcessGroups") +end +function dismissed() + shaderConfig = nil +end local function addGroupToList(data) local name = widget.addListItem(GROUP_LIST_WIDGET) @@ -67,7 +75,7 @@ local function addOptionGroup(data, i, added) added[#added + 1] = name local label = { type = "label", - value = data.name, + value = data.label, wrapWidth = 120, fontSize = 8, hAnchor = "mid", @@ -77,6 +85,16 @@ local function addOptionGroup(data, i, added) widget.addChild(fmt("%s.%s", BINDS_WIDGET, name), label, "text") end +local function digitRegex(n) + local i = 0 + while n ~= math.floor(n) do + n = n * 10 + i = i + 1 + end + return fmt("%%.%df",i) -- create format string %.nf, where n = %d (i with no decimal points) +end +local optionPrefix = "option_" +local optionOffset = #optionPrefix+1 local function addOption(data, i, added) local y = (i - 1) * -14 local bg = { @@ -84,12 +102,12 @@ local function addOption(data, i, added) file = PATH .. "optionname.png", position = {-12, y} } - local name = "label_" .. i + local name = "label_" .. data.name widget.addChild(OPTIONS_WIDGET, bg, name) added[#added + 1] = name local label = { type = "label", - value = data.name, + value = data.label, wrapWidth = 120, fontSize = 8, hAnchor = "mid", @@ -97,7 +115,115 @@ local function addOption(data, i, added) position = {62, 6} } widget.addChild(fmt("%s.%s", OPTIONS_WIDGET, name), label, "text") + local value = data.default or 0 + if not shaderConfig[activeGroup] then + shaderConfig[activeGroup] = {parameters={}} + end + if not shaderConfig[activeGroup].parameters then + shaderConfig[activeGroup].parameters = {} + end + if shaderConfig[activeGroup].parameters[data.name] ~= nil then + value = shaderConfig[activeGroup].parameters[data.name] + end + -- todo: finish this + if data.type == "slider" then + local range = data.range or {0,1} + local delta = data.delta or 0.01 + -- for some reason ranges require ints so + local r = {range[1]/delta, range[2]/delta, 1} + + local slider = { + type = "slider", + callback = "sliderOptionModified", + position = {110, y + 2}, + gridImage = "/interface/optionsmenu/smallselection.png", + range = r + } + name = optionPrefix..data.name + added[#added + 1] = name + widget.addChild(OPTIONS_WIDGET, slider, name) + + widget.setSliderValue(fmt("%s.%s",OPTIONS_WIDGET,name), value/delta) + local valLabel = { + type = "label", + value = fmt(digitRegex(delta),value), + position = {186, y + 2} + } + added[#added + 1] = name.."_value" + widget.addChild(OPTIONS_WIDGET, valLabel, name.."_value") + elseif data.type == "select" then + local n = #data.values + local width = math.floor(118/n) + local by = y + local buttons = {} + for i=0,n-1 do + local img = fmt("%sselect.png?crop=0;0;%.0f;13",PATH,width) + local button = { + type = "button", + callback="selectOptionPressed", + caption = data.values[i+1], + base = img, + hover = img.."?brightness=-25", + baseImageChecked = img.."?multiply=00ff00", + hoverImageChecked = img.."?multiply=00ff00?brightness=-25", + position = {110+width*i, by}, + pressedOffset = {0, 0}, + checkable = true, + checked = (value == i) + } + name = "select_"..data.name.."_"..i + added[#added + 1] = name + widget.addChild(OPTIONS_WIDGET, button, name) + table.insert(buttons,{widget=fmt("%s.%s",OPTIONS_WIDGET,name),index=i}) + end + for k,v in next, buttons do + widget.setData(v.widget,{option=data,index=v.index,buttons=buttons}) + end + --[[local bge = { + type = "image", + file = PATH.."selectend.png", + position = {110+width*3, by} + } + name = "bgend_"..data.name + added[#added + 1] = name + widget.addChild(OPTIONS_WIDGET, bge, name)]] + end +end + +function sliderOptionModified(option, odata) + local oname = string.sub(option, optionOffset) + local parameter = groups[activeGroup].parameters[oname] + local value = widget.getSliderValue(fmt("%s.%s",OPTIONS_WIDGET,option))*parameter.delta + + widget.setText(fmt("%s.%s",OPTIONS_WIDGET,option.."_value"), fmt(digitRegex(parameter.delta),value)) + + for k,v in next, parameter.effects do + renderer.setEffectParameter(v, oname, value) + end + shaderConfig[activeGroup].parameters[oname] = value + root.setConfiguration("postProcessGroups",shaderConfig) +end + +function selectOptionPressed(button,bdata) + sb.logInfo(sb.print(bdata)) + + for k,v in next, bdata.buttons do + if v.index ~= bdata.index then + widget.setChecked(v.widget, false) + end + end + + value = bdata.index + + local oname = bdata.option.name + local parameter = groups[activeGroup].parameters[oname] + + for k,v in next, parameter.effects do + renderer.setEffectParameter(v, oname, value) + end + shaderConfig[activeGroup].parameters[oname] = value + root.setConfiguration("postProcessGroups",shaderConfig) end local function addEnabled(groupname, i, added) @@ -139,6 +265,7 @@ end function toggleGroupEnabled(checkbox, cdata) renderer.setPostProcessGroupEnabled(activeGroup, widget.getChecked(fmt("%s.%s",OPTIONS_WIDGET,checkbox)), true) + shaderConfig = root.getConfiguration("postProcessGroups") end function selectGroup() @@ -163,7 +290,21 @@ function selectGroup() local added = {} local index = 0 addEnabled(group.groupId,index,added) - + if group.categories then + + elseif group.parameters then + local sortedParams = {} + for k,v in next, group.parameters do + v.name = k + sortedParams[#sortedParams+1] = v + end + table.sort(sortedParams, alphabeticalNameSortLesser) + + for k,v in next, sortedParams do + index = index + 1 + addOption(v, index, added) + end + end --[[ local categories = group.categories or {} if not categories.unsorted then @@ -198,7 +339,8 @@ function selectGroup() addOption(category.sortedOptions[iB], index, added) end end - end]] + end + ]] widget.setData(OPTIONS_WIDGET, added) end From 740cf89122b1010da4db21fb404f483c2f7a019f Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:04:19 -0800 Subject: [PATCH 06/11] Update StarRenderer_opengl.hpp --- source/application/StarRenderer_opengl.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/application/StarRenderer_opengl.hpp b/source/application/StarRenderer_opengl.hpp index 36b8354..79e5400 100644 --- a/source/application/StarRenderer_opengl.hpp +++ b/source/application/StarRenderer_opengl.hpp @@ -25,6 +25,9 @@ public: void loadEffectConfig(String const& name, Json const& effectConfig, StringMap const& shaders) override; void setEffectParameter(String const& parameterName, RenderEffectParameter const& parameter) override; + void setEffectScriptableParameter(String const& effectName, String const& parameterName, RenderEffectParameter const& parameter) override; + Maybe getEffectScriptableParameter(String const& effectName, String const& parameterName) override; + Maybe getEffectScriptableParameterType(String const& effectName, String const& parameterName) override; void setEffectTexture(String const& textureName, ImageView const& image) override; void setScissorRect(Maybe const& scissorRect) override; @@ -191,6 +194,7 @@ private: GLuint program = 0; Json config; StringMap parameters; + StringMap scriptables; // scriptable parameters which can be changed when the effect is not loaded StringMap textures; StringMap attributes; From 5e072417414a0d9a51d7c0c574fd0cdfc1fa29c9 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:04:59 -0800 Subject: [PATCH 07/11] Update StarRenderer.hpp --- source/application/StarRenderer.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/application/StarRenderer.hpp b/source/application/StarRenderer.hpp index 2a156f7..2b106ff 100644 --- a/source/application/StarRenderer.hpp +++ b/source/application/StarRenderer.hpp @@ -120,7 +120,7 @@ public: virtual void set(List& primitives) = 0; }; -typedef Variant RenderEffectParameter; +typedef Variant RenderEffectParameter; class Renderer { public: @@ -141,6 +141,9 @@ public: // The effect config will specify named parameters and textures which can be // set here. virtual void setEffectParameter(String const& parameterName, RenderEffectParameter const& parameter) = 0; + virtual void setEffectScriptableParameter(String const& effectName, String const& parameterName, RenderEffectParameter const& parameter) = 0; + virtual Maybe getEffectScriptableParameter(String const& effectName, String const& parameterName) = 0; + virtual Maybe getEffectScriptableParameterType(String const& effectName, String const& parameterName) = 0; virtual void setEffectTexture(String const& textureName, ImageView const& image) = 0; virtual bool switchEffectConfig(String const& name) = 0; From 1a0bf768f071d26a04ac20c5f0eb43056b14cc8f Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:07:04 -0800 Subject: [PATCH 08/11] Update StarRenderer_opengl.cpp --- source/application/StarRenderer_opengl.cpp | 112 ++++++++++++++++++--- 1 file changed, 97 insertions(+), 15 deletions(-) diff --git a/source/application/StarRenderer_opengl.cpp b/source/application/StarRenderer_opengl.cpp index 9d0d717..ceb945d 100644 --- a/source/application/StarRenderer_opengl.cpp +++ b/source/application/StarRenderer_opengl.cpp @@ -308,21 +308,39 @@ void OpenGlRenderer::loadEffectConfig(String const& name, Json const& effectConf throw RendererException::format("Unrecognized effect parameter type '{}'", type); } - effect.parameters[p.first] = effectParameter; - - if (Json def = p.second.get("default", {})) { - if (type == "bool") { - setEffectParameter(p.first, def.toBool()); - } else if (type == "int") { - setEffectParameter(p.first, (int)def.toInt()); - } else if (type == "float") { - setEffectParameter(p.first, def.toFloat()); - } else if (type == "vec2") { - setEffectParameter(p.first, jsonToVec2F(def)); - } else if (type == "vec3") { - setEffectParameter(p.first, jsonToVec3F(def)); - } else if (type == "vec4") { - setEffectParameter(p.first, jsonToVec4F(def)); + if (p.second.getBool("scriptable",false)) { + if (Json def = p.second.get("default", {})) { + if (type == "bool") { + effectParameter.parameterValue = (RenderEffectParameter)def.toBool(); + } else if (type == "int") { + effectParameter.parameterValue = (RenderEffectParameter)(int)def.toInt(); + } else if (type == "float") { + effectParameter.parameterValue = (RenderEffectParameter)def.toFloat(); + } else if (type == "vec2") { + effectParameter.parameterValue = (RenderEffectParameter)jsonToVec2F(def); + } else if (type == "vec3") { + effectParameter.parameterValue = (RenderEffectParameter)jsonToVec3F(def); + } else if (type == "vec4") { + effectParameter.parameterValue = (RenderEffectParameter)jsonToVec4F(def); + } + } + effect.scriptables[p.first] = effectParameter; + } else { + effect.parameters[p.first] = effectParameter; + if (Json def = p.second.get("default", {})) { + if (type == "bool") { + setEffectParameter(p.first, def.toBool()); + } else if (type == "int") { + setEffectParameter(p.first, (int)def.toInt()); + } else if (type == "float") { + setEffectParameter(p.first, def.toFloat()); + } else if (type == "vec2") { + setEffectParameter(p.first, jsonToVec2F(def)); + } else if (type == "vec3") { + setEffectParameter(p.first, jsonToVec3F(def)); + } else if (type == "vec4") { + setEffectParameter(p.first, jsonToVec4F(def)); + } } } } @@ -384,6 +402,50 @@ void OpenGlRenderer::setEffectParameter(String const& parameterName, RenderEffec ptr->parameterValue = value; } +void OpenGlRenderer::setEffectScriptableParameter(String const& effectName, String const& parameterName, RenderEffectParameter const& value) { + auto find = m_effects.find(effectName); + if (find == m_effects.end()) + return; + + Effect& effect = find->second; + + auto ptr = effect.scriptables.ptr(parameterName); + if (!ptr || (ptr->parameterValue && *ptr->parameterValue == value)) + return; + + if (ptr->parameterType != value.typeIndex()) + throw RendererException::format("OpenGlRenderer::setEffectScriptableParameter '{}' parameter type mismatch", parameterName); + + ptr->parameterValue = value; +} + +Maybe OpenGlRenderer::getEffectScriptableParameter(String const& effectName, String const& parameterName) { + auto find = m_effects.find(effectName); + if (find == m_effects.end()) + return {}; + + Effect& effect = find->second; + + auto ptr = effect.scriptables.ptr(parameterName); + if (!ptr) + return {}; + + return ptr->parameterValue; +} +Maybe OpenGlRenderer::getEffectScriptableParameterType(String const& effectName, String const& parameterName) { + auto find = m_effects.find(effectName); + if (find == m_effects.end()) + return {}; + + Effect& effect = find->second; + + auto ptr = effect.scriptables.ptr(parameterName); + if (!ptr) + return {}; + + return ptr->parameterType; +} + void OpenGlRenderer::setEffectTexture(String const& textureName, ImageView const& image) { auto ptr = m_currentEffect->textures.ptr(textureName); if (!ptr) @@ -1063,6 +1125,26 @@ void OpenGlRenderer::setupGlUniforms(Effect& effect, Vec2U screenSize) { } glUniform2f(m_screenSizeUniform, screenSize[0], screenSize[1]); + + for (auto& param : effect.scriptables) { + auto ptr = ¶m.second; + auto mvalue = ptr->parameterValue; + if (mvalue) { + RenderEffectParameter value = mvalue.value(); + if (auto v = value.ptr()) + glUniform1i(ptr->parameterUniform, *v); + else if (auto v = value.ptr()) + glUniform1i(ptr->parameterUniform, *v); + else if (auto v = value.ptr()) + glUniform1f(ptr->parameterUniform, *v); + else if (auto v = value.ptr()) + glUniform2f(ptr->parameterUniform, (*v)[0], (*v)[1]); + else if (auto v = value.ptr()) + glUniform3f(ptr->parameterUniform, (*v)[0], (*v)[1], (*v)[2]); + else if (auto v = value.ptr()) + glUniform4f(ptr->parameterUniform, (*v)[0], (*v)[1], (*v)[2], (*v)[3]); + } + } } RefPtr OpenGlRenderer::getGlFrameBuffer(String const& id) { From f7dc97965dd245a1d9272bdb48d1f16dc0b82233 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:07:34 -0800 Subject: [PATCH 09/11] Update StarRenderingLuaBindings.cpp --- source/client/StarRenderingLuaBindings.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/client/StarRenderingLuaBindings.cpp b/source/client/StarRenderingLuaBindings.cpp index 4c9e7a2..39dc1a1 100644 --- a/source/client/StarRenderingLuaBindings.cpp +++ b/source/client/StarRenderingLuaBindings.cpp @@ -1,6 +1,8 @@ #include "StarRenderingLuaBindings.hpp" +#include "StarJsonExtra.hpp" #include "StarLuaConverters.hpp" #include "StarClientApplication.hpp" +#include "StarRenderer.hpp" namespace Star { @@ -11,8 +13,30 @@ LuaCallbacks LuaBindings::makeRenderingCallbacks(ClientApplication* app) { callbacks.registerCallbackWithSignature>("setPostProcessGroupEnabled", bind(mem_fn(&ClientApplication::setPostProcessGroupEnabled), app, _1, _2, _3)); callbacks.registerCallbackWithSignature("postProcessGroupEnabled", bind(mem_fn(&ClientApplication::postProcessGroupEnabled), app, _1)); + // not entirely necessary (root.assetJson can achieve the same purpose) but may as well callbacks.registerCallbackWithSignature("postProcessGroups", bind(mem_fn(&ClientApplication::postProcessGroups), app)); + + // typedef Variant RenderEffectParameter; + // feel free to change this if there's a better way to do this + // specifically checks if the effect parameter is an int since Lua prefers converting the values to floats + callbacks.registerCallback("setEffectParameter", [app](String const& effectName, String const& effectParameter, RenderEffectParameter const& value) { + auto renderer = app->renderer(); + auto mtype = renderer->getEffectScriptableParameterType(effectName, effectParameter); + if (mtype) { + auto type = mtype.value(); + if (type == 1 && value.is()) { + renderer->setEffectScriptableParameter(effectName, effectParameter, (int)value.get()); + } else { + renderer->setEffectScriptableParameter(effectName, effectParameter, value); + } + } + }); + + callbacks.registerCallback("getEffectParameter", [app](String const& effectName, String const& effectParameter) { + auto renderer = app->renderer(); + return renderer->getEffectScriptableParameter(effectName, effectParameter); + }); return callbacks; } From 922427e25f0e6edf00909f8c6ae1dfc6770c7308 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:08:17 -0800 Subject: [PATCH 10/11] Update StarScrollArea.cpp --- source/windowing/StarScrollArea.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/windowing/StarScrollArea.cpp b/source/windowing/StarScrollArea.cpp index f4cc140..775462a 100644 --- a/source/windowing/StarScrollArea.cpp +++ b/source/windowing/StarScrollArea.cpp @@ -384,7 +384,8 @@ bool ScrollArea::sendEvent(InputEvent const& event) { return true; } -void ScrollArea::update(float) { +void ScrollArea::update(float dt) { + Widget::update(dt); if (!m_visible) return; From ec6c8f0c3c72cd7a9c9ea97721f12225cff42406 Mon Sep 17 00:00:00 2001 From: Bottinator22 <59987380+Bottinator22@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:09:29 -0800 Subject: [PATCH 11/11] Update StarLuaConverters.hpp --- source/core/StarLuaConverters.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/core/StarLuaConverters.hpp b/source/core/StarLuaConverters.hpp index d9dfc67..c79cbdc 100644 --- a/source/core/StarLuaConverters.hpp +++ b/source/core/StarLuaConverters.hpp @@ -168,11 +168,11 @@ struct LuaConverter> { template struct LuaConverter> { static LuaValue from(LuaEngine& engine, Variant const& variant) { - return variant.call([&engine](auto const& a) { return luaFrom(engine, a); }); + return variant.call([&engine](auto const& a) { return engine.luaFrom(a); }); } static LuaValue from(LuaEngine& engine, Variant&& variant) { - return variant.call([&engine](auto& a) { return luaFrom(engine, std::move(a)); }); + return variant.call([&engine](auto& a) { return engine.luaFrom(std::move(a)); }); } static Maybe> to(LuaEngine& engine, LuaValue const& v) { @@ -217,7 +217,7 @@ struct LuaConverter> { static LuaValue from(LuaEngine& engine, MVariant const& variant) { LuaValue value; variant.call([&value, &engine](auto const& a) { - value = luaFrom(engine, a); + value = engine.luaFrom(a); }); return value; } @@ -225,7 +225,7 @@ struct LuaConverter> { static LuaValue from(LuaEngine& engine, MVariant&& variant) { LuaValue value; variant.call([&value, &engine](auto& a) { - value = luaFrom(engine, std::move(a)); + value = engine.luaFrom(std::move(a)); }); return value; }