Jump to content

  • Log In with Google      Sign In   
  • Create Account


Alundra

Member Since 19 Jul 2011
Online Last Active Today, 04:52 PM

Topics I've Started

Fixed-Time step only for physics ?

Yesterday, 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 ?

 


Signed floating point texture

29 August 2014 - 03:39 PM

Hi all,

I have a heightmap data for a terrain I need to create a texture of it but if I send the floating point data I don't have the sign, all values are positive.

What is the good way to handle the creation of floating point texture in Direct3D11 ?

If texture 16 bits floating point is used, what is the good way to convert to unsigned short ?

Thanks for the help

 

EDIT:

The problem of float texture was because I used a linear sampling state and not a point sampling state.

Still the question about float to unsigned short, 0.5f * (value / 32767.0f) + 0.5f sounds the best option ?


Distance Field everywhere on sprite and text ?

23 August 2014 - 05:00 PM

Hi all,

The good way to have proper render of sprite and texture on all size and can have outline color is to use distance field.

Is it good to use distance field for all sprite and text or one boolean is better to set to use or not on the batch render ?

Maybe something like the :

BeginSprite(ITexture* Texture, ITexture* DistanceField);
RenderSprite( ... );
EndSprite();

If DistanceField is NULL, use the classical sprite pixel shader, if not NULL, use distance field pixel shader.

Does it sounds the best way to handle that ?

Thanks


PARTNERS