LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

ShaderUniform for DX11 ? #6

Closed BobbyBao closed 5 years ago

BobbyBao commented 6 years ago

How to implement a extendible material system on dx11, use ConstBuffer?

LukasBanana commented 6 years ago

Hi, could you please describe your question in more detail?

How extensible should your material system be? This sounds like a question about the typical issue of so called "Uber-Shaders" where you have all material effects inside a single (and commonly large) shader.

Or is this a question specifically about LLGL?

BobbyBao commented 6 years ago

A Material class, like Urho3D engine and Unity Engine, material contains a vector of ShaderParaments, each shader parament set value by name,LLGL dx11 renderer should implement ShaderUniform interface or provide a reflection API

LukasBanana commented 6 years ago

The ShaderUniform interface is only for the older shader versions of GLSL to set individual uniforms, like this:

uniform int param0;
uniform float param1;

In modern shaders you typically use Uniform Buffers (OpenGL) or Constant Buffers (Direct3D), like this:

// GLSL
layout(std140) uniform Parameters {
    int param0;
    float param1;
};
// HLSL
cbuffer Parameters : register(b0) {
    int param0;
    float param1;
};

Take a look at the constantBuffer field in Tutorial02.

BobbyBao commented 6 years ago

I kown, but ConstantBuffer shoulder privider reflection API. In a extensible material system, when you add a new shader, you only need to change a material config, instead of change the ConstBuffer struct in cpp source code.

LukasBanana commented 6 years ago

The only shader reflection for constant buffers LLGL supports right now are the ShaderProgram::QueryConstantBuffers function and ConstantBufferViewDescriptor structure. But individual members of a constant buffer can not be queried. So you need to know your shader structures and map them 1:1 into C++.

Even if I add this functionality at some day, I would not use the ShaderUniform interface, but I would extend the ConstantBufferViewDescriptor structure to support it.

However, I currently don't know when I have time for this.

LukasBanana commented 5 years ago

This thread is quite old now, but might be related this new ticket.