void draw(void) { unsigned char pixels[SCREEN_WIDTH * 60 * 3]; unsigned int prog = shaders[current_shader].prog; iGlobalTime = get_msec() / 1000.0f; glDisable(GL_BLEND); switch(shaders[current_shader].type) { case GL_CODE: switch(prog) { case 1: draw_osaa(); break; } break; case REAL_SHADER: set_shader(prog); set_uniform1f(prog, "iGlobalTime", iGlobalTime); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(-1, -1); glTexCoord2f(1, 0); glVertex2f(1, -1); glTexCoord2f(1, 1); glVertex2f(1, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1); glEnd(); break; } set_shader(0); glEnable(GL_BLEND); glColor4f(0.0f, 0.0f, 0.0f, transition_offset_x / (float)SCREEN_WIDTH); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(-1, -1); glTexCoord2f(1, 0); glVertex2f(1, -1); glTexCoord2f(1, 1); glVertex2f(1, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1); glEnd(); glutSwapBuffers(); memset(pixels, 0, SCREEN_WIDTH*60*3); glReadPixels(0, 0, SCREEN_WIDTH, 60, GL_RGB, GL_UNSIGNED_BYTE, pixels); send_packet(pixels, sizeof(pixels)); }
PerspectiveObject::PerspectiveObject(int x, int y, int type_id) : FrameObject(x, y, type_id) { collision = new InstanceBox(this); set_shader(Render::PERSPECTIVE); }
ProjectCubemapToGeometryPass::ProjectCubemapToGeometryPass(std::string flyvr_basepath, osg::TextureCubeMap* texture, osg::Uniform::Callback* observer_position_cb, DisplaySurfaceGeometry* geometry_parameters, unsigned int tex_width, unsigned int tex_height) : _geometry_parameters( geometry_parameters), _tex_width(tex_width), _tex_height(tex_height), _observer_position_callback(observer_position_cb) { flyvr_assert( texture!=NULL ); flyvr_assert( geometry_parameters!=NULL ); set_flyvr_base_path(flyvr_basepath); set_plugin_path(flyvr_basepath,false); _top = new osg::Group; _top->addDescription("ProjectCubemapToGeometryPass top node"); _in_texture_cubemap = texture; create_output_texture(); _camera = new osg::Camera; setup_camera(); _geometry = create_textured_geometry(); _camera->addChild( _geometry.get() ); _top->addChild( _camera ); set_shader( "ProjectCubemapToGeometryPass.vert", "ProjectCubemapToGeometryPass.frag"); }
void ProjectCubemapToGeometryPass::replace_display_surface_geometry( DisplaySurfaceGeometry* geometry_parameters ) { freemoovr_assert( geometry_parameters!=NULL ); // Tear down usage of previous display surface geometry. if (_state_set.valid()) { if (_observerPositionUniform != NULL) { _state_set->removeUniform(_observerPositionUniform); } } if (_private_geometry.valid()) { _camera->removeChild( _private_geometry.get() ); } if (_inner_geode.valid()) { _public_geometry->removeChild(_inner_geode.get()); } // Use new display surface geometry. _geometry_parameters = geometry_parameters; _private_geometry = create_textured_geometry(); _camera->addChild( _private_geometry.get() ); _state_set = _private_geometry->getOrCreateStateSet(); _state_set->addUniform(_observerPositionUniform); _program = set_shader( _state_set, "ProjectCubemapToGeometryPass.vert", "ProjectCubemapToGeometryPass.frag"); _inner_geode = _create_textured_geometry_inner_geode(); _public_geometry->addChild(_inner_geode.get()); }
void idle_func(void) { /* Check if we are going faster than the FRAME_TIME */ long current_time = get_msec(); long delta = next_frame_time - current_time; if(delta > 0 && delta < FRAME_TIME) { usleep(delta * 1000l); next_frame_time += FRAME_TIME; } else { /* Seems we are too late or we just started. Just sync. */ next_frame_time = current_time + FRAME_TIME; } glutPostRedisplay(); /* Check if we should go to the next shader or if we are transitioning */ if(transition_offset_x) { transition_offset_x += transition_direction; if(transition_offset_x >= SCREEN_WIDTH) { /* Old shader is now shifted out. Switch shader and shift it in */ current_shader = (current_shader+1) % shader_count; set_shader(shaders[current_shader].prog); shader_activated_time = current_time; transition_offset_x = SCREEN_WIDTH; transition_direction = -1; } else if(transition_offset_x <= 0) { transition_direction = 0; } } else if(shaders[current_shader].time + shader_activated_time < current_time) { transition_offset_x = 1; transition_direction = 1; } }
CameraImageToDisplayImagePass::CameraImageToDisplayImagePass(Poco::Path shader_dir, osg::ref_ptr<osg::Texture> live_camera_texture, std::string p2c_filename, bool UseHDR) : _live_camera_texture(live_camera_texture), _UseHDR(UseHDR) { double scale_width = live_camera_texture->getTextureWidth(); double scale_height = live_camera_texture->getTextureHeight(); osg::ref_ptr<osg::Image> image = load_exr( p2c_filename, _display_width, _display_height, scale_width, scale_height ); _p2c_texture = new osg::Texture2D; _p2c_texture->setTextureSize( _display_width, _display_height); _p2c_texture->setInternalFormat(GL_RGB32F); _p2c_texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); _p2c_texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); _p2c_texture->setImage(image); create_output_texture(); _camera = new osg::Camera; setup_camera(); osg::ref_ptr<osg::Group> g = create_input_geometry(); _camera->addChild( g.get() ); _top = new osg::Group; _top->addDescription("CameraImageToDisplayImagePass top node"); _top->addChild( _camera ); set_shader( shader_dir.absolute().append("CameraImageToDisplayImagePass.vert").toString(), shader_dir.absolute().append("CameraImageToDisplayImagePass.frag").toString() ); }
bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) { if (p_name==SceneStringNames::get_singleton()->shader_shader) { set_shader(p_value); return true; } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { set_shading_mode(ShadingMode(p_value.operator int())); return true; } else { if (shader.is_valid()) { StringName pr = shader->remap_param(p_name); if (!pr) { String n = p_name; if (n.find("param/")==0) { //backwards compatibility pr = n.substr(6,n.length()); } } if (pr) { VisualServer::get_singleton()->canvas_item_material_set_shader_param(material,pr,p_value); return true; } } } return false; }
int main(int argc, char **argv) { if(init_socket() < 0) { perror("failed to init socket"); return -1; } glutInitWindowSize(64, 60); /* initialize glut */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("Raadhus Shader"); glutDisplayFunc(draw); glutIdleFunc(idle_func); glutKeyboardFunc(key_handler); glutMotionFunc(mouse_handler); if(read_shaders("shaders.conf")) { return EXIT_FAILURE; } set_shader(shaders[current_shader].prog); shader_activated_time = get_msec(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); init_osaa(); glutMainLoop(); return 0; }
//Init for States int state_init () { prev_time = al_get_time (); set_shader (identity_shader ()); gui_init (); return handlers[state].proc_init (); }
PerspectiveObject::PerspectiveObject(int x, int y, int type_id) : FrameObject(x, y, type_id) { collision = new InstanceBox(this); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); set_shader(perspective_shader); }
void CanvasGradient::initRadial(const Point& center, double radius, const Vector<SkColor>& colors, const Vector<float>& color_stops, SkShader::TileMode tile_mode) { ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); SkShader* shader = SkGradientShader::CreateRadial( center.sk_point, radius, colors.data(), color_stops.data(), colors.size(), tile_mode); set_shader(adoptRef(shader)); }
void CanvasGradient::initLinear(const Vector<Point>& end_points, const Vector<SkColor>& colors, const Vector<float>& color_stops, SkShader::TileMode tile_mode) { ASSERT(end_points.size() == 2); ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); SkPoint sk_end_points[2]; for (int i = 0; i < 2; ++i) sk_end_points[i] = end_points[i].sk_point; SkShader* shader = SkGradientShader::CreateLinear( sk_end_points, colors.data(), color_stops.data(), colors.size(), tile_mode); set_shader(adoptRef(shader)); }
void CanvasGradient::initRadial(const Point& center, double radius, const std::vector<CanvasColor>& colors, const std::vector<float>& color_stops, SkShader::TileMode tile_mode) { ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); std::vector<SkColor> sk_colors; sk_colors.reserve(colors.size()); for (const CanvasColor& color : colors) sk_colors.push_back(color); set_shader(SkGradientShader::MakeRadial( center.sk_point, radius, sk_colors.data(), color_stops.data(), sk_colors.size(), tile_mode)); }
void ImageShader::initWithImage(CanvasImage* image, SkShader::TileMode tmx, SkShader::TileMode tmy, const Float64List& matrix4, ExceptionState& es) { ASSERT(image != NULL); SkMatrix sk_matrix = toSkMatrix(matrix4, es); if (es.had_exception()) return; SkBitmap bitmap; image->image()->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); set_shader(adoptRef(SkShader::CreateBitmapShader(bitmap, tmx, tmy, &sk_matrix))); }
bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) { if (p_name==SceneStringNames::get_singleton()->shader_shader) { set_shader(p_value); return true; } else { String n = p_name; if (n.begins_with("param/")) { VisualServer::get_singleton()->material_set_param(material,String(n.ptr()+6),p_value); return true; } } return false; }
ProjectCubemapToGeometryPass::ProjectCubemapToGeometryPass(std::string freemoovr_basepath, osg::TextureCubeMap* texture, osg::Uniform::Callback* observer_position_cb, DisplaySurfaceGeometry* geometry_parameters, unsigned int tex_width, unsigned int tex_height) : _geometry_parameters( geometry_parameters), _tex_width(tex_width), _tex_height(tex_height), _observer_position_callback(observer_position_cb) { freemoovr_assert( texture!=NULL ); freemoovr_assert( geometry_parameters!=NULL ); set_freemoovr_base_path(freemoovr_basepath); _top = new osg::Group; _top->addDescription("ProjectCubemapToGeometryPass top node"); _in_texture_cubemap = texture; _observerPositionUniform = new osg::Uniform( "ObserverPosition", osg::Vec3(0.22f, 0.22f, 0.9f) ); if (_observer_position_callback!=NULL) { _observerPositionUniform->setUpdateCallback(_observer_position_callback); } create_output_texture(); _camera = new osg::Camera; setup_camera(); _private_geometry = create_textured_geometry(); _camera->addChild( _private_geometry.get() ); _top->addChild( _camera ); _state_set = _private_geometry->getOrCreateStateSet(); _state_set->addUniform(_observerPositionUniform); _program = set_shader( _state_set, "ProjectCubemapToGeometryPass.vert", "ProjectCubemapToGeometryPass.frag"); _public_geometry = new osg::Group; _public_geometry->addDescription("ProjectCubemapToGeometryPass output textured geometry top node"); _inner_geode = _create_textured_geometry_inner_geode(); _public_geometry->addChild(_inner_geode.get()); }
void CanvasGradient::initLinear(const std::vector<Point>& end_points, const std::vector<CanvasColor>& colors, const std::vector<float>& color_stops, SkShader::TileMode tile_mode) { ASSERT(end_points.size() == 2); ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); SkPoint sk_end_points[2]; for (int i = 0; i < 2; ++i) sk_end_points[i] = end_points[i].sk_point; std::vector<SkColor> sk_colors; sk_colors.reserve(colors.size()); for (const CanvasColor& color : colors) sk_colors.push_back(color); set_shader(SkGradientShader::MakeLinear( sk_end_points, sk_colors.data(), color_stops.data(), sk_colors.size(), tile_mode)); }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image; #define MAX_SPRITES 100 int numSprites; float positions[2*MAX_SPRITES]; float colors[4*4*MAX_SPRITES]; float expanded_colors[4*MAX_SPRITES]; float src_rects[4*MAX_SPRITES]; Uint32 v, f, p; GPU_ShaderBlock block; Uint8 shader_index; int i; SDL_Color color = {255, 255, 255, 255}; SDL_Color red = {255, 0, 0, 255}; SDL_Color green = {0, 255, 0, 255}; SDL_Color blue = {0, 0, 255, 255}; GPU_Rect src_rect; int mx, my; Uint32 mouse_state; image = GPU_LoadImage("data/happy_50x50.bmp"); if(image == NULL) return -1; numSprites = 0; color_attr.format = GPU_MakeAttributeFormat(4, GPU_TYPE_FLOAT, 0, 4*sizeof(float), 0); color_attr.format.is_per_sprite = 0; color_attr.values = colors; block = load_shaders(&v, &f, &p); shader_index = 1; set_shader(p, &block); startTime = SDL_GetTicks(); frameCount = 0; src_rect.x = 0; src_rect.y = 0; src_rect.w = image->w; src_rect.h = image->h; add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect); done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_MOUSEBUTTONDOWN) { if(event.button.x <= 150 && event.button.y <= 150) { if(event.button.button == SDL_BUTTON_LEFT) { float dx = event.button.x/3 - src_rect.x; float dy = event.button.y/3 - src_rect.y; src_rect.x = event.button.x/3; src_rect.y = event.button.y/3; src_rect.w -= dx; src_rect.h -= dy; } else if(event.button.button == SDL_BUTTON_RIGHT) { src_rect.w = event.button.x/3 - src_rect.x; src_rect.h = event.button.y/3 - src_rect.y; } } } else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) { if(numSprites < MAX_SPRITES) add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect); } else if(event.key.keysym.sym == SDLK_MINUS) { if(numSprites > 0) numSprites--; } else if(event.key.keysym.sym == SDLK_SPACE) { shader_index++; shader_index %= 2; if(shader_index == 0) set_shader(0, NULL); else if(shader_index == 1) set_shader(p, &block); } else if(event.key.keysym.sym == SDLK_RETURN) { use_color_expansion = !use_color_expansion; if(use_color_expansion) { GPU_LogError("Using attribute expansion.\n"); color_attr.format.is_per_sprite = 1; color_attr.values = expanded_colors; } else { GPU_LogError("Using per-vertex attributes.\n"); color_attr.format.is_per_sprite = 0; color_attr.values = colors; } } } } mouse_state = SDL_GetMouseState(&mx, &my); if(mouse_state & (SDL_BUTTON_LMASK | SDL_BUTTON_RMASK)) { if(mx <= 150 && my <= 150) { if(mouse_state & SDL_BUTTON_LMASK) { float dx = mx/3 - src_rect.x; float dy = my/3 - src_rect.y; src_rect.x = mx/3; src_rect.y = my/3; src_rect.w -= dx; src_rect.h -= dy; } else if(mouse_state & SDL_BUTTON_RMASK) { src_rect.w = mx/3 - src_rect.x; src_rect.h = my/3 - src_rect.y; } } } GPU_SetUniformf(timeloc, SDL_GetTicks()/1000.0f); GPU_Clear(screen); if(use_color_expansion) GPU_SetAttributeSource(numSprites, color_attr); else GPU_SetAttributeSource(4*numSprites, color_attr); for(i = 0; i < numSprites; i++) { GPU_Rect r = {src_rects[4*i], src_rects[4*i+1], src_rects[4*i+2], src_rects[4*i+3]}; GPU_Blit(image, &r, screen, positions[2*i], positions[2*i+1]); } //GPU_BlitBatchSeparate(image, screen, numSprites, positions, src_rects, expanded_colors, 0); set_shader(0, NULL); GPU_BlitScale(image, NULL, screen, 75, 75, 3.0f, 3.0f); GPU_Rectangle(screen, 3*src_rect.x, 3*src_rect.y, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), red); GPU_CircleFilled(screen, 3*src_rect.x, 3*src_rect.y, 4, blue); GPU_CircleFilled(screen, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), 4, green); if(shader_index == 1) set_shader(p, &block); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); free_shaders(v, f, p); } GPU_Quit(); return 0; }
void refresh() { if(lost && !recover()) return; RECT rd, rs; //dest, source rectangles GetClientRect(settings.handle, &rd); SetRect(&rs, 0, 0, settings.width, settings.height); //if output size changed, driver must be re-initialized. //failure to do so causes scaling issues on some video drivers. if(state.width != rd.right || state.height != rd.bottom) { init(); set_shader(shader_source_markup); return; } if(caps.shader && effect) { device->BeginScene(); set_vertex(0, 0, settings.width, settings.height, iwidth, iheight, 0, 0, rd.right, rd.bottom); D3DXVECTOR4 rubyTextureSize; rubyTextureSize.x = iwidth; rubyTextureSize.y = iheight; rubyTextureSize.z = 1.0 / iheight; rubyTextureSize.w = 1.0 / iwidth; effect->SetVector("rubyTextureSize", &rubyTextureSize); D3DXVECTOR4 rubyInputSize; rubyInputSize.x = settings.width; rubyInputSize.y = settings.height; rubyInputSize.z = 1.0 / settings.height; rubyInputSize.w = 1.0 / settings.width; effect->SetVector("rubyInputSize", &rubyInputSize); D3DXVECTOR4 rubyOutputSize; rubyOutputSize.x = rd.right; rubyOutputSize.y = rd.bottom; rubyOutputSize.z = 1.0 / rd.bottom; rubyOutputSize.w = 1.0 / rd.right; effect->SetVector("rubyOutputSize", &rubyOutputSize); UINT passes; effect->Begin(&passes, 0); effect->SetTexture("rubyTexture", texture); device->SetTexture(0, texture); for(unsigned pass = 0; pass < passes; pass++) { effect->BeginPass(pass); device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); effect->EndPass(); } effect->End(); device->EndScene(); } else { device->BeginScene(); set_vertex(0, 0, settings.width, settings.height, iwidth, iheight, 0, 0, rd.right, rd.bottom); device->SetTexture(0, texture); device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); device->EndScene(); } if(settings.synchronize) { D3DRASTER_STATUS status; //wait for a previous vblank to finish, if necessary while(true) { device->GetRasterStatus(0, &status); if(status.InVBlank == false) break; } //wait for next vblank to begin while(true) { device->GetRasterStatus(0, &status); if(status.InVBlank == true) break; } } if(device->Present(0, 0, 0, 0) == D3DERR_DEVICELOST) lost = true; }
WaterQuadTree::WaterQuadTree(const glm::dmat4& rotation, const glm::dmat4& translation, double extents, double radii, std::shared_ptr<Shader> shader) : Drawable(), _translation(translation), _rotation(rotation), _extents(extents), _radii(radii) { set_shader(shader); create_patch(); }
void VertexShader::set() { check_render( device->SetVertexDeclaration(vertex_decl) ); set_shader(); }