void RayTracerMaterial::createVertexBuffer(ID3D11Device * device, const Mesh& mesh, ID3D11Buffer** vertexBuffers)const { const std::vector<XMFLOAT3>& sourceVertices = mesh.vertices(); std::vector<XMFLOAT3>* textureCoordinates = mesh.textureCoords().at(0); assert(textureCoordinates->size() == sourceVertices.size()); std::vector<VertexPositionTexture> vertices; vertices.reserve(sourceVertices.size()); for (UINT i = 0; i < sourceVertices.size(); i++) { XMFLOAT3 position = sourceVertices.at(i); XMFLOAT3 uv = textureCoordinates->at(i); vertices.push_back(VertexPositionTexture(XMFLOAT4(position.x, position.y, position.z, 1.0f), XMFLOAT2(uv.x, uv.y))); } createVertexBuffer(device, &vertices[0], vertices.size(), vertexBuffers); }
PostProcessRenderer::PostProcessRenderer(GraphicsContext& graphicsContext) : _graphicsContext(graphicsContext), _quadVertexBuffer(graphicsContext.CreateVertexBuffer(BufferType::Static)) { static const VertexPositionTexture quadVertices[6] { VertexPositionTexture(Vector3f(-1, 1, 0), Vector2f::UnitY), VertexPositionTexture(Vector3f(-1, -1, 0), Vector2f::Zero), VertexPositionTexture(Vector3f(1, -1, 0), Vector2f::UnitX), VertexPositionTexture(Vector3f(-1, 1, 0), Vector2f::UnitY), VertexPositionTexture(Vector3f(1, -1, 0), Vector2f::UnitX), VertexPositionTexture(Vector3f(1, 1, 0), Vector2f::One), }; _quadVertexBuffer->SetVertexData(quadVertices, Array::Length(quadVertices)); _currentRenderTarget = _graphicsContext.CreateRenderTarget(1920, 1080, DepthBufferFormat::Depth24Stencil8); _backgroundRenderTarget = _graphicsContext.CreateRenderTarget(1920, 1080, DepthBufferFormat::Depth24Stencil8); static const std::string VertexShader = R"XXX( #version 330 core layout(location = 0) in vec3 vertexPosition; layout(location = 2) in vec2 vertexUV; out vec2 fragmentUV; void main(){ gl_Position = vec4(vertexPosition, 1); fragmentUV = vertexUV; })XXX"; static const std::string FragmentShader = R"XXX( #version 330 core in vec2 fragmentUV; out vec4 color; uniform sampler2D TextureSampler; void main() { color = texture2D(TextureSampler, fragmentUV); })XXX";