Jump to content

Internal shader uniforms


Josh
 Share

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.

  • Upvote 7

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

  • Upvote 1

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...