티스토리 뷰

Game/Graphics

Shader Uniform variable

newpolaris 2018. 2. 22. 14:56

가장 간단하게는 shader bind 후 호출하는 방식

복잡하게는 한도 끝도 없지만,

렌더링시에 메모리에 써버리는 방식의 경우 MiniEngine 에서 봤다

MiniEngine

DirectX 12 기반은 저걸 써야 하고, DirectX 11은 11.1에서 추가된 방식을 쓰면되던데

Vulkan도 비슷할듯하다

반면, Shader query를 기반으로 자료형 다 조사해서 uniform이나 cbuffer 구조를

만들어두고 변경시 update하는 방식이 있다.

Direct 11 기반은 ForwardPlus, 히에로그라프가 있는데 shader query는 컴퓨터에서 밖에 사용 못한다.

OpenGL은 Ray 가 비슷한 방식을 사용한다.

Ray

아래와 같이 할당하면,

effect->getParameter("quality")->uniform4f(quality);

리스너를 통해 전파된다

void
MaterialParam::uniform3fmatv(const std::vector<float3x3>& value) noexcept
{
    for (auto& it : _listeners)
        it->uniform3fmatv(value);
}

저런 리스너는, 실제 아래 과정을 통해 생성되는데

auto binding = std::make_unique<MaterialParamBinding>();
binding->setGraphicsUniformSet(activeUniformSet);
binding->setMaterialParam(param);

이는 material setup 과정의 일부이다.

material.setup();
...
descriptorSetLayoutDesc.setUniformComponents(_program->getActiveParams());
...
descriptorSet->setup(desc) {
    _activeUniformSets.push_back(uniformSet);
    _descriptorSetDesc = descriptorSetDesc;
}
...
_descriptorSet = _program->getDevice()->createDescriptorSet

실제 렌더링 과정에서는 needUpdate check를 통해 적용이 펜딩되는 듯

_graphicsContext->setDescriptorSet(pass->getDescriptorSet());
...
_needUpdateDescriptor = true
...
_descriptorSet->apply(*_program);
...
glProgramUniform2fv(program, location, 1, it->getFloat2().ptr());

'Game > Graphics' 카테고리의 다른 글

LTC Implementations  (0) 2018.03.05
LTCs Fittting - Nelder-Mead optimization algorithm  (0) 2018.02.26
Framebuffer  (0) 2018.02.20
Area light  (0) 2018.02.19
GLSL include handling  (0) 2018.02.15
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크