void DXPrimitives::DrawLineCircle(vec3 position, float radius, vec3 axisOfRotation) { vec3 referenceAxis = UNIT_X; if(axisOfRotation == referenceAxis) referenceAxis = UNIT_Z; vec3 rotPoint = cross(axisOfRotation, referenceAxis) * radius; const int numSegments = 30; float* verts = new float[numSegments * vertexSize]; for(int i = 0; i < numSegments; i++) { float theta = 2.0f * M_PI * float(i) / float(numSegments - 1); quaternion quat = quat_from_axis_angle(axisOfRotation, theta); vec3 point = quat * rotPoint; verts[i*vertexSize+0] = point.x + position.x; verts[i*vertexSize+1] = point.y + position.y; verts[i*vertexSize+2] = point.z + position.z; verts[i*vertexSize+3] = 1.0f; verts[i*vertexSize+4] = 0.5f; verts[i*vertexSize+5] = 0.5f; } DrawPrimitives(verts, numSegments, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); delete[] verts; }
void Render(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program, dp::RenderState const & state, ref_ptr<TParamsSetter> paramsSetter, TParams const & params) { Bind(context, program); ApplyState(context, program, state); paramsSetter->Apply(context, program, params); DrawPrimitives(context); Unbind(program); };
void DXPrimitives::DrawLines(const vec4 vertices[], int numVertices) { float* verts = new float[numVertices * vertexSize]; for(int i = 0; i < numVertices; i++) { verts[i*vertexSize+0] = vertices[i].x; verts[i*vertexSize+1] = vertices[i].y; verts[i*vertexSize+2] = vertices[i].z; verts[i*vertexSize+3] = vertices[i].w; verts[i*vertexSize+4] = 0.5f; verts[i*vertexSize+5] = 0.5f; } DrawPrimitives(verts, numVertices, D3D11_PRIMITIVE_TOPOLOGY_LINELIST); delete[] verts; }
void DXPrimitives::DrawTris(const vec4 vertices[], const vec2 texCoords[], int numVertices) { float* verts = new float[numVertices * vertexSize]; vec2 texCoord = vec2(0.5f, 0.5f); for(int i = 0; i < numVertices; i++) { verts[i*vertexSize+0] = vertices[i].x; verts[i*vertexSize+1] = vertices[i].y; verts[i*vertexSize+2] = vertices[i].z; verts[i*vertexSize+3] = vertices[i].w; if(texCoords != nullptr) texCoord = texCoords[i]; verts[i*vertexSize+4] = texCoord.x; verts[i*vertexSize+5] = texCoord.y; } DrawPrimitives(verts, numVertices, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); delete[] verts; }
void DXPrimitives::DrawQuads(const vec4 vertices[], const vec2 texCoords[], int numQuadVertices) { //converts quads to tris while buffering int numTriVertices = numQuadVertices * 6 / 4; float* verts = new float[numTriVertices * vertexSize]; const unsigned offsets[] = { 0, 1, 3, 3, 1, 2 }; vec2 texCoord = vec2(0.5f, 0.5f); for(int i = 0; i < numTriVertices; i++) { verts[i*vertexSize+0] = vertices[4*(i/6)+offsets[i%6]].x; verts[i*vertexSize+1] = vertices[4*(i/6)+offsets[i%6]].y; verts[i*vertexSize+2] = vertices[4*(i/6)+offsets[i%6]].z; verts[i*vertexSize+3] = vertices[4*(i/6)+offsets[i%6]].w; if(texCoords != nullptr) texCoord = texCoords[4*(i/6)+offsets[i%6]]; verts[i*vertexSize+4] = texCoord.x; verts[i*vertexSize+5] = texCoord.y; } DrawPrimitives(verts, numTriVertices, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); delete[] verts; }
void Model::Draw(const Matrix4f& transform) const { if (_vbuffer == 0) return; auto video = _context->GetModule<Video>(); if (!video->BindBuffer(_vbuffer, Vertex3::DECLARE.size, Vertex3::DECLARE.types, Vertex3::DECLARE.count)) return; glPushMatrix(); glMultMatrixf(transform.GetData()); video->BindTexture(_texture); if (_ibuffer && video->BindBuffer(_ibuffer, 0, 0, 0)) { video->DrawIndexedPrimitives(_topology, _icount, VALUE_USHORT); video->UnbindBuffer(_ibuffer, 0, 0); } else video->DrawPrimitives(_topology, _vcount, 0); glPopMatrix(); video->UnbindBuffer(_vbuffer, Vertex3::DECLARE.types, Vertex3::DECLARE.count); }
void AnimaRenderer::DeferredDrawAll(AnimaScene* scene) { Anima::AnimaShadersManager* shadersManager = scene->GetShadersManager(); AnimaLightsManager* lightsManager = scene->GetLightsManager(); // // Preparazione dei buffer iniziali // GetGBuffer("PrepassBuffer")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); DeferredPreparePass(scene, shadersManager->GetProgramFromName("deferred-prepare")); Finish(scene); //// //// Aggiorno il buffer per SSAO //// //ApplyEffectFromGBufferToTexture(shadersManager->GetProgramFromName("ssao"), GetGBuffer("PrepassBuffer"), nullptr); //// //// Aggiorno le mappature per le ombre //// //Start(scene); //DeferredUpdateShadowMaps(scene, shadersManager->GetProgramFromName("deferred-shadowMap")); //Finish(scene); // // Preparazione dei buffer della luce // GetGBuffer("LightsBuffer")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glDepthMask(GL_FALSE); AnimaTypeMappedArray<AnimaLight*>* lights = lightsManager->GetLights(); boost::unordered_map<AnimaString, AnimaMappedArray<AnimaLight*>*, AnimaString::Hasher>* lightsMap = lights->GetArraysMap(); for (auto pair : (*lightsMap)) DeferredLightPass(scene, pair.second->GetArray()); glDepthMask(GL_TRUE); glCullFace(GL_BACK); glBlendFunc(GL_ONE, GL_ZERO); Finish(scene); // // Composizione dei buffer nell'immagine finale // if(_primitives.GetSize() <= 0) { GetTexture("DiffuseMap")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); DeferredCombinePass(scene, shadersManager->GetProgramFromName("deferred-combine")); Finish(scene); } else { // Renderizzo l'immagine finale completa di luci in Diffuse2Map GetTexture("Diffuse2Map")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); DeferredCombinePass(scene, shadersManager->GetProgramFromName("deferred-combine")); Finish(scene); // Disegno le primitive in PrimitivesBuffer GetGBuffer("PrimitivesBuffer")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); DrawPrimitives(scene, shadersManager->GetProgramFromName("primitive-draw")); Finish(scene); // Compongo l'immagine finale prendendo la profondità da PrepassBuffer, il colore della scena da Diffuse2Map // ed il colore + profondità da PrimitivesBuffer GetTexture("DiffuseMap")->BindAsRenderTarget(); Start(scene); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); CombinePrimitives(scene, shadersManager->GetProgramFromName("primitive-combine")); Finish(scene); ClearPrimitives(); } ApplyEffectFromTextureToTexture(shadersManager->GetProgramFromName("fxaaFilter"), GetTexture("DiffuseMap"), nullptr); }