Jump to content

  • Log In with Google      Sign In   
  • Create Account


Alundra

Member Since 19 Jul 2011
Offline Last Active Today, 04:08 PM

Topics I've Started

OIT (Order Independent Transparency)

17 September 2014 - 09:35 AM

Hi all,

When you sort transparent objects back-to-front it's not correct because you sort one distance but one object is large and demand a dynamic array to use a sort algorithm.

The modern research give solution to that, actually two solutions is there Intel and Morgan+Louis solution.

Here link to both methods :

https://software.intel.com/en-us/blogs/2013/07/18/order-independent-transparency-approximation-with-pixel-synchronization

http://jcgt.org/published/0002/02/09/

Weighted Blended Order-Independent Transparency looks to give more perfs but is it good to use it or the intel solution still the best ?

Thanks for the help


Recast-Detour Crowd Filter

04 September 2014 - 09:57 AM

Hi all,

Recast-Detour has DetourCrowd who is used a lot in differents games or engine.

The limitation of DetourCrowd is you only have one filter by query who is a problem for RTS games (terrestrial vs aerial)

The only solution is to sort the actors and have multiple dtCrowd by type ?

Thanks for the help


Fixed-Time step only for physics ?

01 September 2014 - 10:07 PM

Hi all,

Fixed time step is used for physic update, is it better to do all using fixed time step ?

Is it better to do variable time step and have a fixed time step update function ?

Thanks for the help


STB_Image or FreeImage ?

31 August 2014 - 08:38 PM

Hi all,

I had problems with STB_Image in the past but using the latest version from GitHub problem are removed.

When I had theses problem I switched to FreeImage who is a stable image lib.

The good thing of STB_Image is the license and it's just one header file.

Is it good to use STB_Image or it's better to stay with FreeImage ?

Thanks


Template shader, Bad practice ?

31 August 2014 - 08:01 PM

Hi all,

It's possible to do that to factor the shader code, code from intel sample :

// Templated shader factory utilities
namespace ShaderFactoryUtil
{
    template <typename T> LPCSTR GetShaderProfileString();
    template <typename T> T* CreateShader(ID3D11Device* d3dDevice, const void* shaderBytecode, size_t bytecodeLength);

    // Vertex shader
    template <> inline LPCSTR GetShaderProfileString<ID3D11VertexShader>() { return "vs_5_0"; }
    template <> inline 
    ID3D11VertexShader* CreateShader<ID3D11VertexShader>(ID3D11Device* d3dDevice, const void* shaderBytecode, size_t bytecodeLength)
    {
        ID3D11VertexShader *shader = 0;
        HRESULT hr = d3dDevice->CreateVertexShader(shaderBytecode, bytecodeLength, 0, &shader);
        if (FAILED(hr)) {
            // This shouldn't produce errors given proper bytecode, so a simple assert is fine
            assert(false);
        }
        return shader;
    }

    // Pixel shader
    template <> inline LPCSTR GetShaderProfileString<ID3D11PixelShader>() { return "ps_5_0"; }
    template <> inline 
    ID3D11PixelShader* CreateShader<ID3D11PixelShader>(ID3D11Device* d3dDevice, const void* shaderBytecode, size_t bytecodeLength)
    {
        ID3D11PixelShader *shader = 0;
        HRESULT hr = d3dDevice->CreatePixelShader(shaderBytecode, bytecodeLength, 0, &shader);
        if (FAILED(hr)) {
            // This shouldn't produce errors given proper bytecode, so a simple assert is fine
            assert(false);
        }
        return shader;
    }

    // Compute shader
    template <> inline LPCSTR GetShaderProfileString<ID3D11ComputeShader>() { return "cs_5_0"; }
    template <> inline 
    ID3D11ComputeShader* CreateShader<ID3D11ComputeShader>(ID3D11Device* d3dDevice, const void* shaderBytecode, size_t bytecodeLength)
    {
        ID3D11ComputeShader *shader = 0;
        HRESULT hr = d3dDevice->CreateComputeShader(shaderBytecode, bytecodeLength, 0, &shader);
        if (FAILED(hr)) {
            // This shouldn't produce errors given proper bytecode, so a simple assert is fine
            assert(false);
        }
        return shader;
    }
}

// Templated (on shader type) shader wrapper to wrap basic functionality
// TODO: Support optional lazy compile
template <typename T>
class Shader
{
public:
    Shader(ID3D11Device* d3dDevice, LPCTSTR srcFile, LPCSTR functionName, CONST D3D10_SHADER_MACRO *defines = 0)
    {
        // TODO: Support profile selection from the application? Probably not necessary as we don't
        // support down-level hardware at the moment anyways.
        LPCSTR profile = ShaderFactoryUtil::GetShaderProfileString<T>();
        UINT shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
        ID3D10Blob *bytecode = 0;
        ID3D10Blob *errors = 0;
        HRESULT hr = D3DX11CompileFromFile(srcFile, defines, 0, functionName, profile, shaderFlags, 0, 0, &bytecode, &errors, 0);
        if (errors) {
            OutputDebugStringA(static_cast<const char *>(errors->GetBufferPointer()));
        }
        if (FAILED(hr)) {
            // TODO: Define exception type and improve this error string, but the ODS will do for now
            throw std::runtime_error("Error compiling shader");
        }
        mShader = ShaderFactoryUtil::CreateShader<T>(d3dDevice, bytecode->GetBufferPointer(), bytecode->GetBufferSize());
        bytecode->Release();
    }
    
    ~Shader() { mShader->Release(); }
    T* GetShader() { return mShader; }

private:
    // Not implemented
    Shader(const Shader&);
    Shader& operator=(const Shader&);

    T* mShader;
};

typedef Shader<ID3D11VertexShader> VertexShader;
typedef Shader<ID3D11PixelShader> PixelShader;
typedef Shader<ID3D11ComputeShader> ComputeShader;

Do you see that as a bad practice ?

 


PARTNERS