OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Shader composition with multiple function injection


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Sat May 12, 2018 9:59 pm    Post subject:
Shader composition with multiple function injection
Reply with quote

Hi,

I had a look at the shader composition example. The main shader looks like this:
Code:

#pragma import_defines ( LIGHTING, TEXTURE_2D, VERTEX_FUNC(v) )

#ifdef LIGHTING
// forward declare lighting computation, provided by lighting.vert shader
void directionalLight( int lightNum, vec3 normal, inout vec4 color );
#endif

#ifdef TEXTURE_2D
varying vec2 texcoord;
#endif

#ifdef VERTEX_FUNC
uniform float osg_SimulationTime;
#endif

varying vec4 basecolor;

void main(void)
{
    basecolor = gl_Color;

#ifdef LIGHTING
    directionalLight( 0, gl_Normal.xyz, basecolor);
#endif

#ifdef TEXTURE_2D
    // if we want texturing we need to pass on texture coords
    texcoord = gl_MultiTexCoord0.xy;
#endif

#ifdef VERTEX_FUNC
    gl_Position   = gl_ModelViewProjectionMatrix * VERTEX_FUNC(gl_Vertex);
#else
    gl_Position   = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif

}


In the example code one directional light computation can be injected. What is the best solution if I like to inject 0 to N directional lights where N is runtime dependent?

I could do something like:
Code:

#ifdef LIGHTING0
    directionalLight( 0, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING1
    directionalLight( 1, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING2
    directionalLight( 2, gl_Normal.xyz, basecolor);
#endif
...


but this is not very elegant. Though I do not see any other possibility. Am I missing a better solution?

Thank you!

Cheers,
Hartwig
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Sun May 13, 2018 11:00 am    Post subject:
Shader composition with multiple function injection
Reply with quote

Hi Hartwig,



On 12 May 2018 at 22:59, Hartwig Wiesmann <> wrote:
Quote:
In the example code one directional light computation can be injected. What is the best solution if I like to inject 0 to N directional lights where N is runtime dependent?

I could do something like:

Code:

#ifdef LIGHTING0
directionalLight( 0, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING1
directionalLight( 1, gl_Normal.xyz, basecolor);
#endif
#ifdef LIGHTING2
directionalLight( 2, gl_Normal.xyz, basecolor);
#endif
...

but this is not very elegant. Though I do not see any other possibility. Am I missing a better solution?

You could use the above approach, this kinda what the fixed function
pipeline does with needing to enable/disable GL_LIGHT0, GL_LIGHT1,
GL_LIGHT2 etc.

Another approach is pass in the number of active lights and have a for
loop iterator through the calls to directionalLight(i, gl_Normals,
basecolor); The number of lights could be a uniform or supplied by
#pragma(tic) shader composition.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts CompositeViewer with multiple view, a... Angel General 3 Tue Aug 28, 2018 1:15 pm View latest post
No new posts EXTERNAL: Re: LookAt() function param... Rowley, Marlin R General 0 Mon Aug 13, 2018 2:59 pm View latest post
No new posts LookAt() function parameter meanings.. Rowley, Marlin R General 2 Mon Aug 13, 2018 2:08 pm View latest post
No new posts Problem with output - OSG/Shader romulogcerqueira General 3 Sat Aug 04, 2018 6:36 pm View latest post
No new posts OSG vec3array size() function working... ak477 General 0 Fri Jul 06, 2018 5:57 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP