本文整理汇总了C++中ofShader类的典型用法代码示例。如果您正苦于以下问题:C++ ofShader类的具体用法?C++ ofShader怎么用?C++ ofShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ofShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupProjectionUniforms
void ofxRGBDRenderer::setupProjectionUniforms(ofShader& theShader){
rgbMatrix = (depthToRGBView * rgbProjection);
ofVec2f dims = ofVec2f(currentRGBImage->getTextureReference().getWidth(),
currentRGBImage->getTextureReference().getHeight());
theShader.setUniform2f("fudge", xmult, ymult);
theShader.setUniform2f("dim", dims.x, dims.y);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadMatrixf(rgbMatrix.getPtr());
glMatrixMode(GL_MODELVIEW);
}
示例2: draw
void SPECTRUM_INDICATOR__TYPE_POINT::draw(ofShader& shader, float *spectrum)
{
/********************
********************/
shader.setUniform4f("BaseColor", IndicatorColor);
/********************
********************/
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
float spectrum_out = spectrum[NUM_DISP_SPECTRUMS - 1];
for(int id = 0; id < NUM_DISP_SPECTRUMS; id++){
int x = (int)(id * IndicatorHoriSpace);
spectrum_out = FreqFilter_k * spectrum[id] + (1 - FreqFilter_k) * spectrum_out;
shader.setUniform1f( "DispTextureSize", IndicatorTextureSize + IndicatorGainSize * spectrum_out ); // 描画サイズ
// shader.setUniform1f( "TextureSize", IndicatorTextureSize ); // 描画サイズ
for(int y = 0; y <= ofGetHeight()/2; y+= IndicatorVertSpace){
/********************
********************/
vbo_drawPoint(ofVec3f(x, y, 0));
if(y != 0) vbo_drawPoint(ofVec3f(x, -y, 0));
/********************
********************/
if(x != 0){
vbo_drawPoint(ofVec3f(-x, y, 0));
if(y != 0) vbo_drawPoint(ofVec3f(-x, -y, 0));
}
}
}
ofPopMatrix();
}
示例3: updateRenderer
void Dude::updateRenderer( ofShader & shader )
{
// update the rendering matrices
renderMats = animSys.getBoneMatrices();
std::vector<float> boneLengths = animSys.getBoneLengths();
for( int i = 0; i < animSys.getNumBones(); i++ )
{
renderMats[i].scale(1,1,boneLengths[i]);
//renderMats[i].preTranslate(position);
renderMats[i].invert();
}
// prepare rendering steer matrix
renderSteerMatrix.identity();
renderSteerMatrix.translate(position);
renderSteerMatrix *= steerMatrix;
//renderSteerMatrix.translate(-position);
// set it up
shader.setUniformMatrix4f("steerMatrix",ofMatrix4x4((float*)renderSteerMatrix.inverse()));
shader.setUniform1f("blend_k",blend_k);
shader.setUniformMatrix4f("box_mats", (ofMatrix4x4&) renderMats[0], renderMats.size());//
}
示例4: ofPushMatrix
void helix::drawCenteredForDOF( ofShader & dofShader, bool bDrawInner, bool bDrawOuter ){
GLint sideLocation = dofShader.getAttributeLocation("side");
GLint nextLocation = dofShader.getAttributeLocation("next");
ofPoint midPt;
int count = 0;
for (int i = 0; i < helix0.size(); i++){
midPt += helix0[i];
count++;
}
for (int i = 0; i < helix1.size(); i++){
midPt += helix1[i];
count++;
}
for (int i = 0; i < lines.size(); i++){
midPt += lines[i].a;
midPt += lines[i].b;
count += 2;
}
midPt /= (float)count;
ofPushMatrix();
ofTranslate(-midPt.x, -midPt.y, -midPt.z);
if (bDrawOuter){
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < helix0.size()-1; i++){
ofPoint cur = helix0[i];
ofPoint next = helix0[i+1];
ofPoint temp0 = cur;
ofPoint temp1 = next;
temp0.normalize();
temp1.normalize();
ofPoint normal = temp0.cross(temp1).normalize();
dofShader.setAttribute1f(sideLocation, -.5);
dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
//glNormal3f(normal.x, normal.y, normal.y);
glVertex3f(cur.x, cur.y, cur.z);
dofShader.setAttribute1f(sideLocation, +.5);
dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
//glNormal3f(normal.x, normal.y, normal.y);
glVertex3f(cur.x, cur.y, cur.z);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < helix1.size()-1; i++){
ofPoint cur = helix1[i];
ofPoint next = helix1[i+1];
ofPoint temp0 = cur;
ofPoint temp1 = next;
temp0.normalize();
temp1.normalize();
ofPoint normal = temp0.cross(temp1).normalize();
dofShader.setAttribute1f(sideLocation, -.5);
dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
//glNormal3f(normal.x, normal.y, normal.y);
glVertex3f(cur.x, cur.y, cur.z);
dofShader.setAttribute1f(sideLocation, +.5);
dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
//glNormal3f(normal.x, normal.y, normal.y);
glVertex3f(cur.x, cur.y, cur.z);
}
glEnd();
}
if (bDrawInner)
for (int i = 0; i < lines.size(); i++){
//.........这里部分代码省略.........
示例5: uploadMatrices
void ofBaseMaterial::uploadMatrices(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
const ofMatrix4x4 & normalMatrix = renderer.getCurrentNormalMatrix();
shader.setUniformMatrix4f("normalMatrix",normalMatrix);
}
示例6: updateLights
void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
for(size_t i=0;i<ofLightsData().size();i++){
string idx = ofToString(i);
shared_ptr<ofLight::Data> light = ofLightsData()[i].lock();
if(!light || !light->isEnabled){
shader.setUniform1f("lights["+idx+"].enabled",0);
continue;
}
auto lightEyePosition = renderer.getCurrentViewMatrix() * light->position;
shader.setUniform1f("lights["+idx+"].enabled",1);
shader.setUniform1f("lights["+idx+"].type", light->lightType);
shader.setUniform4f("lights["+idx+"].position", lightEyePosition);
shader.setUniform4f("lights["+idx+"].ambient", light->ambientColor);
shader.setUniform4f("lights["+idx+"].specular", light->specularColor);
shader.setUniform4f("lights["+idx+"].diffuse", light->diffuseColor);
if(light->lightType!=OF_LIGHT_DIRECTIONAL){
shader.setUniform1f("lights["+idx+"].constantAttenuation", light->attenuation_constant);
shader.setUniform1f("lights["+idx+"].linearAttenuation", light->attenuation_linear);
shader.setUniform1f("lights["+idx+"].quadraticAttenuation", light->attenuation_quadratic);
}
if(light->lightType==OF_LIGHT_SPOT){
auto direction = toGlm(light->position).xyz() + light->direction;
auto direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction,1.0);
direction = direction4.xyz() / direction4.w;
direction = direction - lightEyePosition.xyz();
shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction));
shader.setUniform1f("lights["+idx+"].spotExponent", light->exponent);
shader.setUniform1f("lights["+idx+"].spotCutoff", light->spotCutOff);
shader.setUniform1f("lights["+idx+"].spotCosCutoff", cos(ofDegToRad(light->spotCutOff)));
}else if(light->lightType==OF_LIGHT_DIRECTIONAL){
auto halfVector = glm::normalize(glm::vec4(0.f, 0.f, 1.f, 0.f) + lightEyePosition);
shader.setUniform3f("lights["+idx+"].halfVector", halfVector.xyz());
}else if(light->lightType==OF_LIGHT_AREA){
shader.setUniform1f("lights["+idx+"].width", light->width);
shader.setUniform1f("lights["+idx+"].height", light->height);
auto direction = light->position.xyz() + light->direction;
auto direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction, 1.0);
direction = direction4.xyz() / direction4.w;
direction = direction - lightEyePosition.xyz();
shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction));
auto right = toGlm(light->position).xyz() + light->right;
auto right4 = renderer.getCurrentViewMatrix() * glm::vec4(right, 1.0);
right = right4.xyz() / right4.w;
right = right - lightEyePosition.xyz();
auto up = glm::cross(toGlm(right), direction);
shader.setUniform3f("lights["+idx+"].right", glm::normalize(toGlm(right)));
shader.setUniform3f("lights["+idx+"].up", glm::normalize(up));
}
}
}
示例7: update
//--------------------------------------------------------------
void SnapshotRamses::update(ofShader& shader)
{
shader.setUniformTexture("uTransform", m_bufferTexture, 0);
}
示例8: updateMaterial
void ofMaterial::updateMaterial(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
shader.setUniform4fv("mat_ambient", &data.ambient.r);
shader.setUniform4fv("mat_diffuse", &data.diffuse.r);
shader.setUniform4fv("mat_specular", &data.specular.r);
shader.setUniform4fv("mat_emissive", &data.emissive.r);
shader.setUniform4fv("global_ambient", &ofGetGlobalAmbientColor().r);
shader.setUniform1f("mat_shininess",data.shininess);
for(auto & uniform: uniforms1f){
shader.setUniform1f(uniform.first, uniform.second);
}
for (auto & uniform : uniforms2f) {
shader.setUniform2f(uniform.first, uniform.second);
}
for (auto & uniform : uniforms3f) {
shader.setUniform3f(uniform.first, uniform.second);
}
for (auto & uniform : uniforms4f) {
shader.setUniform4f(uniform.first, uniform.second);
}
for (auto & uniform : uniforms1i) {
shader.setUniform1i(uniform.first, uniform.second);
}
for (auto & uniform : uniforms2i) {
shader.setUniform2i(uniform.first, uniform.second.x, uniform.second.y);
}
for (auto & uniform : uniforms3i) {
shader.setUniform3i(uniform.first, uniform.second.x, uniform.second.y, uniform.second.z);
}
for (auto & uniform : uniforms4i) {
shader.setUniform4i(uniform.first, uniform.second.x, uniform.second.y, uniform.second.z, uniform.second.w);
}
for (auto & uniform : uniformstex) {
shader.setUniformTexture(uniform.first,
uniform.second.textureTarget,
uniform.second.textureID,
uniform.second.textureLocation);
}
}
示例9: setupProjectionUniforms
//--------------------------------------------------------------- ACTIONS
void CloudsRGBDVideoPlayer::setupProjectionUniforms(ofShader& shader){
if(!getPlayer().isLoaded() || !getTextureReference().isAllocated()){
//ofLogWarning() << " CloudsRGBDVideoPlayer::setupProjectionUniforms -- player is not ready";
return;
}
if(playingVO){
return;
}
shader.setUniformTexture("rgbdTexture", getTextureReference(), 1);
shader.setUniform2f("textureSize", getPlayer().getWidth(), getPlayer().getHeight());
shader.setUniform4f("colorRect", colorRect.x, colorRect.y, colorRect.width, colorRect.height);
shader.setUniform2f("colorScale", colorScale.x, colorScale.y);
shader.setUniform2f("colorFOV", colorFOV.x, colorFOV.y );
shader.setUniform2f("colorPP", colorPrincipalPoint.x, colorPrincipalPoint.y);
shader.setUniform3f("dK", distortionK.x, distortionK.y, distortionK.z);
shader.setUniform2f("dP", distortionP.x, distortionP.y);
ofMatrix4x4 adjustmentMatrix;
adjustmentMatrix.rotate(adjustRotate.x, 0, 1, 0);
adjustmentMatrix.rotate(adjustRotate.y, 1, 0, 0);
adjustmentMatrix.translate(adjustTranslate.x, adjustTranslate.y, adjustTranslate.z);
shader.setUniformMatrix4f("extrinsics", extrinsics * adjustmentMatrix );
shader.setUniform4f("depthRect", depthRect.x, depthRect.y, depthRect.width, depthRect.height);
shader.setUniform2f("depthPP", depthPrincipalPoint.x, depthPrincipalPoint.y);
shader.setUniform2f("depthFOV", depthFOV.x, depthFOV.y);
shader.setUniform4f("normalRect", normalRect.x, normalRect.y, normalRect.width, normalRect.height);
shader.setUniform4f("faceFeatureRect", faceFeatureRect.x, faceFeatureRect.y, faceFeatureRect.width, faceFeatureRect.height);
shader.setUniform4f("deltaChangeRect", deltaChangeRect.x, deltaChangeRect.y, deltaChangeRect.width, deltaChangeRect.height);
shader.setUniform1f("farClip", farClip);
shader.setUniform1f("nearClip", nearClip);
shader.setUniform1f("edgeClip", edgeClip);
shader.setUniform1f("minDepth", minDepth);
shader.setUniform1f("maxDepth", maxDepth);
shader.setUniform3f("skinSampleColor",skinSampleColor.r,skinSampleColor.g,skinSampleColor.b);
shader.setUniform3f("skinWeights", skinWeights.x,skinWeights.y,skinWeights.z);
shader.setUniform2f("skinThreshold", skinThreshold.min, skinThreshold.max);
shader.setUniform3f("headPosition",headPosition.x,-headPosition.y,headPosition.z);
shader.setUniform1f("flowPosition", flowPosition);
}
示例10: setupProjectionUniforms
//--------------------------------------------------------------- ACTIONS
void CloudsRGBDVideoPlayer::setupProjectionUniforms(ofShader& shader){
if(!getPlayer().isLoaded()){
ofLogWarning() << " CloudsRGBDVideoPlayer::setupProjectionUniforms -- player is not ready";
return;
}
shader.setUniformTexture("rgbdTexture", getPlayer().getTextureReference(), 0);
shader.setUniform2f("textureSize", getPlayer().getWidth(), getPlayer().getHeight());
shader.setUniform4f("colorRect", colorRect.x, colorRect.y, colorRect.width, colorRect.height);
shader.setUniform2f("colorScale", colorScale.x, colorScale.y);
shader.setUniform2f("colorFOV", colorFOV.x, colorFOV.y );
shader.setUniform2f("colorPP", colorPrincipalPoint.x, colorPrincipalPoint.y);
shader.setUniform3f("dK", distortionK.x, distortionK.y, distortionK.z);
shader.setUniform2f("dP", distortionP.x, distortionP.y);
ofMatrix4x4 adjustmentMatrix;
adjustmentMatrix.rotate(adjustRotate.x, 0, 1, 0);
adjustmentMatrix.rotate(adjustRotate.y, 1, 0, 0);
adjustmentMatrix.translate(adjustTranslate.x, adjustTranslate.y, adjustTranslate.z);
shader.setUniformMatrix4f("extrinsics", extrinsics * adjustmentMatrix );
shader.setUniform4f("depthRect", depthRect.x, depthRect.y, depthRect.width, depthRect.height);
shader.setUniform2f("depthPP", depthPrincipalPoint.x, depthPrincipalPoint.y);
shader.setUniform2f("depthFOV", depthFOV.x, depthFOV.y);
shader.setUniform4f("normalRect", normalRect.x, normalRect.y, normalRect.width, normalRect.height);
shader.setUniform4f("faceFeatureRect", faceFeatureRect.x, faceFeatureRect.y, faceFeatureRect.width, faceFeatureRect.height);
shader.setUniform4f("deltaChangeRect", deltaChangeRect.x, deltaChangeRect.y, deltaChangeRect.width, deltaChangeRect.height);
shader.setUniform1i("useFaces", useFaces ? 1 : 0);
shader.setUniform1f("flowPosition", flowPosition);
shader.setUniform1f("farClip", farClip);
shader.setUniform1f("nearClip", nearClip);
shader.setUniform1f("edgeClip", edgeClip);
shader.setUniform1f("minDepth", minDepth);
shader.setUniform1f("maxDepth", maxDepth);
}
开发者ID:CLOUDS-Interactive-Documentary,项目名称:VisualSystemsLibrary,代码行数:45,代码来源:CloudsRGBDVideoPlayer.cpp
示例11: drawFace
void BGNode::drawFace(ofShader & mEyeShader) {
/*
int n = neighbours.size();
ofVec2f toVector(1,0);
if(n > 0)
toVector = (neighbours[0]->position - position).normalize();
ofVec2f perpVec(-toVector.y, toVector.x);
*/
ofSetColor(255);
float offset = .05 * nodeRadius;
float perpOffset = .6 * nodeRadius;
float eyeRadius = .6 * nodeRadius;
ofVec2f toVector = mSurfaceNormal;
ofVec2f perpVec(-toVector.y, toVector.x);
ofVec2f goalPos = position;
if(neighbours.size() > 0)
goalPos = neighbours[0]->position;
float texFactor = .6 * nodeRadius;
for(int i=0; i<2; ++i) {
int factor = i == 0 ? 1 : -1;
ofVec2f pos = position + toVector * offset + factor * perpVec * perpOffset;
ofMesh eyeMesh;
eyeMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for(int j=0; j<4; ++j) {
ofVec2f texPos(j % 2, j / 2);
ofVec2f vPos = pos + (texPos.x - .5) * texFactor * perpVec + (texPos.y - .5) * texFactor * toVector;
eyeMesh.addVertex(ofVec3f(vPos.x, vPos.y, 0));
eyeMesh.addTexCoord(texPos);
}
ofVec2f goalPos = position;
if(neighbours.size() > 0)
goalPos = neighbours[0]->position;
ofVec2f toGoal = goalPos - pos;
float toGoalLength = toGoal.length();
ofVec2f pupilPos = pos;
if(toGoalLength > 0.01)
pupilPos = pos + .25 * eyeRadius / toGoalLength * toGoal;
mEyeShader.begin();
mEyeShader.setUniform2f("uCenter", pos.x, pos.y);
mEyeShader.setUniform2f("uFocusPoint", goalPos.x, goalPos.y);
mEyeShader.setUniform2f("uPupilLoc", pupilPos.x, pupilPos.y);
mEyeShader.setUniform1i("uFlipHorizontally", i > 0);
eyeMesh.draw();
mEyeShader.end();
}
ofMesh mouthMesh;
mouthMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for(int i=0; i<21; ++i) {
float t = i / 20.0;
float x = .6 * (t - .5) * nodeRadius;
float yVar = 2 * abs(t - .5);
float y = (-yVar * yVar * (1 - yVar) * .6 - .3) * nodeRadius;
for(int it=0; it<2; ++it) {
mouthMesh.addVertex(position + y * toVector + x * perpVec);
mouthMesh.addColor(ofColor(0));
y -= 3;
}
}
mouthMesh.draw();
}
示例12: setup
void setup() {
ofEnableDepthTest();
ofDisableArbTex();
img.loadImage("img1.jpg");
env.loadImage("env.jpg");
env1.loadImage("env1.jpg");
shader.load("material.vert","material.frag");
model.loadModel("wolf.dae", true);
}
示例13: draw
void draw() {
ofBackgroundGradient(64, 0);
if(reflect || sreflect)
env.draw(0,0,env.getWidth()/8,env.getHeight()/8);
if(sreflect)
env1.draw(env.getWidth()/8,0,env1.getWidth()/8,env1.getHeight()/8);
ofEnableDepthTest();
cam.begin();
shader.begin();
if(sreflect){
// shader.setUniform3f("CameraPos",cam.getGlobalPosition().x, cam.getGlobalPosition().y, cam.getGlobalPosition().z);
// shader.setUniformMatrix4f("ModelWorld4x4",cam.getGlobalTransformMatrix());
shader.setUniform3f("CameraPos",cam.getPosition().x, cam.getPosition().y, cam.getPosition().z);
shader.setUniformMatrix4f("ModelWorld4x4",cam.getModelViewMatrix());//getLocalTransformMatrix());
shader.setUniformTexture("frontMap", env,1);
shader.setUniformTexture("backMap", env1,2);
}
if(reflect){
shader.setUniformTexture("colorMap",env1,1);
shader.setUniformTexture("envMap", env,2);
}else if(sreflect==false){
shader.setUniformTexture("texture", img, 1);
shader.setUniform1f("time", ofGetElapsedTimef());
}
if(cube)
ofDrawBox(200);
else {
ofTranslate(0,-150,0);
ofRotateX(-90);
ofRotateY(-90);
ofRotateZ(45);
model.drawFaces();
}
shader.end();
cam.end();
ofDisableDepthTest();
ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
}
示例14: draw
void draw() {
ofBackground(25);
fbo.begin();
ofClear(0,0,0,0);
ofEnableDepthTest();
camera.begin();
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
if(dvel) draw_velocity();
if(dden){
draw_density();
}
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glPopMatrix();
if( drawAxis ){ ofDrawAxis(15); }
camera.end();
ofDisableDepthTest();
fbo.end();
shader.begin();
shader.setUniformTexture("tex",fbo.getTextureReference(),0);
shader.setUniform2f("resolution",dw,dh);
shader.setUniform1f("timer",ofGetElapsedTimef());
fbo.draw(0,0);
shader.end();
gui.draw();
}
示例15: setup
void setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);
dw=ofGetScreenWidth();
dh=ofGetScreenHeight();
ofDisableArbTex();
fbo.allocate(dw,dh);
shader.load("shaders/fluid.vert","shaders/fluid.frag");
camera.setFarClip(100000);
camera.setNearClip(.1);
if ( !allocate_data () ){
cout<<"error allocate!"<<endl;
exit();
}
clear_data ();
gui.setup();
gui.setPosition(ofPoint(10,10));
gui.add(size_cube.setup("size box", 100.0f,0.0f,255.0f));
gui.add(dvel.setup("draw velocity", true));
gui.add(dden.setup("draw density", false));
gui.add(TaddSource.setup("add source",false));
gui.add(Bclear.setup("clear source",false));
gui.add(addX.setup("add x",false));
gui.add(addY.setup("add y",false));
gui.add(addZ.setup("add z",false));
gui.add(dt.setup("time delta", 0.9f,0.0f,25.0f));
gui.add(diff.setup("diffuse", 0.0f,0.0f,25.0f));
gui.add(visc.setup("viscosity", 0.0f,0.0f,25.0f));
gui.add(force.setup("add force",30.0f,0.0f,60.0f));
gui.add(source.setup("density", 200.0f,0.0f,600.0f));
gui.add(source_alpha.setup("alpha",0.05,0.0,1.0));
gui.add(drawAbstacle.setup("draw abstacle",false));
gui.add(drawAxis.setup("draw Axis",true));
gui.add(sourcePosX.setup("source posX", 0,-10,SIZE));
gui.add(sourcePosY.setup("source posY", 0,-10,SIZE));
gui.add(sourcePosZ.setup("source posZ", 0,-10,SIZE));
}