Material::Material(Material_t tag) : tag(tag), vertexShader(this), fragmentShader(this), index0AttributeName(this) { mId = Material::MaterialIdCount++; mUuid = Math::generateUUID(); mName = ""; side() = kFrontSide; opacity() = 1.0f; transparent() = false; blending() = kNormalBlending; blendSrc() = kSrcAlphaFactor; blendDst() = kOneMinusSrcAlphaFactor; blendEquation() = kAddEquation; depthTest() = true; depthWrite() = true; polygonOffset() = false; polygonOffsetFactor() = 0; polygonOffsetUnits() = 0; // mAlphaTest = 0; overdraw() = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer visible() = true; needsUpdate() = true; // By default, bind position to attribute index 0. In WebGL, attribute 0 // should always be used to avoid potentially expensive emulation. index0AttributeName("position"); linewidth() = 1.0f; metal() = false; perPixel() = true; shading() = kNoShading; vertexColors() = kNoColors; wireframe() = false; wireframeLinewidth() = 1.0f; }
ParticleBasicMaterial::ParticleBasicMaterial() : Material(kParticleBasicMaterial) { // equivalent to three.js setMaterialShaders initUniforms(uniforms); vertexShader(ParticleBasicMaterial::kVertexShader); fragmentShader(ParticleBasicMaterial::kFragmentShader); color() = Color( 0xffffff ); // map = null; size() = 1.0f; sizeAttenuation() = true; vertexColors() = false; fog() = true; }
/****************************************************************************** * Renders the construction grid. ******************************************************************************/ void ViewportSceneRenderer::renderGrid() { if(isPicking()) return; FloatType gridSpacing; Box2I gridRange; std::tie(gridSpacing, gridRange) = determineGridRange(viewport()); if(gridSpacing <= 0) return; // Determine how many grid lines need to be rendered. int xstart = gridRange.minc.x(); int ystart = gridRange.minc.y(); int numLinesX = gridRange.size(0) + 1; int numLinesY = gridRange.size(1) + 1; FloatType xstartF = (FloatType)xstart * gridSpacing; FloatType ystartF = (FloatType)ystart * gridSpacing; FloatType xendF = (FloatType)(xstart + numLinesX - 1) * gridSpacing; FloatType yendF = (FloatType)(ystart + numLinesY - 1) * gridSpacing; // Allocate vertex buffer. int numVertices = 2 * (numLinesX + numLinesY); std::unique_ptr<Point3[]> vertexPositions(new Point3[numVertices]); std::unique_ptr<ColorA[]> vertexColors(new ColorA[numVertices]); // Build lines array. ColorA color = Viewport::viewportColor(ViewportSettings::COLOR_GRID); ColorA majorColor = Viewport::viewportColor(ViewportSettings::COLOR_GRID_INTENS); ColorA majorMajorColor = Viewport::viewportColor(ViewportSettings::COLOR_GRID_AXIS); Point3* v = vertexPositions.get(); ColorA* c = vertexColors.get(); FloatType x = xstartF; for(int i = xstart; i < xstart + numLinesX; i++, x += gridSpacing, c += 2) { *v++ = Point3(x, ystartF, 0); *v++ = Point3(x, yendF, 0); if((i % 10) != 0) c[0] = c[1] = color; else if(i != 0) c[0] = c[1] = majorColor; else c[0] = c[1] = majorMajorColor; } FloatType y = ystartF; for(int i = ystart; i < ystart + numLinesY; i++, y += gridSpacing, c += 2) { *v++ = Point3(xstartF, y, 0); *v++ = Point3(xendF, y, 0); if((i % 10) != 0) c[0] = c[1] = color; else if(i != 0) c[0] = c[1] = majorColor; else c[0] = c[1] = majorMajorColor; } OVITO_ASSERT(c == vertexColors.get() + numVertices); // Render grid lines. setWorldTransform(viewport()->gridMatrix()); if(!_constructionGridGeometry || !_constructionGridGeometry->isValid(this)) _constructionGridGeometry = createLinePrimitive(); _constructionGridGeometry->setVertexCount(numVertices); _constructionGridGeometry->setVertexPositions(vertexPositions.get()); _constructionGridGeometry->setVertexColors(vertexColors.get()); _constructionGridGeometry->render(this); }
void IShape::Update() { const unsigned int numVertices = GetVertexCount(); // Get all the data. std::unique_ptr<glm::vec3[]> vertexPositions(new glm::vec3[numVertices]); std::unique_ptr<glm::vec4[]> vertexColors(new glm::vec4[numVertices]); std::unique_ptr<glm::vec2[]> vertexTextureCoordinates(new glm::vec2[numVertices]); for (unsigned int i = 0; i < numVertices; ++i) { const glm::vec2 position = GetVertexPosition(i); vertexPositions[i] = glm::vec3(position, 0.0f); vertexColors[i] = m_fillColor; vertexTextureCoordinates[i] = GetTextureCoordinate(i); } // Bind the Vertex Array Object. glBindVertexArray(m_VAO); // Send the vertex position data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_positionVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec3) * numVertices, &vertexPositions[0], GL_STATIC_DRAW ); // Set the vertex position data to be the first attribute // passed to the shader (index 0). glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Send the vertex color data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_colorVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec4) * numVertices, &vertexColors[0], GL_STATIC_DRAW ); // Set the vertex color data to be the third attribute // passed to the shader (index 2). glEnableVertexAttribArray(2); glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, 0); // Texturing... if (m_texture) { // Send the texture coordinate data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_textureCoordinatesVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec2) * numVertices, &vertexTextureCoordinates[0], GL_STATIC_DRAW ); // Set the vertex texture coordinate data to be the fourth // attribute passed to the shader (index 3). glEnableVertexAttribArray(3); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, 0); } // Unbind the Vertex Array Object. glBindVertexArray(0); }