/////////////////////////////////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. 高并发下linux ulimit优化

    系统性能一直是一个受关注的话题,如何通过最简单的设置来实现最有效的性能调优,如何在有限资源的条件下保证程序的运作,ulimit 是我们在处理这些问题时,经常使用的一种简单手段.ulimit 是一种 l ...

  2. UI基础:UIControl及其子类

    UISegmentedControl  UISegmentedControl 是iOS中的分段控件 每个segment 都能被点击,相当于集成了若干个button. 通常我们会点击不同的segment ...

  3. xgboost 简单测试

    #coding=utf8 import pandas as pd from sklearn.model_selection import train_test_split from sklearn.f ...

  4. JPEG文件格式

    格式:JFIF(JPEG档的交换格式)压缩:JPEG(灰阶影像压缩比约为10:1:彩色影像约为20:1)以JPEG文件格式保存的图像实际上是2个不同格式的混合物:JPEG格式规范本身,用来定义图像的压 ...

  5. ORA-01791: not a SELECTed expression

    Student表有3个字段:id,name,age 看这两个SQL语句 (1)select name from student order by id; (2)select distinct(name ...

  6. smarty学习——高级知识

    1.Objects 对象 smarty允许通过模板访问PHP对象.有两种方式来访问它们.一种是注册对象到模板,然后通过类似于用户自定义函数的形式来访问它. 另一种方法给模板分配对象,然后通过访问其它赋 ...

  7. tomcat源码阅读之安全机制

    一.领域(Realm): 1.Principal接口代表角色信息,包含了三个成员:用户名.密码.role列表(以逗号分隔),对应了tomcat-users.xml文件中一行user信息: Generi ...

  8. gphoto2 canon eos450d

    hjs@ubuntu:~$ gphoto2 --capture-image-and-download                                                   ...

  9. Oracle GI 日志收集工具 - TFA 简介

    转载自:https://blogs.oracle.com/Database4CN/entry/tfa_collector_%E4%BB%8B%E7%BB%8D 1.TFA的目的: TFA是个11.2版 ...

  10. iPhone激活策略知识讲解:官方解锁和黑解

    iPhone激活策略知识讲解:官方解锁和黑解 [复制链接]     LEECHY 该用户从未签到 1372 XY豆 438 帖子 440 贡献 苹果花 积分 2250 发消息 电梯直达 楼主    发 ...