管理 HLSL 效果 (Managing HLSL effects)


問題描述

管理 HLSL 效果 (Managing HLSL effects)

Let say, for this example, that I have World class. World has collection of Models :

class World
{
    public:
      map<string, Model*> Models;
};

Model would be abstract class for all entities in application, for example car, ball, mountain, or cube.

And the question is ‑ what's the best practice for managing effects for that models. Let say, that I've got 4 effect files : base1.fx, base2.fx, base3.fx, bas4.fx. Each of them has class interface, which might be bound to model ( IBaseEffect1, IBaseEffect2, IBaseEffect3, IBaseEffect4 ).

Now, should I consider each model independent, and do something like:

Cube1.Bind(IBaseEffect2);
Car.Bind(IBaseEffect3);

Where model would have ability to manage effect, so I would make:

World::Render()
{
    foreach model ‑> Render();
}

Which is actual solution for my engine.

Or better would be to manage effects independent, and do something like:

IBaseEffect1.SetAsActual();

foreach Model which should be considered for effect1 ‑> Render();

IBaseEffect2.SetAsActual();

foreach Model which should be considered for effect2 ‑> Render();

etc...

Maybe my whole point of view is wrong, and it should be made other way ?

‑‑‑‑‑

參考解法

方法 1:

I think you should use both of your methods. That is:

  1. Each model has got its own effect bound: model‑>Bind(effect);
  2. You manage the effects separately (for efficiency reasons):
    1. Sort models by the effects they're using
    2. For each effect:
      • Set up the effect
      • Render all models associated with the current effect

Models which have to be rendered in a fixed order (e.g. transparent objects) should be processed in a different way unless  all of them share the same effect.

(by Norbert Ozdobamiloszmaki)

參考文件

  1. Managing HLSL effects (CC BY‑SA 3.0/4.0)

#hlsl #directx-10 #C++ #directx






相關問題

如何將幾何著色器與輸出流一起使用? (How do you use Geometry Shader with Output Stream?)

поўнаэкранны квадрат у піксельным шэйдары мае экранныя каардынаты? (fullscreen quad in pixel shader has screen coordinates?)

硬編碼 HLSL 著色器 (Hardcoding HLSL Shader)

GLSL和HLSL之間的模型視圖區別? (Modelview Difference between GLSL and HLSL?)

未定義的 TEXCOORD 數量 (Undefined number of TEXCOORDs)

像素著色器總是返回白色 (Pixel shader always returning white)

GLSL / HLSL 著色器中的星球大戰全息效果 (Star Wars holographic effect in GLSL / HLSL shader)

在 GLSL 中混合多個紋理 (Blending multiple textures in GLSL)

警告 X4000:使用可能未初始化的變量 (warning X4000: use of potentially uninitialized variable)

著色器中的點積與直接向量分量總和性能 (Dot product vs Direct vector components sum performance in shaders)

Unity Compute Shader 中調用 numthreads 和 Dispatch 的區別 (Difference Between Calling numthreads and Dispatch in a Unity Compute Shader)

DirectX 11 曲面細分著色器不工作 (DirectX 11 Tesellation Shader Not Working)







留言討論