Effect

/////////////////////////////////shader source/////////////////////////////////
Texture2D colorMap : register( t0 );
SamplerState colorSampler : register( s0 );

cbuffer cbChangesEveryFrame : register( b0 )
{
  matrix worldMatrix;
};

cbuffer cbNeverChanges : register( b1 )
{
  matrix viewMatrix;
};

cbuffer cbChangeOnResize : register( b2 )
{
  matrix projMatrix;
};

struct VS_Input
{
  float4 pos : POSITION;
  float2 tex0 : TEXCOORD0;
};

struct PS_Input
{
  float4 pos : SV_POSITION;
  float2 tex0 : TEXCOORD0;
};

PS_Input VS_Main( VS_Input vertex )
{
  PS_Input vsOut = ( PS_Input )0;
  vsOut.pos = mul( vertex.pos, worldMatrix );
  vsOut.pos = mul( vsOut.pos, viewMatrix );
  vsOut.pos = mul( vsOut.pos, projMatrix );
  vsOut.tex0 = vertex.tex0;

  return vsOut;
}

float4 PS_Main( PS_Input frag ) : SV_TARGET
{
  return 1.0f - colorMap.Sample( colorSampler, frag.tex0 );
}

technique11 ColorInversion
{
  pass P0
  {
    SetVertexShader( CompileShader( vs_5_0, VS_Main() ) );
    SetGeometryShader( NULL );
    SetPixelShader( CompileShader( ps_5_0, PS_Main() ) );
  }
}

/////////////////////end shader source ////////////////////////

ID3DBlob* buffer = 0;
RESULT d3dResult;
bool compileResult = CompileD3DShader( "ColorInversion.fx", 0, "fx_5_0", &buffer );

ID3DX11Effect* effect_;
D3DX11CreateEffectFromMemory(buffer->GetBufferPointer(),buffer->GetBufferSize(),0,d3dDevice_,&effect_);

D3D11_INPUT_ELEMENT_DESC solidColorLayout[]=
{
{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERETEX_DATA,0},
{"TEXCOORD",0,DCGI_FORMAT_R32G32_FLOAT,0,12,D3D11_INPUT_PER_VERETEX_DATA,0}
};

unsigned int totalLayoutElements = ARRAYSIZE(solidColorLayout);

ID3DX11EffectTechnique* colorInvTechnique;
colorInvTechnique = effect_->GetTechniqueByName("ColorInversion");
ID3DX11EffectPass* effectPass = colorInvTechnique->GetPassByIndex(0);

D3DX11_PASS_SHADER_DESC passDesc;
D3DX11_EFFECT_SHADER_DESC shaderDesc;
effectPass->GetVertexShaderDesc(&passDesc);
passDesc.pShaderVatiable->GetShaderDesc(passDesc.ShaderIndex,&shaderDesc);

d3dResult = d3dDevice_->CreateInputLayout(solidColorLayout,totalLayoutElements,shaderDesc.pBytecode,
shaderDesc.BytecodeLength,&inputLayout_);

buffer->Release();

//render
float clearColor[4] = { 0.0f, 0.0f, 0.25f,1.0f};
d3dContex_->ClearRenderTargetView(backBufferTarget_,clearColor);
d3dContex_-->ClearDepthStencilVIew(depthStencilView_,D3D11_CLEAT_DEPTH,1.0f,0);

unsigned int stride = sizeof(VertexPos);
unsigned int offset = 0;

d3dContex_->IASetInputLayout(inputLayout_);
d3dContex_->IASetVertexBuffers(0,1,&vertexBuffer_,&stride,&offset);
d3dContex_->IASetIndexBuffer(indexBuffer_,DXGI_FORMAT_R16_UINT,0);
d3dContex_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

XMMATRIX rotationMat = XMMatrixRotationRollPitchYaw(0.0f,0.7f,0.7f);
XMMATRIX translationMat = XMMatrixTranslation(0.0f,0.0f,6.0f);
XMMATRIX worldMat = rotationMat * translationMat;

ID3DX11EffectShaderResourceVariable* colorMap;
colorMap = effect_->GetVariableByName("colorMap")->AsShaderResource();
colorMap->SetResource(colorMap_);

ID3DX11EffectSamplerVariable* colorMapSampler;
colorMapSampler = effect_->GetVariableByName("colorSampler")->AsSampler();
colorSampler->SetSampler(0,colorMapSampler);

ID3DX11EffectMatrixVariable* worldMatrix;
worldMatrix = effect_->GetVariableByName("worldMatrix")->AsMatrix();
worldMatrix->SetMatrix((float*)&worldMat);

ID3DX11EffectTechnique* colorInvTechnique;
colorInvTechnique = effect_->GetTechniqueByName("ColorINversion");

