Skip to content

Conversation

@EM4Volts
Copy link
Contributor

@EM4Volts EM4Volts commented Jan 1, 2026

This adds a new Flag check for the glueflag in a material in after executing shaderexecute, adding it at the right spot in the graphics pipeline of the game.

the flag is 0x04089901

if called a new buffer is bound to the shader and stored in static memory.
this is stored associated with a material GUID passed via a SQ command

struct Ns_Constant_Buffer { float data[320]; };

The buffer has 320 floats accessible, you can bind in a buffer in a pixel shader like so:

cbuffer NorthstarCustomBuffer : register(b4) { float4 NS_custom_float4_0 : packoffset(c0); float4 NS_custom_float4_1 : packoffset(c1); float4 NS_custom_float4_2 : packoffset(c2); float4 NS_custom_float4_3 : packoffset(c3); float4 NS_custom_float4_4 : packoffset(c4); float4 NS_custom_float4_5 : packoffset(c5); ... ... };

to access this buffer and write to it in script call NSSetCustomDXBuffer(string materialGUID, array floats)

ex.:
NSSetCustomDXBuffer( "0x8CFD6305B9061988", myCoolArray)

if the array is smaller then the buffer the floats are populated in order.
if its too big the vm will throw an error to avoid overflow

this is usefull to create script controlled shader settings, or do logic for things like ammo counters with custom shaders in sqvm and pass for example an ammo count or other such things

Code review:

im pretty new to this, so be harsh thanks

Testing:

you can download my examplemod:
em4v.prtest.zip

and then go on any map, equip the Devotion and see that its mostly black. in console run:

script_client thread changeColorBasedOnLocation(GetLocalClientPlayer())

this runs changeColorBasedOnLocation() a function implemented in "shadertest.nut" in the mod, which changes certain values every frame in the shader, such as certain color settings to update them based on your world position. this results in changing color based on this.
Video of this:

output3.mp4

to get the guid of a material you can either call -pakguid on the rpak string via rePak or use rsx

@github-actions github-actions bot added needs testing Changes from the PR still need to be tested needs code review Changes from PR still need to be reviewed in code labels Jan 1, 2026
update dx context and device to static
error out if guid is malformed
fix random if true
Copy link
Contributor

@ASpoonPlaysGames ASpoonPlaysGames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall to me

Copy link
Member

@catornot catornot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just quickly looked at this

g_pSquirrel[ScriptContext::CLIENT]->AddFuncRegistration(
"void",
"NSSetCustomDXBuffer",
"string rPakMaterialGUID array NSCustomBufferPerMaterialData",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why untyped array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I was probably unsure if u can make it a typed array with this, but it still works. No matter what type u feed it if the data is too much it should still error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I was probably unsure if u can make it a typed array with this, but it still works. No matter what type u feed it if the data is too much it should still error

return true;
}

template <ScriptContext context> SQRESULT NSSetCustomDXBuffer(HSQUIRRELVM sqvm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this use the the ADD_SQFUNC macro?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs access the the sqvm to get data from the array, don't have a reference the sqvm from the macro version

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs access the the sqvm to get data from the array, don't have a reference the sqvm from the macro version

the macro version gives you a sqvm reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs code review Changes from PR still need to be reviewed in code needs testing Changes from the PR still need to be tested

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants