/////////////////////////////////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. UI基础:事件.响应链 分类: iOS学习-UI 2015-07-03 19:51 1人阅读 评论(0) 收藏

    UIEvent:事件,是由硬件捕捉的一个代表用户操作操作设备的对象. 事件分三类:触摸事件.晃动事件.远程控制事件. 触摸事件:用户通过触摸设备屏幕操作对象,.输入数据.支持多点触摸,包含1个到多个触 ...

  2. linux下sprintf_s函数的替代

    error code: ]; sprintf_s(buf, , "predicted position:(%3d, %3d)", predict_pt.x, predict_pt. ...

  3. HDU 3342:Legal or Not(拓扑排序)

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  4. Linux操作系统网络配置

  5. L2-2 重排链表 (25 分)

    给定一个单链表 L​1​​→L​2​​→⋯→L​n−1​​→L​n​​,请编写程序将链表重新排列为 L​n​​→L​1​​→L​n−1​​→L​2​​→⋯.例如:给定L为1→2→3→4→5→6,则输出 ...

  6. treeql 基于rest 标准的接口开发协议

    treeql 可以让我们按照数据库的关系模型,生成一个tree 模型的json 数据,基于rest 标准, 从设计上,来说还是很不错的,但是从长远发展来说graphql 应该会更好,也有相关的比较 参 ...

  7. mave安装配置

    首先从官网上 http://maven.apache.org/ 下载最新版Maven.我用的是apache-maven-3.0.4-bin.tar.gz.将下载后的文件拷贝到 /usr/local/目 ...

  8. Oracle 11gR2 RAC 新特性说明

    最近接触了一下Oracle 11g R2 的RAC,发现变化很大. 所以在自己动手做实验之前还是先研究下它的新特性比较好. 一.    官网介绍 先看一下Oracle 的官网文档里对RAC 新特性的一 ...

  9. sed 给文件每行末尾追加相同字符

    给文件file1每行末尾追加字符 ; sed 's/$/;/' file1

  10. jquery ajax 上传文件

    html:<!-- /.tab-pane --> <div class="tab-pane" id="head_portrait"> & ...