Jump to content

Control lua shader by c++


Roberto14
 Share

Recommended Posts

Hi all, as title say, i can't figure out how can i take control of some uniforms, inside a file.shader,

but loaded by a .lua file.

 

An example is :

 

in file PostProcess/Bloom/Bloom.shader, ( loaded by PostProcess/bloom.lua )

 

How can i control uniform "cutoff" by c++ side?

 

When i load it

 

int index = pCamera->AddPostEffect( "Shaders/PostProcess/bloom.lua" );

 

i try

 

Leadwerks::Shader *pShader = (Leadwerks::Shader*)pCamera->posteffects[ index ];

 

and pShader is not NULL, but program crash if i use

 

pShader->SetFloat( "cutoff", fMycutoff);

I'm not english, so please sorry for my grammatical errors :)

 

I'm using Leadwerks and can programm in C++ and LUA

Link to comment
Share on other sites

Try loading the shader in question via C++ and then adjust its uniforms. It should affect all the bloom shaders loaded in the scene.

 

http://www.leadwerks.com/werkspace/topic/14230-global-uniform/#entry97586

 

Well, i already doing that, i'm not?

I say, i'm already using c++, lo "load" it.

 

I load bloom.lua file directly, because is really hard to create a cpp file equivalent.

I'm not english, so please sorry for my grammatical errors :)

 

I'm using Leadwerks and can programm in C++ and LUA

Link to comment
Share on other sites

Well, i already doing that, i'm not?

I say, i'm already using c++, lo "load" it.

 

I load bloom.lua file directly, because is really hard to create a cpp file equivalent.

 

Well you are loading the lua script via c++ then lua is loading the shader. I am suggesting you load the script as you showed above but also try loading the shader in c++ so you have access to the shader in question.

 

So instead of doing:

int index = pCamera->AddPostEffect( "Shaders/PostProcess/bloom.lua" );
Leadwerks::Shader *pShader = (Leadwerks::Shader*)pCamera->posteffects[ index ];
pShader->SetFloat( "cutoff", fMycutoff); 

try doing (psuedo-code):

int index = pCamera->AddPostEffect( "Shaders/PostProcess/bloom.lua" );
Leadwerks::Shader *pShader = Shader::Load("shaderpath.shader");
pShader->SetFloat( "cutoff", fMycutoff); 

 

--Note that i'm saying "try" since I do not have a way to attempt it - but it has worked for the previous attempt as shown in the link above.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well you are loading the lua script via c++ then lua is loading the shader. I am suggesting you load the script as you showed above but also try loading the shader in c++ so you have access to the shader in question.

 

So instead of doing:

int index = pCamera->AddPostEffect( "Shaders/PostProcess/bloom.lua" );
Leadwerks::Shader *pShader = (Leadwerks::Shader*)pCamera->posteffects[ index ];
pShader->SetFloat( "cutoff", fMycutoff); 

try doing (psuedo-code):

int index = pCamera->AddPostEffect( "Shaders/PostProcess/bloom.lua" );
Leadwerks::Shader *pShader = Shader::Load("shaderpath.shader");
pShader->SetFloat( "cutoff", fMycutoff); 

 

--Note that i'm saying "try" since I do not have a way to attempt it - but it has worked for the previous attempt as shown in the link above.

 

Seems to work, i need more test but i think u solved my problem, really thank you :)

I'm not english, so please sorry for my grammatical errors :)

 

I'm using Leadwerks and can programm in C++ and LUA

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...