Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (dr_panther, Quad, AndrewAMD, 7th_zorro), 945 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Shader defines #422617
05/13/13 18:26
05/13/13 18:26
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline OP
Expert
Slin  Offline OP
Expert

Joined: May 2005
Posts: 2,713
Lübeck
It would be a big improvement, if there where lots of shader defines and shaders being compiled and used for the needed variations.
Things like fog, sun, number of lights effecting the object, alpha clipping, clipplanes, shadow receiver, animations and more.
This way one could write one "Übershader" assign it to all objects which are supposed to use it and it would just work for all different situations like a reflection view, indoor and outdoor levels and so on.
Sure one could do the same with branching, but with a noticeable performance hit.

It would also be great if there was a possibility not to clear the depth buffer before rendering some view, as for example in case of the PSSM shadows it should be a usefull performance gain to get rid of any overdraw by reusing the depth buffer.

Re: Shader defines [Re: Slin] #422627
05/13/13 21:07
05/13/13 21:07
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Originally Posted By: Slin
It would be a big improvement, if there where lots of shader defines and shaders being compiled and used for the needed variations


I receive great workflow results with dynamically compiled shaders, based on the .fx code and a preamble, generated during runtime, used together with the following function:

Code:
MATERIAL* avCompileMtl (MATERIAL* m, char* file, char* preamble, char* technique)
{
    if (m == NULL)
        return NULL;
    
    if (technique != NULL)
        m->technique = technique;

    if (file != NULL)
    {
        int s = 0;
        void* c = file_load(file, NULL, &s);

        if (s != 0)
        {
            STRING* strShader = NULL;
            
            if (preamble != NULL)
            {
                strShader = str_create(preamble);
                
                str_cat(strShader, "\n");
                str_cat(strShader, c);
                
                effect_load(m, strShader);
            }
            else
                effect_load(m, c);
                
            file_load(NULL, c, NULL);
            
            if (strShader != NULL)
                ptr_remove(strShader);
        }
    }
            
    return m;
}



In your game infrastructure, you just need to create a function that evaluates certain information (like variables and flags) and generate a series of defines (separated with "\n") to generate a preamble, that you can use to structure your HLSL shader-code with #ifdef and #ifndef. You can even use this to dynamically re-arrange samplers, by adding e.g. "#define SKIN_SPEC entSkin3" to your preamble and use SKIN_SPEC in the sampler definition: sampler smpSpecular = sampler_state { Texture = < SKIN_SPEC >; };, whereas the string above is e.g. generated by an int and sprintf.

Originally Posted By: Slin
It would also be great if there was a possibility not to clear the depth buffer before rendering some view


Do you mean the NOSKY flag? I used it to render particles into a SSAO-shaded scene and it works really good.

Last edited by HeelX; 05/13/13 21:08.

Moderated by  aztec, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1