/////////////////////////////////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);、

Effect的更多相关文章

  1. GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)

    GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1) 前言: 无意打开GooglePlay app来着,然后发现首页用了揭示效果,连起来用着感觉还不错. 不清楚 ...

  2. Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果

    Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...

  3. 数据分析 - 斯特鲁普效应(Stroop effect)

    数据分析 - 斯特鲁普效应(Stroop effect) Reinhard得到了一份斯特鲁普效应试验的数据,我们来分析下,文字的颜色,是否会影响受试者的反应. 这里先看看什么是斯特鲁普效应: 斯特鲁普 ...

  4. My Tornado Particle Effect

    These animations are more able to demostrate this plugin than the following static images. :) test 1 ...

  5. 3D Grid Effect – 使用 CSS3 制作网格动画效果

    今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的​​.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...

  6. CF 405B Domino Effect(想法题)

    题目链接: 传送门 Domino Effect time limit per test:1 second     memory limit per test:256 megabytes Descrip ...

  7. Material Design风格的水波涟漪效果(Ripple Effect)的实现

    Material Design是Google在2014年Google I/O大会上推出的一套全新的设计语言,经过接近两年的发展,可谓是以燎原之势影响着整个设计交互生态,和Material Design ...

  8. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  9. 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.sc ...

  10. PHPExcel中open_basedir restriction in effect的解决方法

    用PHPExcel做导出execl的时候发现在本地没有问题,但是把网站传到租用的服务器的时候就报错,具体如下: Warning: realpath() [function.realpath]: ope ...

随机推荐

  1. lamdba 性能测试 大数据内存查找

      由于工作中需要对大量数据进行快速校验,试验采用读入内存List实体采用lamdba查找来实现. 实际需求:实际读入内存数据 50W条记录主集数据,还包含约20个子集,子集最大记录数300W条记录. ...

  2. nib must contain exactly one top level object which must be a UICollectionReusableView instance

    多了一个

  3. HDU 1234:开门人和关门人

    开门人和关门人 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. ElasticSearch(十):springboot集成ElasticSearch集群完成数据的增,删,改

    前言 之前介绍了使用devTools进行索引库数据的crud,这里使用的是java程序,使用中间件activeMQ进行数据库和索引库数据的同步.主要是用来完成对数据库的修改来完成对索引库的同步. 正文 ...

  5. POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)

    推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文 ...

  6. SQL Server2008 R2命令行启动及停止SQL服务的方法

    ===================================================== 在 SQL Server中,想要启动或停止SQL Server服务,通过SQL Server ...

  7. 在oracle的连接(join)中使用using关键字

    如果是使用natraul join,并且两张表中如果有多个字段是具有相同的名称和数据类型的,那么这些字段都将被oracle自作主张的将他们连接起来. 但实际上我们有时候是不需要这样来连接的.我们只需要 ...

  8. cocos2dx学习资料

    [9秒原创]cocos2d-x——CCScrollView用法 http://www.9miao.com/thread-45619-1-1.html [9秒原创]cocos2d-x——场景切换效果示例 ...

  9. some ideas

    1. 3d camera h/w: 单反+projector s/w: 抓图 -> 3d成像 -> 3d显示 -->  3d编辑(?具体要那些功能)--> to 3d prin ...

  10. css 通用兄弟选择器( ~ )

    stylus设置兄弟元素样式: 鼠标浮动在 .video-li 元素上时,.video-li 兄弟中 .video-info 下的 .word 显示. .video-li &:hover ~ ...