ychding11 / imageeffects Goto Github PK
View Code? Open in Web Editor NEWImage Effect based DX11 Compute Shader
Image Effect based DX11 Compute Shader
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.
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);
}
// create a smooth transition in sphere edge
return 1.f - smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01), dot(l,l)*4.0);
For example, instance data is a matrix. But there is NO direct DXGI data format for a matrix in HLSL.
option1: manually fetch instance data by "instance ID"?
option2: 4 float4 vectors make a matrix. Let hardware fetch the data. It needs a correct Vertex Layout object.
Which one is better ?
This is an example:
Because HLSL by default expects column-major packed matrix.
It can make the matrix data is correct when column-major pack a matrix to transpose a raw-major matrix before sending to shader.
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-variable-syntax
https://www.gamedev.net/forums/topic/662986-hlsl-mul-and-rowcolumn-major-matricies-in-directx/
This MSDN article is a good reference.
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));
}
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.