• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tom KQT

Precompiled effect files and macros

8 posts in this topic

Hello,
I'll try to explain my problem and I will be grateful for any feedback.


To change some graphics settings that affect shaders (especially texture filtering mode and max anisotropy) I use macros passed to D3DXCreateEffectFromFile. The .fx files use that macros with preprocessor #if directives, so everything happens during effect compilation.

But, D3DXCreateEffectFromFile takes quite a long time to compile .fx files (it can be even around 0.2 seconds for a SINGLE effect file) so I thought I could use precompiled .fxo files (created for example with the tool fxc.exe) which would probably load much faster. But if I'm not mistaken, I wouldn't be able to set macros in the D3DXCreateEffectFromFile anymore, I would have to set them in the command line when running fxc.exe...

So the question is, what other solutions would you suggest to allow me to change for example texture filtering or max anisotropy - that means values directly written in the sampler definition in an effect file?
0

Share this post


Link to post
Share on other sites
Typically you compile the shader using fxc.exe using every possible combination of options that you might require at runtime, and end up with a large collection of compiled shaders.

N.B. ignoring D3DX "effects" for a moment, texture filtering modes and max anisotropy are sampler states, not shader code, so they can be set programmatically -- though yes, D3DX FX syntax does allow you to specify default values for those states in your shader code.
However, I'm not very familiar with D3DX FX structures ([i]I use regular D3D shaders[/i]), so I can't tell you how to override it.
1

Share this post


Link to post
Share on other sites
Yea, I was also thinking about putting samplers out of the effect file, assigning them to a specific register and just refering to that register in the shaders.

There are however some else values I'm currently setting via the macros, like shadow map size. But those can be just constants set from the C++ code.
0

Share this post


Link to post
Share on other sites
It's been a very long time, but I [i]think[/i] you can assign a sampler state a value from a global int declared in your .fx file. Then at runtime you can set the int value with ID3DXEffect::SetInt. Otherwise you could always just call SetSamplerState yourself.
1

Share this post


Link to post
Share on other sites
I'd personally just call SetSamplerState myself, and leave the default sampler states in the Effect file unset (i.e. just declare it as "sampler mySampler;").

What I have done before is to do what MJP suggests and assign a state from a shader constant. The Effect code looks something like this:[code]
int myMipFilter;

sampler s = sampler_state
{
mipfilter = <myMipFilter>;
};[/code]

Then in your C++ you do:[code]effect->SetInt ("myMipfilter", D3DTEXF_LINEAR);[/code]

(That's largely working from memory so please don't copy/paste this.)

A third way is to attach an ID3DXEffectStateManager to your Effect and set the states you want from there. See http://msdn.microsoft.com/en-us/library/windows/desktop/bb205795%28v=vs.85%29.aspx for more info on this. This is probably the approach I'd prefer as you can also add some state filtering to your Effect with it.
1

Share this post


Link to post
Share on other sites
Thank you guys. I'll decide which way to go, I think I prefer to move sampler settings away from the effect file and just use SetSamplerState, but I'll see how it will turn out when I'll be putting it into my code.

[quote name='mhagain' timestamp='1349461383' post='4987199']
A third way is to attach an ID3DXEffectStateManager to your Effect and set the states you want from there. See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205795%28v=vs.85%29.aspx"]http://msdn.microsof...5(v=vs.85).aspx[/url] for more info on this. This is probably the approach I'd prefer as you can also add some state filtering to your Effect with it.
[/quote]
I already am using ID3DXEffectStateManager to filter redundant changes. It's been quite a long time so I'll have to look at it again and see how it could be used.
0

Share this post


Link to post
Share on other sites
[quote name='Tom KQT' timestamp='1349466205' post='4987225']
Thank you guys. I'll decide which way to go, I think I prefer to move sampler settings away from the effect file and just use SetSamplerState, but I'll see how it will turn out when I'll be putting it into my code.
[/quote]

I should have added that if you do this it will go much easier on you if you specify explicit sampler registers in your HLSL code, like so:[code]sampler mySampler : register(s0)[/code]
2

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1349479725' post='4987281']
I should have added that if you do this it will go much easier on you if you specify explicit sampler registers in your HLSL code, like so:[code]sampler mySampler : register(s0)[/code]
[/quote]
Hm, the question is whether it is much easier (as you say) or rather the only way how to do it? How else would I know which number to use as the first parameter of SetSamplerState?

Btw, that's what I'm already doing with my shadow map texture, because I haven't found any way how to "unset" a texture using the effect framework and I was getting debug runtimes warnings about using a texture that has been previously assigned as a render target. When I have the shadow map texture in a fixed register, I can easily set it to NULL using SetTexture.
0

Share this post


Link to post
Share on other sites
[quote name='Tom KQT' timestamp='1349601010' post='4987632']
[quote name='mhagain' timestamp='1349479725' post='4987281']
I should have added that if you do this it will go much easier on you if you specify explicit sampler registers in your HLSL code, like so:[code]sampler mySampler : register(s0)[/code]
[/quote]
Hm, the question is whether it is much easier (as you say) or rather the only way how to do it? How else would I know which number to use as the first parameter of SetSamplerState?
[/quote]

An effect state manager would also let you do it, but otherwise - yeah - it is kinda necessary isn't it?
1

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  
Followers 0