D3D11PFX_HDR::D3D11PFX_HDR(D3D11PfxRenderer* rnd) : D3D11PFX_Effect(rnd) { D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; // Create lum-buffer LumBuffer1 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2))); LumBuffer2 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2))); LumBuffer3 = new RenderToTextureBuffer(engine->GetDevice(), LUM_SIZE, LUM_SIZE, DXGI_FORMAT_R16_FLOAT, NULL, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, (int)(log(LUM_SIZE) / log(2))); engine->GetContext()->ClearRenderTargetView(LumBuffer1->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0)); engine->GetContext()->ClearRenderTargetView(LumBuffer2->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0)); engine->GetContext()->ClearRenderTargetView(LumBuffer3->GetRenderTargetView(), (float *)&D3DXVECTOR4(0,0,0,0)); ActiveLumBuffer = 0; }
/** Initializes the ocean */ XRESULT GOcean::InitOcean() { D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; PlaneMesh = new GMesh; if(XR_SUCCESS != PlaneMesh->LoadMesh("system\\GD3D11\\Meshes\\PlaneSubdiv.3ds")) { delete PlaneMesh; PlaneMesh = NULL; return XR_FAILED; } // Create ocean simulating object // Ocean object OceanParameter ocean_param; // The size of displacement map. In this sample, it's fixed to 512. ocean_param.dmap_dim = 512; // The side length (world space) of square patch ocean_param.patch_length = 2000.0f; // Adjust this parameter to control the simulation speed ocean_param.time_scale = 0.8f; // A scale to control the amplitude. Not the world space height ocean_param.wave_amplitude = 0.35f; // 2D wind direction. No need to be normalized ocean_param.wind_dir = D3DXVECTOR2(0.8f, 0.6f); // The bigger the wind speed, the larger scale of wave crest. // But the wave scale can be no larger than patch_length ocean_param.wind_speed = 600.0f; // Damp out the components opposite to wind direction. // The smaller the value, the higher wind dependency ocean_param.wind_dependency = 0.07f; // Control the scale of horizontal movement. Higher value creates // pointy crests. ocean_param.choppy_scale = 1.3f; FFTOceanSimulator = new OceanSimulator(ocean_param, engine->GetDevice()); // Update the simulation for the first time. FFTOceanSimulator->updateDisplacementMap(0); // Create fresnel map CreateFresnelMap(engine->GetDevice()); return XR_SUCCESS; }
/** Called on resize */ XRESULT D3D11PfxRenderer::OnResize(const INT2& newResolution) { D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; // Create temp-buffer delete TempBuffer; TempBuffer = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x, newResolution.y, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL); delete TempBufferDS4_1; TempBufferDS4_1 = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x / 4, newResolution.y / 4, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL); delete TempBufferDS4_2; TempBufferDS4_2 = new RenderToTextureBuffer(engine->GetDevice(), newResolution.x / 4, newResolution.y / 4, DXGI_FORMAT_R16G16B16A16_FLOAT, NULL); FX_SMAA->OnResize(newResolution); return XR_SUCCESS; }
/** Sets the position and size of this sub-view */ void SV_GMeshInfoView::SetRect(const D2D1_RECT_F& rect) { D3D11GraphicsEngine* g = (D3D11GraphicsEngine *)Engine::GraphicsEngine; D2DSubView::SetRect(rect); Panel->SetRect(D2D1::RectF(0, 0, GetSize().width, GetSize().height)); // Create new RT delete RT; RT = new RenderToTextureBuffer(g->GetDevice(), (UINT)std::max(8.0f, GetSize().width), (UINT)std::max(8.0f, GetSize().height), DXGI_FORMAT_R8G8B8A8_UNORM); delete DS; DS = new RenderToDepthStencilBuffer(g->GetDevice(), (UINT)std::max(8.0f, GetSize().width), (UINT)std::max(8.0f, GetSize().height), DXGI_FORMAT_R32_TYPELESS, NULL, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT); }
/** Creates the vertexbuffer with the given arguments */ XRESULT D3D11VertexBuffer::Init(void* initData, unsigned int sizeInBytes, EBindFlags EBindFlags, EUsageFlags usage, ECPUAccessFlags cpuAccess, const std::string& fileName) { HRESULT hr; D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; if (sizeInBytes == 0) { LogError() << "VertexBuffer size can't be 0!"; } SizeInBytes = sizeInBytes; // Create our own vertexbuffer D3D11_BUFFER_DESC bufferDesc; bufferDesc.ByteWidth = sizeInBytes; bufferDesc.Usage = (D3D11_USAGE)usage; bufferDesc.BindFlags = (D3D11_BIND_FLAG)EBindFlags; bufferDesc.CPUAccessFlags = (D3D11_CPU_ACCESS_FLAG)cpuAccess; bufferDesc.MiscFlags = 0; // In case we dont have data, allocate some to satisfy D3D11 char* data = NULL; if (!initData) { data = new char[bufferDesc.ByteWidth]; memset(data, 0, bufferDesc.ByteWidth); initData = data; } D3D11_SUBRESOURCE_DATA InitData; InitData.pSysMem = initData; InitData.SysMemPitch = 0; InitData.SysMemSlicePitch = 0; LE(engine->GetDevice()->CreateBuffer(&bufferDesc, &InitData, &VertexBuffer)); #ifndef PUBLIC_RELEASE VertexBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, fileName.size(), fileName.c_str()); #endif delete[] data; return XR_SUCCESS; }
D3D11PfxRenderer::D3D11PfxRenderer(void) { TempBuffer = NULL; TempBufferDS4_1 = NULL; TempBufferDS4_2 = NULL; FX_Blur = NULL; D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; ScreenQuad = new D3D11FullscreenQuad; ScreenQuad->CreateQuad(engine->GetDevice()); FX_Blur = new D3D11PFX_Blur(this); FX_HeightFog = new D3D11PFX_HeightFog(this); //FX_DistanceBlur = new D3D11PFX_DistanceBlur(this); FX_HDR = new D3D11PFX_HDR(this); FX_SMAA = new D3D11PFX_SMAA(this); FX_GodRays = new D3D11PFX_GodRays(this); NvHBAO = new D3D11NVHBAO; NvHBAO->Init(); }
/** Loads shader */ XRESULT D3D11VShader::LoadShader(const char* vertexShader, int layout, std::vector<D3D10_SHADER_MACRO>& makros) { HRESULT hr; D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine; ID3DBlob* vsBlob; LogInfo() << "Compilling vertex shader: " << vertexShader; File = vertexShader; // Compile shader if(FAILED(CompileShaderFromFile(vertexShader, "VSMain", "vs_4_0", &vsBlob, makros))) { return XR_FAILED; } // Create the shader LE(engine->GetDevice()->CreateVertexShader(vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), NULL, &VertexShader)); #ifndef PUBLIC_RELEASE VertexShader->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(vertexShader), vertexShader); #endif const D3D11_INPUT_ELEMENT_DESC layout1[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout2[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout3[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 2, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 3, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BONEIDS", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout4[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, { "INSTANCE_SCALE", 0, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, }; const D3D11_INPUT_ELEMENT_DESC layout5[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout6[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout7[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout8[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; const D3D11_INPUT_ELEMENT_DESC layout9[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, }; const D3D11_INPUT_ELEMENT_DESC layout10[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "DIFFUSE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "INSTANCE_WORLD_MATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, { "INSTANCE_WORLD_MATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1}, //{ "INSTANCE_COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, }; switch (layout) { case 1: LE(engine->GetDevice()->CreateInputLayout(layout1, ARRAYSIZE(layout1), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 2: LE(engine->GetDevice()->CreateInputLayout(layout2, ARRAYSIZE(layout2), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 3: LE(engine->GetDevice()->CreateInputLayout(layout3, ARRAYSIZE(layout3), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 4: LE(engine->GetDevice()->CreateInputLayout(layout4, ARRAYSIZE(layout4), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 5: LE(engine->GetDevice()->CreateInputLayout(layout5, ARRAYSIZE(layout5), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 6: LE(engine->GetDevice()->CreateInputLayout(layout6, ARRAYSIZE(layout6), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 7: LE(engine->GetDevice()->CreateInputLayout(layout7, ARRAYSIZE(layout7), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 8: LE(engine->GetDevice()->CreateInputLayout(layout8, ARRAYSIZE(layout8), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 9: LE(engine->GetDevice()->CreateInputLayout(layout9, ARRAYSIZE(layout9), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; case 10: LE(engine->GetDevice()->CreateInputLayout(layout10, ARRAYSIZE(layout10), vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &InputLayout)); break; } return XR_SUCCESS; }