D3DX11_TECHNIQUE_DESC techDesc;
colorInvTechnique->GetDws(&techDesc);
for(unsigned int p = 0, p < techDesc.Passed;p++)
{
ID3DXEffectPass* pass = colorInvTechnique->GetPassByIndex(p);
if(pass != 0)
{
pass->Apple(0,dedContext_);
d3dContext_->DrawIndexed(36,0,0);
}
}

swapChain_->Present(0,0);

//创建Effect
//CompileD3DShader(----------------------------)
DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
shaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* errorBuffer = 0;
HRSULT rsult;
result = D3DX11CompileFromFile(filePath,0,0,0,"fx_5_0",shaderFlags,0,0,buffer,*errorBuffer,0);、

时间: 2025-01-07 03:31:09

Effect的相关文章

POJ 1135 Domino Effect(最短路 多米诺骨牌)

题意 题目描述: 你知道多米诺骨牌除了用来玩多米诺骨牌游戏外,还有其他用途吗?多米诺骨牌游戏:取一 些多米诺骨牌,竖着排成连续的一行,两张骨牌之间只有很短的空隙.如果排列得很好,当你推 倒第 1张骨牌,会使其他骨牌连续地倒下(这就是短语"多米诺效应"的由来). 然而当骨牌数量很少时,这种玩法就没多大意思了,所以一些人在 80 年代早期开创了另一个 极端的多米诺骨牌游戏:用上百万张不同颜色.不同材料的骨牌拼成一幅复杂的图案.他们开创 了一种流行的艺术.在这种骨牌游戏中,通常有多行骨牌同时

How to create water Ripple effect using HTML5 canvas

https://www.script-tutorials.com/how-to-create-water-drops-effect-using-html5-canvas/ https://www.script-tutorials.com/demos/97/index.html Rain & Water Effects(只在谷歌浏览器有效) http://tympanus.net/Development/RainEffect/#slide-1 示例(http://tympanus.net/Deve

[256个管理学理论]004.鲶鱼效应(Catfish Effect)

鲶鱼效应(Catfish Effect) 来自于大洋彼岸的让你看不懂的解释: 鲶鱼效应(Catfish Effect):鲶鱼在搅动小鱼生存环境的同时,也激活了小鱼的求生能力.鲶鱼效应是采取一种手段或措施,刺激一些企业活跃起来投入到市场中积极参与竞争,从而激活市场中的同行业企业.其实质是一种负激励,是激活员工队伍之奥秘.需要强调的一点,在某些企业中,由于一些官僚长期无所作为或者无力承担新任务新责任,鲶鱼性人才成为企业正向提升的动力. 鲶 鱼:一种生性好动的鱼类,其本身并没有什么十分特别的地方.然而

unity3d 制造自己的水体water effect(一)

first,I wish you a happy new year, and study in spring festival's eve means you are hardworking,haha. I write in two languages. One passage write in Chineseone passage translate into English. My English is poor., If I write some thing wrong, welcome

the zeigarnik effect:the scientific key to better work

If you, like us, are constantly looking for more efficient ways to work, then you will really appreciate what the Zeigarnik effect has to offer. It carries the name of Bluma Zeigarnik, a Lithuanian-born psychologist who first described this effect in

d3d11 effect state and default value tables

Blend state State Default ValueAlphaToCoverage Enable FALSEIndependentBlend Enable FALSERenderTarget[0].BlendEnable FALSERenderTarget[0].SrcBlend D3D11_BLEND_ONERenderTarget[0].DestBlend D3D11_BLEND_ZERORenderTarget[0].BlendOp D3D11_BLEND_OP_ADDRende

thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)

今天想把玩一下tp5,结果怎么都无法访问,每次都是报500错误,我把错误提示都打开看到下面的错误 require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s): (/mnt/hgfs/root/tp5/public/:/tmp/:/proc/) 1,我是php7 ,php.ini里面的open_basedir

一些WPF中的滤镜特效——Effect Library

WPF支持类似PhotoShop的滤镜功能,称之为Effect.在.Net 4.0中,WPF就废弃了对BitMapEffect的支持,转向使用支持GPU加速的Effect类,例如,我们可以使用如下代码生成带有阴影效果的按钮. 1 <Button ... > 2 <Button.Effect> 3 <DropShadowEffect /> 4 </Button.Effect> 5 Hello 6 </Button> 系统已经自带了十来种Effect

unity, 在image effect shader中用_CameraDepthTexture重建世界坐标

我用于渲染_CameraDepthTexture的相机是一个透视相机.正交的情况没试,估计差不多. unity的image effect的机制我们大致都了解:它是画了一个覆盖全屏的quad(具体尺寸和位置未知). 要注意的是image effect使用的投影矩阵并非相机的投影矩阵,而是使用了一个正交投影矩阵(具体形式未知),这一点我卡了好久才意识到,不过一想也很正常合理,毕竟只是想画个全屏quad,直接push个正交矩阵(即切换到2d模式)去画就好了. 虽然image effect使用的投影矩阵