Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 09:19:14 am
Xith3D CommunityGeneral CategoryGeneral Discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)multiple shader support request
Pages: [1]
Print
Author Topic: multiple shader support request  (Read 1169 times)
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« on: 14. November 2008, 02:36:28 am »

Marvin

   I have hacked your shader <-> Shape3D approach to allow me to override the default bump mapping factory because I have several different shaders in a single scene.  I was hoping sometme we could generalize this for everyone.  I wasn't sure how you would approach this.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 14. November 2008, 02:47:34 am »

For this to work we need a shader based render pipeline. This should anyway be done soon. We would need some shaders to do all the things, that are currently supported by xith and done by the fixed function pipeline. All these shaders need to be combinable and need certain known uniforms and a well defined interface to integrate it with the whole system.

I am still not a shader pro. So could you possibly help me and tell me, what you changed?

Marvin
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #2 on: 14. November 2008, 02:55:08 am »

all i did was add this method to Shape3D passing in a different bump factory


Code:
public final void setBumpMappingEnabled( boolean enabled, String normalMapTex,BumpMappingFactory bumpFactory  )
    {
    alternateBumpFactory=bumpFactory;
   
        if ( bumpFactory != null )
        {
            setBumpMappingEnabled( enabled, BumpMappingFactory.loadNormalMap( normalMapTex ) );
        }
        else
        {
            System.err.println( "ERROR: Cannot apply BumpMapping, while no BumpMappingFactory is registered at the EffectFactory!" );
        }
    }


overriding the default factory if alternateBumpFactory is set


Code:
public final void setBumpMappingEnabled( boolean enabled, Texture normalMapTex )
    {
        this.bumpMappingEnabled = enabled;
       
        if ( enabled && ( ( getGeometry() == null ) || ( getAppearance() == null ) ) )
        {
            System.err.println( "Warning: BumpMapping will fail, if this Shape doesn't have a Geometry AND an Appearance." );
        }
        else if ( enabled && ( getGeometry() != null ) && ( getAppearance() != null ) )
        {
            BumpMappingFactory bumpFactory = EffectFactory.getInstance().getBumpMappingFactory();
            if(alternateBumpFactory!=null){
            bumpFactory=alternateBumpFactory;
            }
Logged
maguila007
Enjoying the stay
*
Offline Offline

Posts: 43



View Profile Email
« Reply #3 on: 14. November 2008, 12:43:19 pm »

Quote
We would need some shaders to do all the things, that are currently supported by xith and done by the fixed function pipeline

Do you wante to recreate all the fixed pipeline with a shader-base pipeline?

Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 14. November 2008, 02:31:06 pm »

@hawkwind:
I really don't understand, why you did this. All effect factories are replaceable. You can simply do the following in your game's initialization code to replace the default BumpMappingFactory and it will be automatically selected by the setBumpMappingEnabled() method of Shape3D:
Code:
EffectFactory.getInstance().registerBumpMappingFactory( myCustomBumpMappingFactory );

I don't see the need to modify the code like this.

Do you wante to recreate all the fixed pipeline with a shader-base pipeline?

OK. I think, I rushed the yesterday's post a little bit too much. I will try to explain it more in detail now.

Let's say, you have a Shape3D with some non-default settings like two textures, a special blending function, transparency settings, etc. These settings are passed to OpenGL the regular way. Now you want a certain custom effect on the shape, that can only be done through shaders. Then you have the problem, that you need to rebuild all the standard effects in a shader, since from the moment a shader program is used, the fixed function pipeline is completely ignored. You shader program would have to care for the correct handling of multitexturing for at least your two textures, your blending function, your transparency settings, etc. These shaders are not very complicated each for its own. But it would be pretty lame, if anyone would have to rewrite these shaders and customize them to fit in their own system.

What we need is a set of shaders, that do vertex-transformation, multi-texturnig, blending, etc. These shaders would have to be build in layers and push all the necessary (uniform) variables down to the next layer-shader, so that they all build a complete shader program to correctly render your shape with al the well known effects.

These layers would have to be accessible through the API to configure each layer through uniforms, to disable certain layers or replace them with custom shader code AND to put custom effect shaders between these layers like a bump mapping shader without losing the other layers' functionality and without having to rewrite any effect, that is currently available by default through fixed-function.

@Mathias: Did I forget anything to describe or to mention? Would be nice, if you could put your three cents into this discussion.

Marvin
Logged
maguila007
Enjoying the stay
*
Offline Offline

Posts: 43



View Profile Email
« Reply #5 on: 14. November 2008, 02:41:21 pm »

Can you set more than one vertex and pixel shader at the time for a Shape3D?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 14. November 2008, 03:03:08 pm »

Can you set more than one vertex and pixel shader at the time for a Shape3D?

You can only set one single shader program. But each shader program can be compiled of any number of vertex- and fragment-shaders.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic