Skip to main content
GameDev.net gamedev.net
🔒 Locked

[HLSL] Function style Makro without parmeters

Started by mind in a box Nov 6, 2010 at 12:18 PM 4 replies 1k views
Original Post
mind in a box
mind in a box
Hi!

I wrapped up my lighting functions into useful functions to give my artist easier access to the lighting in the shaders. I wrote some functions which do the needed standard computations, taking some input parameters which are the same every time.

So, they go like this:
float3 GetDiffuseLighting_f(Texture2D LightBuffer, float2 ScreenUV, SamplerState Sampler){   //...}#define GetDiffuseLighting() GetDiffuseLighting_f(g_LightBuffer, GetScreenUV(), samScene);


So that I can use it like this in my shaders:

return GetDiffuseLighting();


The only problem is, that the HLSL compiler complains about those () I want. ( In the #define Bla() )
I want them, just because this here looks rather ugly (As Makros do anyway):

return GetDiffuseLighting;


Someone knows a trick how to do this?
smasherprog
smasherprog
You want to have the option to compile different versions, but use the same format?

///HLSL CODE

float3 GetDiffuseLighting_f(Texture2D LightBuffer, float2 ScreenUV, SamplerState Sampler){#ifdef UseDiff1   //code for diff version 1#else    //code for the else version#endif}


Is that what you were looking for?
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
mind in a box
mind in a box
No, I want them to be a shortcut. I would like to have all this shader stuff as easy as possible for my artist. He can code, but I don't want to make things harder for him.


As for my function "GetDiffuseLighting_f", which lays in some header-file for useful functions (Toolbax.fxh), the input parameters will always be the same. So I thought, I could save him from typing those extra parameters by using a makro.

So that this code:
float3 wtPixelShader(PixelShader Input){    return GetDiffuseLighting_f(g_LightBuffer, GetScreenUV(), samScene);}


could get stripped down to that (Doesn't work, though):
float3 wtPixelShader(PixelShader Input){    return GetDiffuseLighting();}


The actual problem is more a styling issue. The compiler lets me have this:

#define GetDiffuseLighting GetDiffuseLighting_f(g_LightBuffer, GetScreenUV(), samScene)


But not this( Notice the "()" ):
#define GetDiffuseLighting() GetDiffuseLighting_f(g_LightBuffer, GetScreenUV(), samScene)


So the code would look like this to my artist:
float3 wtPixelShader(PixelShader Input){    return GetDiffuseLighting;}


And to me, having this looking like a function is much more pleasant like having it looking like a whateverweirdthingthatdoescoolstuff™.


All I want is to use some braces there [sad]
MJP
MJP
If the parameters are all global, you can just make it a regular function.
DieterVW
DieterVW
Yeah, since all code will be inlined anyway there won't be a difference between a real function and a macro.
mind in a box
mind in a box
Ah, right... I forgot that I can just include the toolbox-header after my decelerations in the main shader file. Thanks for putting me into the right direction! [smile]

I don't even have to use a Makro that way.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.