Sign in to follow this  
JonnyHilly

Passing parameters from Game to Shaders

Recommended Posts

I have been dabbling writing some custom shaders in Gamebryo. and have got some parameters working, that artists can edit in Maya, such as pulse frequencies for glows... specularity, reflectivity etc..... This all works ok. But how to I make parameters that can be set in game code? that get sent to one or all shaders please. For example... How can I effect a shader's glow texture's brightness or alpha translucency via game code? Or how do I change a global fog value via game code, so it effects all shaders at the same time ? There seems to be one or two existing variables like this that can be passed to all shaders.... such as "Time" But I don't know how to set these up in game code, or make the paramaters accessible to the shaders as attributes. does anyone have any ideas on how to do this. Even better if you know how to do this within GameBryo any help appreciated... cheers

Share this post


Link to post
Share on other sites
Which shader-language are you coding in, and for what platform?

All of those parameters should be easy to set in any language, google for a simple tutorial on the subject. There's plenty. :)

Share this post


Link to post
Share on other sites
.FX is just what you're saving the file as, not the language.

I Haven't worked with Gamebryo but if it's DirectX HLSL (which used the .FX extension as the standard) then when you're setting up the Effect you can define an Effect Pool which allows you to share variables between shaders.

At least with DirectX to set variable in shaders from code, you simply call the effects SetValue function

Share this post


Link to post
Share on other sites
finally figured it out...
its quite easy once you know how..
just had a hard time finding a simple description or example...

//setup Custom Shader global Atribute

NiShaderFactory::RegisterGlobalShaderConstant("ShaderAttributeName",
NiShaderAttributeDesc::ATTRIB_TYPE_FLOAT, //see NiShaderAttributeDesc.h
sizeof(float), (const void*) &floatVariable);

That sets up the attribute, as a global, that code can change.

and can be updated with NiShaderFactory::UpdateGlobalShaderConstant


in the shader code, setup the variable in the usual way.

float variableName
<
string VarType = "Predefined";
string DefinedMapping = "ShaderAttributeName";
> = { 1.0f}; //comment here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this