Jump to content
Josh

Internal shader uniforms

Recommended Posts

Here are the values Leadwerks will automatically send to shaders when they are bound:

   	 if (uniform_currenttime) uniform_currenttime->SetFloat(Time::GetCurrent());
       if (uniform_buffersize) uniform_buffersize->SetVec2(Vec2(buffer->GetWidth(),buffer->GetHeight()));
       if (uniform_drawmatrix) uniform_drawmatrix->SetMat4(graphicsdriver->drawmatrix);
       if (uniform_drawcolor) uniform_drawcolor->SetVec4(Leadwerks::GraphicsDriver::GetCurrent()->drawcolor);
       if (uniform_projectionmatrix) uniform_projectionmatrix->SetMat4(graphicsdriver->projectionmatrix);
       if (uniform_isbackbuffer) uniform_isbackbuffer->SetInt(buffer->isbackbuffer);

  	 if (world != NULL)
       {
           if (uniform_ambientlight) uniform_ambientlight->SetVec4(world->ambientlight);
           if (uniform_tessstrength) uniform_tessstrength->SetFloat(world->tessellationstrength);
       }

  	 if (ActiveCamera!=NULL)
       {
           if (uniform_projectioncameramatrix) uniform_projectioncameramatrix->SetMat4(ActiveCamera->projectioncameramatrix);
           if (uniform_cameraposition) uniform_cameraposition->SetVec3(ActiveCamera->GetPosition(true));
           if (uniform_cameradrawmode) uniform_cameradrawmode->SetInt(ActiveCamera->drawmode);
           if (uniform_cameraprojectionmode) uniform_cameraprojectionmode->SetInt(ActiveCamera->projectionmode);
           if (uniform_lighting_ambient) uniform_lighting_ambient->SetVec4(ActiveCamera->world->ambientlight);
           if (uniform_camerarange) uniform_camerarange->SetVec2(ActiveCamera->range);
           if (uniform_camerazoom) uniform_camerazoom->SetFloat(ActiveCamera->zoom);
           if (uniform_cameramatrix) uniform_cameramatrix->SetMat4(ActiveCamera->mat);
           if (uniform_prevprojectioncameramatrix) uniform_prevprojectioncameramatrix->SetMat4(ActiveCamera->prevprojectioncameramatrix);
           if (uniform_camerainversematrix) uniform_camerainversematrix->SetMat4(ActiveCamera->mat.Inverse());
           if (uniform_cameranormalmatrix) uniform_cameranormalmatrix->SetMat3(Mat3(ActiveCamera->mat));
           if (uniform_camerainversenormalmatrix) uniform_camerainversenormalmatrix->SetMat3(Mat3(ActiveCamera->mat.Inverse()));
       }
       else
       {
           if (uniform_projectioncameramatrix) uniform_projectioncameramatrix->SetMat4(graphicsdriver->projectioncameramatrix);
       }

Additionally, texture0-15 are automatically initialized to 0,1,2, etc.

Share this post


Link to post

Great, thanks!

 

And while you're at it rolleyes.gif :

Could you specify the channel layout of the fragment shader output (frag0, frag1, ...)? I mean, frag0 is the diffuse and frag1 is the normal, but if I read your shaders correctly you are e.g. assigning the alpha from the diffuse to the alpha of the normal vector?

Share this post


Link to post

Sure:

 

Channel 0

  • r = diffuse.r
  • g = diffuse.g
  • b = diffuse.b
  • a = diffuse.a

Channel 1

  • r = normal.x
  • g = normal.y
  • b = normal.z
  • a = specularity

Channel 2

  • r = emissive.r
  • g = emissive.g
  • b = emissive.b
  • a = material flags
    • 1: Lighting enabled
    • 2: Decals enabled (reserved)

Share this post


Link to post

If you look at the animated model shader, that has everything.

 

And there are also two uniform buffers in use, one for bone matrices for vertex skinning, and the other for instance matrices. The right-hand column of the instance matrices stores the entity color, to make it more compact.

Share this post


Link to post

materialcolorspecular and materialcolordiffuse are self-explanatory. The others you listed are all in the code above.

Share this post


Link to post

materialcolorspecular and materialcolordiffuse are self-explanatory. The others you listed are all in the code above.

 

Why can't you just add a list of ALL of them with their descriptions to a shader reference self-explanatory or not? biggrin.png You want some great looking shots filling the gallery to promote the engine right? Help the shader developers!

 

I mean most of the API is self-explanatory but they are there in the documents with unnecessary amounts of code examples for both C++ and Lua and a butt load of description. This is lazy, do the Right-Thing-To-Do as Carmack's fond of saying :)

Share this post


Link to post

True. In reality, if I simply added a mechanism for plug and play post-processing effects it would fill up overnight.

Share this post


Link to post

yay. got the first thing displaying shader wise. Not quite there yet but at least i see something. was just using the wrong variable names :)

Still at the beginning to learn though

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...