Coder Social home page Coder Social logo

imageeffects's People

Contributors

ychding11 avatar

Watchers

 avatar

imageeffects's Issues

code need to revise to make it cleaner

	if( FAILED(D3DCompileFromFile(L"./data/fullQuad.fx", NULL, NULL, "PS", "ps_4_0", dwShaderFlags, 0, &pPSBlob, &pErrorBlob) ) )
	{
		if( pErrorBlob )
		{
			OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
			pErrorBlob->Release();
		}
		return false;
	}

The code above is not clean.

Canvas Example summary

  • draw circle by pixel shader in hlsl.
float circle(in float2 _st, in float _radius)
{
    float2 l = _st-float2(0.5,0.5);
    //return 1.f - smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01), dot(l,l)*4.0);
	return 1.f - step(_radius*_radius, dot(l,l));
}

//--------------------------------------------------------------------------------------
// Pixel Shader: Draw circles 
//--------------------------------------------------------------------------------------
float4 PSCanvas( PS_INPUT input) : SV_Target
{
	float2 resolution = float2(cWidth,cHeight);
	float2 st = input.Pos.xy / resolution;
	float3 color = float3(0.f,0.f,0.f);
	st *= 3.0f;
	st = frac(st); // fract() in glsl
	float v = circle(st, 0.5);
	color = float3(v, v, v); 
    return float4(color,1.0f);
}

image

  • It can be observed that sphere edge is very aliased. It is mainly caused by hlsl function step()
  • use smoothstep to create a smooth transition at sphere edge
// create a smooth transition in sphere edge
return 1.f - smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01), dot(l,l)*4.0);

image

Why have to transpose matrix before sending to HLSL Shader?

The definition cause float4x4 misaligned 8 bytes.

 struct  UniformParam 
    {
        virtual void Init(IGHIComputeCommandCotext *commandcontext, GHIBuffer **constBuffer) = 0;
        virtual void Update(const Camera &camera, IGHIComputeCommandCotext *commandcontext, GHIBuffer *constBuffer) = 0;
    };

    struct alignas(16) VSConstants:public UniformParam
    {
        Float4x4 WorldViewProjection;

        virtual void Init(IGHIComputeCommandCotext *commandcontext, GHIBuffer **constBuffer) override
        {
            *constBuffer = commandcontext->CreateConstBuffer(sizeof(VSConstants), nullptr);
        }

        virtual void Update(const Camera &camera, IGHIComputeCommandCotext *commandcontext, GHIBuffer *constBuffer) override
        {
            VSConstants vsParam;
            vsParam.WorldViewProjection = Float4x4::Transpose(camera.ViewProjectionMatrix());
            commandcontext->UpdateBuffer(constBuffer, &vsParam, sizeof(vsParam));
        }
    };

write a summary about current design.

  • take the following into consideration
    • basic framework
    • independent logic block
    • keep distance to window system to keep little dependency
    • simple and clear interface.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.