void ShinyMetal::Insert(std::ostream& fout) const { int texcolor=0, texbump=0; texcolor = colorTexture(fout); texbump = bumpTexture(fout); if (texcolor) { fout << "Material \"shinymetal\" \"texture Kd\" \"" << texcolor << "\""; if (texbump) fout << " \"texture bumpmap\" \"" << texbump << "\""; fout << std::endl; } }
void Uber::Insert(std::ostream& fout) const { int texcolor=0, texbump=0; texcolor = colorTexture(fout); texbump = bumpTexture(fout); MStatus status; MObject object; MPlug reflectivityPlug = MFnDependencyNode(shaderNode).findPlug("reflectivity"); MPlug translucencePlug = MFnDependencyNode(shaderNode).findPlug("translucence"); MPlug specularPlug = MFnDependencyNode(shaderNode).findPlug("specularColor"); status = specularPlug.getValue(object); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get specular color value out"); } MFnNumericData specularData(object, &status); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get specular color data"); } if (texcolor) { fout << "Material \"uber\" \"texture Kd\" \"" << texcolor << "\" "; if (texbump) fout << "\"texture bumpmap\" \"" << texbump << "\" "; float r; status = reflectivityPlug.getValue(r); if (status == MStatus::kSuccess) fout << "\"color Kr\" [" << r << " " << r << " " << r << "] "; if (specularData.numericType() == MFnNumericData::k3Float) { float r,g,b; specularData.getData(r,g,b); fout << "\"color Ks\" [" << r << " " << g << " " << b << "] "; } else if (specularData.numericType() == MFnNumericData::k3Double) { double r,g,b; specularData.getData(r,g,b); fout << "\"color Ks\" [" << r << " " << g << " " << b << "] "; } float opacity; status = translucencePlug.getValue(opacity); opacity = 1.f - opacity; if (status == MStatus::kSuccess) fout << "\"color opacity\" [" << opacity << " " << opacity << " " << opacity << "] "; fout << std::endl; } }
sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* source, const Context& ctx, SkIPoint* offset) const { SkIPoint colorOffset = SkIPoint::Make(0, 0); sk_sp<SkSpecialImage> color(this->filterInput(1, source, ctx, &colorOffset)); if (!color) { return nullptr; } SkIPoint displOffset = SkIPoint::Make(0, 0); sk_sp<SkSpecialImage> displ(this->filterInput(0, source, ctx, &displOffset)); if (!displ) { return nullptr; } const SkIRect srcBounds = SkIRect::MakeXYWH(colorOffset.x(), colorOffset.y(), color->width(), color->height()); // Both paths do bounds checking on color pixel access, we don't need to // pad the color bitmap to bounds here. SkIRect bounds; if (!this->applyCropRect(ctx, srcBounds, &bounds)) { return nullptr; } SkIRect displBounds; displ = this->applyCropRect(ctx, displ.get(), &displOffset, &displBounds); if (!displ) { return nullptr; } if (!bounds.intersect(displBounds)) { return nullptr; } const SkIRect colorBounds = bounds.makeOffset(-colorOffset.x(), -colorOffset.y()); SkVector scale = SkVector::Make(fScale, fScale); ctx.ctm().mapVectors(&scale, 1); #if SK_SUPPORT_GPU if (source->isTextureBacked()) { GrContext* context = source->getContext(); sk_sp<GrTexture> colorTexture(color->asTextureRef(context)); sk_sp<GrTexture> displTexture(displ->asTextureRef(context)); if (!colorTexture || !displTexture) { return nullptr; } GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = bounds.width(); desc.fHeight = bounds.height(); desc.fConfig = kSkia8888_GrPixelConfig; SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc)); if (!dst) { return nullptr; } GrPaint paint; SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displTexture.get()); offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX), SkIntToScalar(colorOffset.fY - displOffset.fY)); paint.addColorFragmentProcessor( GrDisplacementMapEffect::Create(fXChannelSelector, fYChannelSelector, scale, displTexture.get(), offsetMatrix, colorTexture.get(), SkISize::Make(color->width(), color->height())))->unref(); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); SkMatrix matrix; matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y())); SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())); if (!drawContext) { return nullptr; } drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorBounds)); offset->fX = bounds.left(); offset->fY = bounds.top(); return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), kNeedNewImageUniqueID_SpecialImage, dst); } #endif SkBitmap colorBM, displBM; if (!color->getROPixels(&colorBM) || !displ->getROPixels(&displBM)) { return nullptr; } if ((colorBM.colorType() != kN32_SkColorType) || (displBM.colorType() != kN32_SkColorType)) { return nullptr; } SkAutoLockPixels colorLock(colorBM), displLock(displBM); if (!colorBM.getPixels() || !displBM.getPixels()) { return nullptr; } SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), colorBM.alphaType()); SkBitmap dst; if (!dst.tryAllocPixels(info)) { return nullptr; } SkAutoLockPixels dstLock(dst); computeDisplacement(fXChannelSelector, fYChannelSelector, scale, &dst, displBM, colorOffset - displOffset, colorBM, colorBounds); offset->fX = bounds.left(); offset->fY = bounds.top(); return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds.height()), dst); }
void WScatterData::updateGL() { int N = model_->rowCount(); int cnt = countSimpleData(); FloatBuffer simplePtsArray = Utils::createFloatBuffer(3*cnt); FloatBuffer simplePtsSize = Utils::createFloatBuffer(cnt); FloatBuffer coloredPtsArray = Utils::createFloatBuffer(3*(N-cnt)); FloatBuffer coloredPtsSize = Utils::createFloatBuffer(N-cnt); FloatBuffer coloredPtsColor = Utils::createFloatBuffer(4*(N-cnt)); dataFromModel(simplePtsArray, simplePtsSize, coloredPtsArray, coloredPtsSize, coloredPtsColor); if (simplePtsArray.size() != 0) { // initialize vertex-buffer vertexPosBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexPosBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, simplePtsArray, WGLWidget::STATIC_DRAW, true); vertexBufferSize_ = simplePtsArray.size(); // sizes of simple points vertexSizeBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexSizeBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, simplePtsSize, WGLWidget::STATIC_DRAW, true); } if (coloredPtsArray.size() != 0) { // pos of colored points vertexPosBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexPosBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsArray, WGLWidget::STATIC_DRAW, true); vertexBuffer2Size_ = coloredPtsArray.size(); // size of colored points vertexSizeBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexSizeBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsSize, WGLWidget::STATIC_DRAW, true); // color of colored points vertexColorBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexColorBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsColor, WGLWidget::STATIC_DRAW, true); } if (droplinesEnabled_) { FloatBuffer dropLineVerts = Utils::createFloatBuffer(2*3*N); dropLineVertices(simplePtsArray, dropLineVerts); dropLineVertices(coloredPtsArray, dropLineVerts); lineVertBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, lineVertBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, dropLineVerts, WGLWidget::STATIC_DRAW, true); lineVertBufferSize_ = dropLineVerts.size(); } // initialize texture colormapTexture_ = colorTexture(); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_MAG_FILTER, WGLWidget::NEAREST); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_MIN_FILTER, WGLWidget::NEAREST); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_WRAP_S,WGLWidget::CLAMP_TO_EDGE); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_WRAP_T,WGLWidget::CLAMP_TO_EDGE); initShaders(); chart_->useProgram(shaderProgram_); chart_->uniformMatrix4(mvMatrixUniform_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform_, chart_->pMatrix()); chart_->useProgram(colShaderProgram_); chart_->uniformMatrix4(mvMatrixUniform2_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform2_, chart_->pMatrix()); chart_->useProgram(linesProgram_); chart_->uniformMatrix4(mvMatrixUniform3_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform3_, chart_->pMatrix()); chart_->useProgram(shaderProgram_); float text_min, text_max; if (colormap_ != 0) { text_min = (float)chart_->toPlotCubeCoords(colormap_->minimum(), ZAxis_3D); text_max = (float)chart_->toPlotCubeCoords(colormap_->maximum(), ZAxis_3D); chart_->uniform1f(offsetUniform_, text_min); chart_->uniform1f(scaleFactorUniform_, 1.0/(text_max - text_min)); } else { chart_->uniform1f(offsetUniform_, 0.0); chart_->uniform1f(scaleFactorUniform_, 1.0); } }