├── .gitattributes ├── .gitignore ├── .travis.yml ├── README.md ├── SConstruct ├── examples └── Mesh.cpp ├── fonts ├── Consolas.ttf ├── Enterprise.ttf ├── Ethnocentric.ttf ├── Impact.ttf ├── Neuropol.ttf ├── NeuropolX.ttf ├── Russel.ttf └── airstrikeacad.ttf ├── include └── sfr │ ├── AlphaRenderer.hpp │ ├── AssetLoader.hpp │ ├── AssetTable.hpp │ ├── AttributeBuffer.hpp │ ├── BillboardRenderer.hpp │ ├── Billboards.hpp │ ├── BoundsRenderer.hpp │ ├── Box.hpp │ ├── Camera.hpp │ ├── Color.hpp │ ├── Common.hpp │ ├── Cubemap.hpp │ ├── DecalRenderer.hpp │ ├── Decals.hpp │ ├── DeferredRenderer.hpp │ ├── DepthRenderTarget.hpp │ ├── FlatRenderer.hpp │ ├── Font.hpp │ ├── FontLoader.hpp │ ├── FrameBuffer.hpp │ ├── Frustum.hpp │ ├── HemiLight.hpp │ ├── IndexBuffer.hpp │ ├── Instances.hpp │ ├── Interface.hpp │ ├── Iterator.hpp │ ├── Light.hpp │ ├── LightRenderer.hpp │ ├── Material.hpp │ ├── Matrix.hpp │ ├── Mesh.hpp │ ├── Model.hpp │ ├── ModelRenderer.hpp │ ├── Node.hpp │ ├── NullFunctor.hpp │ ├── ParticleRenderer.hpp │ ├── Particles.hpp │ ├── PointLight.hpp │ ├── Program.hpp │ ├── ProgramLoader.hpp │ ├── Ptr.hpp │ ├── Quad.hpp │ ├── QuadRenderer.hpp │ ├── Quaternion.hpp │ ├── RenderTarget.hpp │ ├── Renderer.hpp │ ├── ResourceException.hpp │ ├── Ribbon.hpp │ ├── RibbonRenderer.hpp │ ├── Scene.hpp │ ├── Shader.hpp │ ├── ShadowRenderer.hpp │ ├── SkyboxRenderer.hpp │ ├── SpotLight.hpp │ ├── StreamDrawBuffer.hpp │ ├── Text.hpp │ ├── TextRenderer.hpp │ ├── Texture.hpp │ ├── TextureLoader.hpp │ ├── Transform.hpp │ ├── TransformUpdater.hpp │ ├── TransparencyRenderer.hpp │ ├── Ui.hpp │ ├── UiRenderer.hpp │ ├── Vector.hpp │ ├── WavefrontLoader.hpp │ └── sfr.hpp ├── install-sfml.sh ├── meshes ├── Blade.mtl ├── Blade.obj ├── Insurrector.mtl ├── Insurrector.obj ├── Lexus.blend ├── Lexus.mtl ├── Lexus.obj ├── LightShapes.blend ├── LightShapes.mtl ├── LightShapes.obj ├── Outrider.blend ├── Outrider.mtl ├── Outrider.obj ├── Plane.blend ├── Plane.mtl ├── Plane.obj ├── Quad.blend ├── Quad.mtl ├── Quad.obj ├── Shield.mtl ├── Shield.obj ├── SmoothSphere.blend ├── SmoothSphere.mtl ├── SmoothSphere.obj └── UnitCube.mtl ├── pkgboot.py ├── shaders ├── Billboard.frag ├── Billboard.geom ├── Billboard.vert ├── Camera.inc.glsl ├── Decals.frag ├── Decals.vert ├── Flat.frag ├── Flat.vert ├── HemiLight.frag ├── HemiLight.vert ├── Light.frag ├── Light.vert ├── Mesh.vert ├── Model.frag ├── Model.vert ├── Particles.frag ├── Particles.geom ├── Particles.vert ├── PointLight.frag ├── PointLight.vert ├── Quad.frag ├── Quad.vert ├── Ribbon.frag ├── Ribbon.vert ├── Shield.frag ├── Shield.vert ├── Skybox.frag ├── Skybox.vert ├── SpotLight.frag ├── SpotLight.vert ├── Text.frag ├── Text.vert ├── Texture.frag ├── Texture.vert ├── Transparency.frag └── Transparency.vert ├── src ├── AlphaRenderer.cpp ├── AssetLoader.cpp ├── AssetTable.cpp ├── AttributeBuffer.cpp ├── BillboardRenderer.cpp ├── Billboards.cpp ├── BoundsRenderer.cpp ├── Box.cpp ├── Camera.cpp ├── Color.cpp ├── Common.cpp ├── Cubemap.cpp ├── DecalRenderer.cpp ├── Decals.cpp ├── DeferredRenderer.cpp ├── DepthRenderTarget.cpp ├── FlatRenderer.cpp ├── Font.cpp ├── FontLoader.cpp ├── FrameBuffer.cpp ├── HemiLight.cpp ├── IndexBuffer.cpp ├── Light.cpp ├── LightRenderer.cpp ├── Material.cpp ├── Matrix.cpp ├── Mesh.cpp ├── Model.cpp ├── ModelRenderer.cpp ├── NullFunctor.cpp ├── ParticleRenderer.cpp ├── Particles.cpp ├── PointLight.cpp ├── Program.cpp ├── ProgramLoader.cpp ├── Quad.cpp ├── QuadRenderer.cpp ├── Quaternion.cpp ├── RenderTarget.cpp ├── Renderer.cpp ├── ResourceException.cpp ├── Ribbon.cpp ├── RibbonRenderer.cpp ├── Scene.cpp ├── Shader.cpp ├── ShadowRenderer.cpp ├── SkyboxRenderer.cpp ├── SpotLight.cpp ├── StreamDrawBuffer.cpp ├── Text.cpp ├── TextRenderer.cpp ├── Texture.cpp ├── TextureLoader.cpp ├── Transform.cpp ├── TransformUpdater.cpp ├── TransparencyRenderer.cpp ├── Ui.cpp ├── UiRenderer.cpp ├── Vector.cpp └── WavefrontLoader.cpp ├── test └── Main.cpp └── textures ├── Blue.png ├── BurstGold.png ├── Checkerboard.png ├── Grill.jpg ├── IncandescentBlue.png ├── LOGO.jpg ├── MetalDiffuse.png ├── MetalNormal.png ├── MetalSpecular.png ├── Nebula.png ├── PARTS.jpg ├── SandDiffuse.png ├── SandNormal.png ├── TIRE.jpg └── White.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/Debug 2 | build/Release 3 | build 4 | lib 5 | bin 6 | main 7 | src/Assets.cpp 8 | include/sfr/Assets.hpp 9 | ipch 10 | *.sdf 11 | *.suo 12 | *.pdb 13 | *.idb 14 | *.vcxproj.filters 15 | *.vcxproj.user 16 | *.orig 17 | *~ 18 | *.o 19 | *.swp 20 | 21 | *.pch 22 | *.gch 23 | *.blend1 24 | *.blend2 25 | *.dblite 26 | *.pyc 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | script: scons 3 | compiler: clang 4 | addons: 5 | apt: 6 | packages: 7 | - cmake 8 | - libgl1-mesa-dev 9 | - libglew-dev 10 | - libfreetype6-dev 11 | - libjpeg-dev 12 | - libopenal-dev 13 | - libudev-dev 14 | - libsndfile1-dev 15 | before_install: 16 | - bash install-sfml.sh 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple, Fast Renderer 2 | ===================== 3 | 4 | ![Build Status](https://travis-ci.org/mfichman/sfr.svg?branch=master) 5 | 6 | Simple, Fast Renderer (SFR) is an OpenGL 3.2+ rendering library. The aim of 7 | the library is to be as simple as possible: you construct the scene graph, and 8 | then run custom "functors" over the scene graph to render. Functors make the 9 | rendering algorithm 100% hackable. SFR uses only OpenGL 3.2+ features. It 10 | avoids deprecated fixed-pipeline functions in favor of a shader-driven 11 | approach. 12 | 13 | SFR features: 14 | * Deferred rendering 15 | * Shadow mapping (directional & spotlight) 16 | * Soft particles 17 | * Screen-space decals 18 | * Normal, emissive, and specular maps 19 | * Point, spot & directional Phong lighting 20 | * Transparency 21 | * Signed distance field font rendering 22 | * OBJ file loader 23 | 24 | Dependencies 25 | ------------ 26 | 27 | Depends on [GLEW](http://glew.sourceforge.net/) for OpenGL 3.2+ context 28 | loading, [Freetype](http://www.freetype.org/freetype2/) for font loading, and 29 | [SFML](http://www.sfml-dev.org/download.php) to run the sample application and 30 | load textures. 31 | 32 | 33 | Building 34 | -------- 35 | 36 | SFR uses scons for building, which requires Python. Install Python, then: 37 | 38 | easy_install scons 39 | git clone git@github.com:mfichman/simple-fast-renderer.git 40 | cd simple-fast-renderer 41 | scons 42 | 43 | 44 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | 2 | import pkgboot 3 | import os 4 | 5 | class Sfr(pkgboot.Package): 6 | defines = {} 7 | includes = [ 8 | '/usr/local/include', 9 | '/usr/local/include/freetype2', 10 | '/usr/include/freetype2', 11 | '/usr/include/freetype', 12 | os.path.join(os.environ.get('LOCALAPPDATA', ''), 'WinBrew\\include\\freetype'), 13 | ] 14 | 15 | lib_path = [ 16 | '/usr/local/lib', 17 | ] 18 | 19 | libs = [ 20 | pkgboot.Lib('opengl32', 'win32'), 21 | pkgboot.Lib('gdi32', 'win32'), 22 | pkgboot.Lib('user32', 'win32'), 23 | pkgboot.Lib('advapi32', 'win32'), 24 | pkgboot.Lib('winmm', 'win32'), 25 | pkgboot.Lib('glew', 'win32'), 26 | 'sfml-window', 27 | 'sfml-graphics', 28 | 'sfml-system', 29 | 'sfml-window', 30 | 'freetype', 31 | 'jpeg', 32 | ] 33 | 34 | frameworks = [ 35 | 'OpenGL', 36 | 'Cocoa', 37 | 'Carbon', 38 | 'IoKit', 39 | ] 40 | 41 | assets = [ 42 | 'shaders/*.glsl', 43 | 'shaders/*.vert', 44 | 'shaders/*.frag', 45 | 'shaders/*.geom', 46 | 'meshes/LightShapes.mtl', 47 | 'meshes/LightShapes.obj', 48 | 'meshes/Quad.mtl', 49 | 'meshes/Quad.obj', 50 | 'textures/Blue.png', 51 | 'textures/White.png', 52 | ] 53 | 54 | major_version = '0' 55 | minor_version = '0' 56 | patch = '0' 57 | 58 | 59 | Sfr() 60 | -------------------------------------------------------------------------------- /fonts/Consolas.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Consolas.ttf -------------------------------------------------------------------------------- /fonts/Enterprise.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Enterprise.ttf -------------------------------------------------------------------------------- /fonts/Ethnocentric.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Ethnocentric.ttf -------------------------------------------------------------------------------- /fonts/Impact.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Impact.ttf -------------------------------------------------------------------------------- /fonts/Neuropol.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Neuropol.ttf -------------------------------------------------------------------------------- /fonts/NeuropolX.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/NeuropolX.ttf -------------------------------------------------------------------------------- /fonts/Russel.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/Russel.ttf -------------------------------------------------------------------------------- /fonts/airstrikeacad.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/fonts/airstrikeacad.ttf -------------------------------------------------------------------------------- /include/sfr/AlphaRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders alpha-blend effects: transparent meshes, particles, etc. */ 15 | class AlphaRenderer : public Renderer { 16 | public: 17 | AlphaRenderer(Ptr manager); 18 | void operator()(Ptr model); 19 | void operator()(Ptr particles); 20 | void operator()(Ptr ribbon); 21 | void operator()(Ptr billboards); 22 | void operator()(Ptr quad); 23 | void operator()(Ptr text); 24 | 25 | using Renderer::operator(); 26 | 27 | private: 28 | void onState(); 29 | void rendererIs(Ptr renderer); 30 | 31 | Ptr transparencyRenderer_; 32 | Ptr particleRenderer_; 33 | Ptr billboardRenderer_; 34 | Ptr ribbonRenderer_; 35 | Ptr quadRenderer_; 36 | Ptr textRenderer_; 37 | Ptr renderer_; 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /include/sfr/AssetLoader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | 10 | #include "sfr/Common.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Convenience object that sets up all built-in asset loaders */ 15 | class AssetLoader : public Interface { 16 | public: 17 | AssetLoader(Ptr notifier); 18 | 19 | private: 20 | Ptr fontLoader_; 21 | Ptr meshLoader_; 22 | Ptr programLoader_; 23 | Ptr textureLoader_; 24 | }; 25 | 26 | 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /include/sfr/AttributeBuffer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Contains one attribute array (e.g., normals, indices, etc.) for a mesh. */ 14 | class AttributeBuffer : public Interface { 15 | public: 16 | enum Status { SYNCED, DIRTY }; 17 | 18 | AttributeBuffer(std::string const& name, GLenum usage); 19 | ~AttributeBuffer(); 20 | 21 | std::string const& name() const; 22 | GLuint id() const; 23 | virtual GLuint elementCount() const=0; 24 | virtual GLuint elementSize() const=0; 25 | Status status() const; 26 | 27 | void statusIs(Status status); 28 | 29 | private: 30 | virtual const void* data() const=0; 31 | void syncHardwareBuffers(); 32 | 33 | std::string name_; 34 | GLuint id_; 35 | GLenum usage_; 36 | Status status_; 37 | 38 | }; 39 | 40 | template 41 | class MutableAttributeBuffer : public AttributeBuffer { 42 | public: 43 | MutableAttributeBuffer(std::string const& name, GLenum usage) : 44 | AttributeBuffer(name, usage) { 45 | } 46 | 47 | GLuint elementCount() const { return GLuint(element_.size()); } 48 | GLuint elementSize() const { return sizeof(T); } 49 | T const& element(GLuint index) { return element_[index]; } 50 | 51 | void elementCountIs(GLuint count) { 52 | if (count == element_.size()) { 53 | return; 54 | } 55 | element_.resize(count); 56 | statusIs(DIRTY); 57 | } 58 | 59 | void elementIs(GLuint index, T element) { 60 | if (index >= elementCount()) { 61 | elementCountIs(index +1); 62 | } 63 | element_[index] = element; 64 | statusIs(DIRTY); 65 | } 66 | 67 | void elementEnq(T element) { 68 | element_.push_back(element); 69 | statusIs(DIRTY); 70 | } 71 | 72 | void elementDelAll() { 73 | element_.clear(); 74 | statusIs(DIRTY); 75 | } 76 | 77 | private: 78 | const void* data() const { 79 | return element_.empty() ? 0 : &element_[0]; 80 | } 81 | 82 | std::vector element_; 83 | }; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /include/sfr/BillboardRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders transparent billboards with an alpha-blend technique. */ 15 | class BillboardRenderer : public Renderer { 16 | public: 17 | BillboardRenderer(Ptr manager); 18 | void operator()(Ptr billboards); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | Ptr program_; 25 | Ptr buffer_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/Billboards.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Color.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Program.hpp" 13 | 14 | namespace sfr { 15 | 16 | class Billboard { 17 | public: 18 | GLvec3 position; // Position of center of billboard 19 | GLvec3 velocity; // For bookkeeping only 20 | GLvec3 forward; // Forward vector for billboard (normal) 21 | GLvec3 right; // Right vector for billboard 22 | GLvec4 color; // Color 23 | GLfloat width; // Width of billboard 24 | GLfloat height; // Height of billboard 25 | }; 26 | 27 | class Billboards : public Node { 28 | public: 29 | enum Attribute { POSITION, FORWARD, RIGHT, COLOR, WIDTH, HEIGHT }; 30 | enum ClearMode { MANUAL, AUTO }; 31 | enum BlendMode { ALPHA, ADDITIVE }; 32 | 33 | Billboards(); 34 | Ptr texture() const { return texture_; } 35 | Billboard const* buffer() const { return &buffer_.front(); } 36 | Billboard const& billboard(GLuint index) const; 37 | GLuint billboardCount() const { return GLuint(buffer_.size()); } 38 | sfr::Color const& tint() const { return tint_; } 39 | ClearMode clearMode() const { return clearMode_; } 40 | BlendMode blendMode() const { return blendMode_; } 41 | bool isVisible() const { return !!texture_&&buffer_.size(); } 42 | 43 | void billboardEnq(Billboard const& billboard); 44 | void billboardIs(GLuint index, Billboard const& billboard); 45 | void billboardDelAll(); 46 | void textureIs(Ptr texture); 47 | void tintIs(sfr::Color tint); 48 | void clearModeIs(ClearMode clearMode); 49 | void blendModeIs(BlendMode mode); 50 | 51 | private: 52 | void operator()(Ptr functor); 53 | 54 | std::vector buffer_; 55 | Ptr texture_; 56 | sfr::Color tint_; 57 | ClearMode clearMode_; 58 | BlendMode blendMode_; 59 | }; 60 | 61 | class BillboardProgram : public Program { 62 | public: 63 | BillboardProgram(std::string const& name) : Program(name) {} 64 | 65 | GLint transform() const { return transform_; } 66 | GLint texture() const { return texture_; } 67 | GLint tint() const { return tint_; } 68 | 69 | private: 70 | void onLink(); 71 | GLint texture_ = -1; 72 | GLint transform_ = -1; 73 | GLint tint_ = -1; 74 | }; 75 | 76 | } 77 | -------------------------------------------------------------------------------- /include/sfr/BoundsRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Shadow map renderer. */ 15 | class BoundsRenderer : public Renderer { 16 | public: 17 | BoundsRenderer(Ptr manager); 18 | void operator()(Ptr object); 19 | void operator()(Ptr mesh); 20 | void operator()(Ptr light); 21 | 22 | using Renderer::operator(); 23 | 24 | private: 25 | void onState(); 26 | Ptr program_; 27 | Ptr unitCube_; 28 | Ptr unitCone_; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /include/sfr/Box.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Vector.hpp" 11 | 12 | namespace sfr { 13 | 14 | class Box { 15 | public: 16 | Box() {}; 17 | Box(Frustum const& frustum); 18 | 19 | void pointIs(Vector const& point); 20 | 21 | Vector max; // Maximum x/y/z coordinate 22 | Vector min; // Minimum x/y/z coordinate 23 | 24 | Vector center() const; 25 | }; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/sfr/Camera.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Frustum.hpp" 12 | #include "sfr/Matrix.hpp" 13 | 14 | namespace sfr { 15 | 16 | 17 | /* Contains parameters for the view camera. */ 18 | class Camera : public Node { 19 | public: 20 | enum State { ACTIVE, INACTIVE }; 21 | enum Status { SYNCED, DIRTY }; 22 | enum Type { PERSPECTIVE, ORTHOGRAPHIC }; 23 | 24 | Camera(); 25 | ~Camera(); 26 | 27 | Frustum viewFrustum(Scalar near, Scalar far) const; 28 | Frustum viewFrustum() const; 29 | Matrix const& projectionMatrix() const; 30 | Matrix const& projectionMatrixInv() const; 31 | Matrix const& viewMatrix() const; 32 | Matrix const& viewMatrixInv() const; 33 | Matrix const& viewProjectionMatrix() const; 34 | Matrix const& viewProjectionMatrixInv() const; 35 | Scalar far() const; 36 | Scalar near() const; 37 | Scalar left() const; 38 | Scalar right() const; 39 | Scalar top() const; 40 | Scalar bottom() const; 41 | Scalar fieldOfView() const; 42 | GLuint viewportWidth() const; 43 | GLuint viewportHeight() const; 44 | State state() const; 45 | Type type() const; 46 | Status status() const; 47 | GLuint id() const; 48 | 49 | void farIs(Scalar distance); 50 | void nearIs(Scalar distance); 51 | void leftIs(Scalar distance); 52 | void rightIs(Scalar distance); 53 | void topIs(Scalar distance); 54 | void bottomIs(Scalar distance); 55 | void fieldOfViewIs(Scalar view); 56 | void stateIs(State state); 57 | void typeIs(Type type); 58 | void statusIs(Status status); 59 | void viewportWidthIs(GLuint width); 60 | void viewportHeightIs(GLuint height); 61 | void viewMatrixIs(Matrix const& matrix); 62 | 63 | void operator()(Ptr functor); 64 | 65 | private: 66 | GLuint id_; 67 | Scalar far_; 68 | Scalar near_; 69 | Scalar left_; 70 | Scalar right_; 71 | Scalar top_; 72 | Scalar bottom_; 73 | Scalar fieldOfView_; 74 | GLuint viewportWidth_; 75 | GLuint viewportHeight_; 76 | State state_; 77 | Type type_; 78 | 79 | // Cached computed values 80 | struct Buffer { 81 | Matrix projectionMatrix_; 82 | Matrix projectionMatrixInv_; 83 | Matrix viewMatrix_; 84 | Matrix viewMatrixInv_; 85 | Matrix viewProjectionMatrix_; 86 | Matrix viewProjectionMatrixInv_; 87 | }; 88 | 89 | mutable Buffer buffer_; 90 | mutable Status status_; 91 | }; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /include/sfr/Color.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | std::ostream& operator<<(std::ostream& out, sfr::Color const& color); 12 | std::istream& operator>>(std::istream& in, sfr::Color& color); 13 | 14 | namespace sfr { 15 | 16 | class Color { 17 | public: 18 | Color(Scalar red, Scalar green, Scalar blue, Scalar alpha); 19 | Color(); 20 | 21 | GLvec4 vec4f() const; 22 | Color operator*(Scalar scale) const; 23 | Color operator+(Color const& other) const; 24 | 25 | friend std::ostream& ::operator<<(std::ostream& out, Color const& color); 26 | friend std::istream& ::operator>>(std::istream& in, Color& color); 27 | 28 | Scalar red; 29 | Scalar green; 30 | Scalar blue; 31 | Scalar alpha; 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /include/sfr/Cubemap.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Manages cubemap texture data */ 14 | class Cubemap : public Interface { 15 | public: 16 | Cubemap(std::string const& name); 17 | ~Cubemap(); 18 | std::string const& name() const; 19 | GLuint width() const; 20 | GLuint height() const; 21 | GLuint id() const; 22 | 23 | void widthIs(GLuint width); 24 | void heightIs(GLuint height); 25 | void dataIs(const GLubyte* pixels); 26 | 27 | private: 28 | std::string name_; 29 | GLuint id_; 30 | GLuint width_; 31 | GLuint height_; 32 | }; 33 | 34 | }; 35 | -------------------------------------------------------------------------------- /include/sfr/DecalRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders transparent particles with an alpha-blend technique. */ 15 | class DecalRenderer : public Renderer { 16 | public: 17 | DecalRenderer(Ptr manager); 18 | void operator()(Ptr decals); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | Ptr program_; 25 | Ptr unitCube_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/Decals.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Program.hpp" 12 | 13 | namespace sfr { 14 | 15 | class Decal { 16 | public: 17 | GLvec3 normal; // Normal of geometry the decal is applied to 18 | GLvec3 right; // Right vector 19 | GLvec3 position; // Position of the center of the decal in world space 20 | GLfloat alpha; // Decal alpha influence 21 | GLfloat width; // Width, height, and depth of the box defined by the normal 22 | GLfloat height; 23 | GLfloat depth; 24 | }; 25 | 26 | /* Renders a set of decals (texture splats) on a existing geometry */ 27 | class Decals : public Node { 28 | public: 29 | Decal const& decal(GLuint index) const; 30 | Decal const* buffer() const { return &decal_.front(); } 31 | GLuint decalCount() const { return GLuint(decal_.size()); } 32 | Ptr texture() const { return texture_; } 33 | bool isVisible() const { return texture_&&decal_.size(); } 34 | 35 | void decalEnq(Decal const& decal); 36 | void decalIs(GLuint index, Decal const& decal); 37 | void decalDelAll(); 38 | void textureIs(Ptr texture); 39 | 40 | private: 41 | virtual void operator()(Ptr functor); 42 | 43 | std::vector decal_; 44 | Ptr texture_; 45 | }; 46 | 47 | class DecalProgram : public Program { 48 | public: 49 | DecalProgram(std::string const& name) : Program(name) {} 50 | 51 | GLint transform() const { return transform_; } 52 | GLint texture() const { return texture_; } 53 | GLint depthBuffer() const { return depthBuffer_; } 54 | GLint unproject() const { return unproject_; } 55 | GLint decalMatrix() const { return decalMatrix_; } 56 | 57 | private: 58 | void onLink(); 59 | GLint transform_ = -1; 60 | GLint texture_ = -1; 61 | GLint depthBuffer_ = -1; 62 | GLint unproject_ = -1; 63 | GLint decalMatrix_ = -1; 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /include/sfr/DeferredRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Deferred shading renderer (with forward-rendering fallback for alpha) */ 15 | class DeferredRenderer : public Node::Functor { 16 | public: 17 | DeferredRenderer(Ptr manager); 18 | void operator()(Ptr scene); 19 | 20 | private: 21 | Ptr materialPass_; 22 | Ptr lightPass_; 23 | Ptr alphaPass_; 24 | Ptr shadowPass_; 25 | Ptr skyboxPass_; 26 | Ptr decalPass_; 27 | Ptr uiPass_; 28 | 29 | Ptr frameBuffer_; 30 | Ptr diffuse_; 31 | Ptr specular_; 32 | Ptr normal_; 33 | Ptr emissive_; 34 | Ptr depth_; 35 | Ptr final_; 36 | 37 | Ptr decalFrameBuffer_; 38 | Ptr finalFrameBuffer_; 39 | }; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /include/sfr/DepthRenderTarget.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Enables render-to-depth texture techniques (i.e., shadow mapping) */ 15 | class DepthRenderTarget : public Interface { 16 | public: 17 | enum Status { ENABLED, DISABLED }; 18 | 19 | DepthRenderTarget(GLuint width, GLuint height); 20 | ~DepthRenderTarget(); 21 | 22 | GLuint id() const; 23 | GLuint depthBuffer() const; 24 | Status status() const; 25 | GLuint width() const { return width_; } 26 | GLuint height() const { return height_; } 27 | 28 | void statusIs(Status status); 29 | 30 | private: 31 | GLuint id_; 32 | GLuint width_; 33 | GLuint height_; 34 | GLuint depthBuffer_; 35 | Status status_; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/sfr/FlatRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Shadow map renderer. */ 15 | class FlatRenderer : public Renderer { 16 | public: 17 | FlatRenderer(Ptr manager, bool shadowPass=false); 18 | void operator()(Ptr object); 19 | void operator()(Ptr mesh); 20 | 21 | using Renderer::operator(); 22 | 23 | private: 24 | void onState(); 25 | Ptr program_; 26 | 27 | bool shadowPass_; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/sfr/Font.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2014 * 6 | *****************************************************************************/ 7 | 8 | #pragma once 9 | 10 | #include "sfr/Common.hpp" 11 | 12 | namespace sfr { 13 | 14 | class Glyph { 15 | public: 16 | GLfloat texX = 0; 17 | GLfloat texY = 0; 18 | GLfloat texWidth = 0; 19 | GLfloat texHeight = 0; 20 | GLfloat advanceX = 0; 21 | GLfloat advanceY = 0; 22 | GLfloat width = 0; 23 | GLfloat height = 0; 24 | GLfloat x = 0; 25 | GLfloat y = 0; 26 | }; 27 | 28 | class Font : public Interface { 29 | public: 30 | enum Type { SDF, SIZED }; 31 | 32 | Font(std::string const& name); 33 | ~Font(); 34 | std::string const& name() const { return name_; } 35 | GLuint id() const { return id_; } 36 | GLuint size() const { return size_; } 37 | GLuint loadSize() const { return loadSize_; } 38 | Glyph glyph(char code) const; 39 | Type type() const { return type_; } 40 | GLvec2 kerning(char prev, char code) const; 41 | void* face() const { return face_; } 42 | 43 | void glyphIs(char code, Glyph const& glyph); 44 | void typeIs(Type type); 45 | private: 46 | Type type_; 47 | std::string name_; 48 | GLuint id_; 49 | GLuint size_; 50 | GLuint loadSize_; 51 | std::vector glyph_; 52 | void* library_; 53 | void* face_; 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /include/sfr/FontLoader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AssetTable.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Loads fonts using freetype2 */ 15 | class FontLoader : public AssetTable::Listener { 16 | public: 17 | FontLoader(Ptr notifier) : AssetTable::Listener(notifier) {} 18 | void onAsset(Ptr font); 19 | 20 | private: 21 | void loadFace(FT_Face face, unsigned char ch); 22 | }; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /include/sfr/FrameBuffer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Collection of textures bound for rendering */ 15 | class FrameBuffer : public Interface { 16 | public: 17 | enum Status { ENABLED, DISABLED }; 18 | FrameBuffer(); 19 | ~FrameBuffer(); 20 | 21 | GLuint drawBufferCount() const; 22 | Ptr drawBuffer(GLuint index) const; 23 | Ptr depthBuffer() const; 24 | Ptr stencilBuffer() const; 25 | Status status() const; 26 | GLuint id() const; 27 | 28 | void drawBufferEnq(Ptr target); 29 | void depthBufferIs(Ptr target); 30 | void stencilBufferIs(Ptr target); 31 | void statusIs(Status status); 32 | 33 | void check(); 34 | 35 | private: 36 | GLuint id_; 37 | std::vector> drawBuffer_; 38 | std::vector drawBufferAttachment_; 39 | Ptr depthBuffer_; 40 | Ptr stencilBuffer_; 41 | Status status_; 42 | }; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/sfr/Frustum.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Vector.hpp" 11 | 12 | namespace sfr { 13 | 14 | class Frustum { 15 | public: 16 | Vector nearTopLeft; 17 | Vector nearTopRight; 18 | Vector nearBottomLeft; 19 | Vector nearBottomRight; 20 | 21 | Vector farTopLeft; 22 | Vector farTopRight; 23 | Vector farBottomLeft; 24 | Vector farBottomRight; 25 | }; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/HemiLight.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Color.hpp" 11 | #include "sfr/Matrix.hpp" 12 | #include "sfr/Node.hpp" 13 | #include "sfr/Vector.hpp" 14 | 15 | namespace sfr { 16 | 17 | /* Simple point light with attenuation */ 18 | class HemiLight : public Node { 19 | public: 20 | HemiLight(); 21 | Color const& diffuseColor() const; 22 | Color const& backDiffuseColor() const; 23 | Color const& specularColor() const; 24 | Color const& ambientColor() const; 25 | Vector const& direction() const; 26 | Scalar constantAttenuation() const; 27 | Scalar linearAttenuation() const; 28 | Scalar quadraticAttenuation() const; 29 | Scalar radiusOfEffect() const; 30 | Ptr shadowMap() const; 31 | Matrix const& transform() const; 32 | Scalar shadowViewDistance() const; 33 | bool isVisible() const; 34 | 35 | void diffuseColorIs(Color const& color); 36 | void backDiffuseColorIs(Color const& color); 37 | void specularColorIs(Color const& color); 38 | void ambientColorIs(Color const& color); 39 | void directionIs(Vector const& direction); 40 | void constantAttenuationIs(Scalar atten); 41 | void linearAttenuationIs(Scalar atten); 42 | void quadraticAttenuationIs(Scalar atten); 43 | void shadowMapIs(Ptr target); 44 | void transformIs(Matrix const& matrix); 45 | void shadowViewDistanceIs(Scalar distance); 46 | 47 | void operator()(Ptr functor); 48 | 49 | private: 50 | Color diffuseColor_; 51 | Color backDiffuseColor_; 52 | Color specularColor_; 53 | Color ambientColor_; 54 | Vector direction_; 55 | Scalar constantAttenuation_; 56 | Scalar linearAttenuation_; 57 | Scalar quadraticAttenuation_; 58 | Ptr shadowMap_; 59 | Matrix transform_; // Light-space transform (for shadow mappping) 60 | Scalar shadowViewDistance_; 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /include/sfr/IndexBuffer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Contains one attribute array (e.g., normals, indices, etc.) for a mesh. */ 15 | class IndexBuffer : public Interface { 16 | public: 17 | enum Status { SYNCED, DIRTY }; 18 | 19 | IndexBuffer(std::string const& name); 20 | ~IndexBuffer(); 21 | 22 | std::string const& name() const; 23 | GLuint id() const; 24 | GLuint elementCount() const; 25 | GLuint elementSize() const; 26 | GLuint const& element(GLuint index) const; 27 | Status status() const; 28 | 29 | void elementCountIs(GLuint count); 30 | void elementIs(GLuint offset, GLuint element); 31 | void elementEnq(GLuint element) { elementIs(GLuint(element_.size()), element); } 32 | void statusIs(Status status); 33 | 34 | private: 35 | void syncHardwareBuffers(); 36 | const void* data() const; 37 | 38 | std::string name_; 39 | GLuint id_; 40 | Status status_; 41 | std::vector element_; 42 | }; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/sfr/Instances.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | namespace sfr { 10 | 11 | class Instance { 12 | public: 13 | sfr::Matrix transform; 14 | sfr::Matrix normalMatrix; 15 | }; 16 | 17 | /* Renders many copies of the same mesh efficiently */ 18 | class Instances : public Node { 19 | public: 20 | enum Attribute { TRANSFORM, NORMALMATRIX }; 21 | 22 | Instances(); 23 | Instance const& instance(GLuint index) const; 24 | GLuint instanceCount() const; 25 | Ptr mesh(); 26 | Ptr model(); 27 | 28 | void meshIs(Ptr mesh); 29 | void modelIs(Ptr model); 30 | void instanceIs(GLuint instance, Instance const& instance); 31 | void instanceEnq(Instance const& instance); 32 | void instanceDelAll(); 33 | 34 | private: 35 | virtual void operator()(Ptr functor); 36 | 37 | std::vector instance_; 38 | Ptr mesh_; 39 | Ptr material_; 40 | }; 41 | 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /include/sfr/Interface.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | namespace sfr { 10 | 11 | /* Provides intrusive smart-pointer support. */ 12 | class Interface : public std::enable_shared_from_this { 13 | public: 14 | virtual ~Interface() {} 15 | }; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /include/sfr/Iterator.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Iterator support for intrusive singly-linked lists. */ 14 | template 15 | class Iterator { 16 | public: 17 | /* 18 | Iterator(T* start) { 19 | current_ = start; 20 | } 21 | 22 | template 23 | void operator()(F* functor) { 24 | if (current_) { 25 | current_->operator()(functor); 26 | } 27 | } 28 | 29 | T* ptr() const { 30 | return current_.ptr(); 31 | } 32 | 33 | T* operator->() const { 34 | return current_.operator->(); 35 | } 36 | 37 | operator T*() const { 38 | return current_; 39 | } 40 | 41 | bool operator==(Ptr const& other) { 42 | return current_ == other; 43 | } 44 | 45 | bool operator!=(Ptr const& other) { 46 | return current_ != other; 47 | } 48 | 49 | Iterator const& operator++(int) { 50 | current_ = current_->next(); 51 | return *this; 52 | } 53 | 54 | template 55 | operator Iterator() const { 56 | return Iterator(current_); 57 | } 58 | 59 | 60 | private: 61 | Ptr current_; 62 | */ 63 | Iterator(C const& list) : 64 | begin_(list.begin()), 65 | end_(list.end()) { 66 | } 67 | 68 | template 69 | void operator()(Ptr functor) { 70 | (*begin_)->operator()(functor); 71 | } 72 | 73 | operator bool() const { 74 | return begin_ != end_; 75 | } 76 | 77 | typename C::value_type const* operator->() const { 78 | return begin_.operator->(); 79 | } 80 | 81 | bool operator==(typename C::value_type const& other) { 82 | return begin_ == other.begin_ && end_ == other.end_; 83 | } 84 | 85 | bool operator!=(typename C::value_type const& other) { 86 | return !operator==(other); 87 | } 88 | 89 | Iterator const& operator++(int) { 90 | begin_++; 91 | return *this; 92 | } 93 | 94 | 95 | typename C::value_type* get() const { 96 | return begin_.operator->(); 97 | } 98 | 99 | private: 100 | typename C::const_iterator begin_; 101 | typename C::const_iterator end_; 102 | 103 | }; 104 | 105 | } 106 | -------------------------------------------------------------------------------- /include/sfr/Light.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Program.hpp" 11 | 12 | namespace sfr { 13 | 14 | class LightProgram : public Program { 15 | public: 16 | LightProgram(std::string const& name) : Program(name) {} 17 | 18 | GLint shadowMap() const { return shadowMap_; } 19 | GLint diffuseBuffer() const { return diffuseBuffer_; } 20 | GLint specularBuffer() const { return specularBuffer_; } 21 | GLint normalBuffer() const { return normalBuffer_; } 22 | GLint emissiveBuffer() const { return emissiveBuffer_; } 23 | GLint depthBuffer() const { return depthBuffer_; } 24 | GLint diffuse() const { return diffuse_; } 25 | GLint specular() const { return specular_; } 26 | GLint ambient() const { return ambient_; } 27 | GLint backDiffuse() const { return backDiffuse_; } 28 | GLint atten0() const { return atten0_; } 29 | GLint atten1() const { return atten1_; } 30 | GLint atten2() const { return atten2_; } 31 | GLint spotCutoff() const { return spotCutoff_; } 32 | GLint spotPower() const { return spotPower_; } 33 | GLint direction() const { return direction_; } 34 | GLint transform() const { return transform_; } 35 | GLint modelView() const { return modelView_; } 36 | GLint unproject() const { return unproject_; } 37 | GLint light() const { return light_; } 38 | GLint shadowMapSize() const { return shadowMapSize_; } 39 | 40 | private: 41 | void onLink(); 42 | 43 | GLint shadowMap_ = -1; 44 | GLint shadowMapSize_ = -1; 45 | GLint diffuseBuffer_ = -1; 46 | GLint specularBuffer_ = -1; 47 | GLint normalBuffer_ = -1; 48 | GLint emissiveBuffer_ = -1; 49 | GLint depthBuffer_ = -1; 50 | GLint diffuse_ = -1; 51 | GLint specular_ = -1; 52 | GLint ambient_ = -1; 53 | GLint backDiffuse_ = -1; 54 | GLint atten0_ = -1; 55 | GLint atten1_ = -1; 56 | GLint atten2_ = -1; 57 | GLint spotCutoff_ = -1; 58 | GLint spotPower_ = -1; 59 | GLint direction_ = -1; 60 | GLint transform_ = -1; 61 | GLint modelView_ = -1; 62 | GLint unproject_ = -1; 63 | GLint light_ = -1; 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /include/sfr/LightRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Deferred shading renderer (2nd pass). */ 15 | class LightRenderer : public Renderer { 16 | public: 17 | LightRenderer(Ptr manager); 18 | void operator()(Ptr light); 19 | void operator()(Ptr effect); 20 | void operator()(Ptr light); 21 | void operator()(Ptr light); 22 | void operator()(Ptr mesh); 23 | 24 | using Renderer::operator(); 25 | 26 | private: 27 | void onState(); 28 | Ptr unitSphere_; 29 | Ptr unitCone_; 30 | Ptr unitQuad_; 31 | Ptr program_; 32 | Ptr directionalLight_; 33 | Ptr pointLight_; 34 | Ptr hemiLight_; 35 | Ptr spotLight_; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/sfr/Material.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | #include "sfr/Color.hpp" 12 | 13 | namespace sfr { 14 | 15 | /* Mesh color and texture properties */ 16 | class Material : public Interface { 17 | public: 18 | enum BlendMode { ALPHA, ADDITIVE }; 19 | 20 | Material(std::string const& name); 21 | 22 | std::string const& name() const; 23 | Ptr diffuseMap() const; 24 | Ptr specularMap() const; 25 | Ptr normalMap() const; 26 | Ptr emissiveMap() const; 27 | Color const& ambientColor() const; 28 | Color const& diffuseColor() const; 29 | Color const& specularColor() const; 30 | Color const& emissiveColor() const; 31 | Scalar shininess() const; 32 | Scalar opacity() const; 33 | BlendMode blendMode() const; 34 | Ptr clone() const; 35 | 36 | void diffuseMapIs(Ptr texture); 37 | void specularMapIs(Ptr texture); 38 | void normalMapIs(Ptr texture); 39 | void emissiveMapIs(Ptr texture); 40 | void ambientColorIs(Color const& color); 41 | void diffuseColorIs(Color const& color); 42 | void specularColorIs(Color const& color); 43 | void emissiveColorIs(Color const& color); 44 | void shininessIs(Scalar shininess); 45 | void opacityIs(Scalar opacity); 46 | void blendModeIs(BlendMode mode); 47 | 48 | private: 49 | std::string name_; 50 | Ptr diffuseMap_; 51 | Ptr specularMap_; 52 | Ptr normalMap_; 53 | Ptr emissiveMap_; 54 | Color ambientColor_; 55 | Color diffuseColor_; 56 | Color specularColor_; 57 | Color emissiveColor_; 58 | Scalar shininess_; 59 | Scalar opacity_; 60 | BlendMode blendMode_; 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /include/sfr/Matrix.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* 4x4 transformation matrix value type. */ 14 | class Matrix { 15 | public: 16 | 17 | static Matrix frustum(Scalar l, Scalar r, Scalar b, Scalar t, Scalar n, Scalar f); 18 | static Matrix ortho(Scalar l, Scalar r, Scalar b, Scalar t, Scalar n, Scalar f); 19 | static Matrix perspective(Scalar fovy, Scalar aspect, Scalar near, Scalar far); 20 | static Matrix scale(Scalar sx, Scalar sy, Scalar sz); 21 | static Matrix rotate(Quaternion const& rotation); 22 | static Matrix rotate(Vector const& x, Vector const& y, Vector const& z); 23 | static Matrix look(Vector const& pos, Vector const& at, Vector const& up); 24 | static Matrix look(Vector const& direction); 25 | static Matrix translate(Vector const& trans); 26 | static Matrix fromForwardVector(Vector const& forward); 27 | 28 | Matrix(const Scalar data[16]); 29 | Matrix(Scalar m00, Scalar m01, Scalar m02, Scalar m03, 30 | Scalar m10, Scalar m11, Scalar m12, Scalar m13, 31 | Scalar m20, Scalar m21, Scalar m22, Scalar m23, 32 | Scalar m30, Scalar m31, Scalar m32, Scalar m33); 33 | Matrix(Quaternion const& rotation, Vector const& trans); 34 | Matrix(); 35 | 36 | GLmat4 mat4f() const; 37 | Matrix inverse() const; 38 | Matrix transpose() const; 39 | Matrix operator*(Matrix const& other) const; 40 | Vector operator*(Vector const& other) const; 41 | Frustum operator*(Frustum const& other) const; 42 | Vector rotate(Vector const& other) const; 43 | Vector normal(Vector const& other) const; 44 | 45 | Vector forward() const; 46 | Vector right() const; 47 | Vector up() const; 48 | Vector origin() const; 49 | Quaternion rotation() const; 50 | 51 | /* Matrix layout (column major, a la OpenGL): 52 | * 0 4 8 12 53 | * 1 5 9 13 54 | * 2 6 10 14 55 | * 3 7 11 15 56 | */ 57 | Scalar operator[](size_t index) const { return data[index]; } 58 | Scalar& operator[](size_t index) { return data[index]; } 59 | private: 60 | Scalar data[16]; 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /include/sfr/Mesh.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AttributeBuffer.hpp" 11 | #include "sfr/Interface.hpp" 12 | #include "sfr/Box.hpp" 13 | 14 | namespace sfr { 15 | 16 | class MeshVertex { 17 | public: 18 | bool operator<(MeshVertex const& other) const; 19 | bool operator==(MeshVertex const& other) const; 20 | bool operator!=(MeshVertex const& other) const; 21 | MeshVertex operator+(MeshVertex const& other) const; 22 | MeshVertex operator*(Scalar scale) const; 23 | 24 | GLvec3 position; 25 | GLvec3 normal; 26 | GLvec3 tangent; 27 | GLvec2 texCoord; 28 | }; 29 | 30 | /* Geometric mesh node (with attached textures) */ 31 | class Mesh : public Interface { 32 | public: 33 | enum Status { SYNCED, DIRTY }; 34 | enum Attribute { POSITION, NORMAL, TANGENT, TEXCOORD }; 35 | enum RenderMode { VISIBLE, INVISIBLE }; 36 | 37 | Mesh(std::string const& name); 38 | ~Mesh(); 39 | std::string const& name() const; 40 | Ptr attributeBuffer() const; 41 | Ptr indexBuffer() const; 42 | Status status() const; 43 | RenderMode renderMode() const { return renderMode_; } 44 | GLuint id() const { return id_; } 45 | Box const& bounds() { return bounds_; } 46 | 47 | void attributeBufferIs(Ptr> buffer); 48 | void indexBufferIs(Ptr indices); 49 | void statusIs(Status status); 50 | void renderModeIs(RenderMode mode) { renderMode_ = mode; } 51 | void boundsIs(Box const& bounds) { bounds_ = bounds; } 52 | 53 | private: 54 | void updateTangents(); 55 | void updateVertexArrayObject(); 56 | 57 | std::string name_; 58 | Ptr> attributeBuffer_; 59 | Ptr indexBuffer_; 60 | Status status_; 61 | RenderMode renderMode_; 62 | GLuint id_; 63 | Box bounds_; 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /include/sfr/Model.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Program.hpp" 12 | 13 | namespace sfr { 14 | 15 | /* Geometric mesh node (with attached textures) */ 16 | class Model : public Node { 17 | public: 18 | Model(); 19 | Ptr material() const; 20 | Ptr mesh() const; 21 | Ptr program() const; 22 | Ptr clone() const; 23 | Ptr nodeClone() const; 24 | void* userData() const; 25 | 26 | void materialIs(Ptr material); 27 | void meshIs(Ptr mesh); 28 | void programIs(Ptr program); 29 | void userDataIs(void* data); 30 | 31 | virtual void operator()(Ptr functor); 32 | 33 | private: 34 | Ptr material_; 35 | Ptr mesh_; 36 | Ptr program_; 37 | void* userData_; 38 | }; 39 | 40 | class ModelProgram : public Program { 41 | public: 42 | ModelProgram(std::string const& name) : Program(name) {} 43 | 44 | GLint diffuseMap() const { return diffuseMap_; } 45 | GLint specularMap() const { return specularMap_; } 46 | GLint normalMap() const { return normalMap_; } 47 | GLint emissiveMap() const { return emissiveMap_; } 48 | GLint ambient() const { return ambient_; } 49 | GLint diffuse() const { return diffuse_; } 50 | GLint specular() const { return specular_; } 51 | GLint emissive() const { return emissive_; } 52 | GLint shininess() const { return shininess_; } 53 | GLint normalMatrix() const { return normalMatrix_; } 54 | GLint transform() const { return transform_; } 55 | GLint opacity() const { return opacity_; } 56 | 57 | virtual void onLink(); 58 | virtual void onRender(Ptr model) {} 59 | 60 | private: 61 | GLint diffuseMap_ = -1; 62 | GLint specularMap_ = -1; 63 | GLint normalMap_ = -1; 64 | GLint emissiveMap_ = -1; 65 | GLint ambient_ = -1; 66 | GLint diffuse_ = -1; 67 | GLint specular_ = -1; 68 | GLint emissive_ = -1; 69 | GLint shininess_ = -1; 70 | GLint opacity_ = -1; 71 | GLint normalMatrix_ = -1; 72 | GLint transform_ = -1; 73 | }; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /include/sfr/ModelRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Node.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Simple renderer. Passes vertex, texture, and material info to a shader. */ 15 | class ModelRenderer : public Renderer { 16 | public: 17 | ModelRenderer(Ptr manager); 18 | void operator()(Ptr object); 19 | void operator()(Ptr mesh); 20 | void operator()(Ptr material); 21 | void operator()(Ptr texture); 22 | 23 | using Renderer::operator(); 24 | 25 | private: 26 | void onState(); 27 | Ptr program_; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/sfr/Node.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Provides functor support for the classes in the scene graph. */ 15 | class Node : public Interface { 16 | public: 17 | class Functor; 18 | virtual void operator()(Ptr functor)=0; 19 | virtual Ptr nodeClone() const { return 0; } 20 | }; 21 | 22 | /* Implement this interface to perform processing on the scene. */ 23 | class Node::Functor : public Interface { 24 | public: 25 | virtual ~Functor() {}; 26 | virtual void operator()(Ptr camera) {} 27 | virtual void operator()(Ptr transform) {} 28 | virtual void operator()(Ptr model) {} 29 | virtual void operator()(Ptr light) {} 30 | virtual void operator()(Ptr light) {} 31 | virtual void operator()(Ptr light) {} 32 | virtual void operator()(Ptr particles) {} 33 | virtual void operator()(Ptr ribbon) {} 34 | virtual void operator()(Ptr billboards) {} 35 | virtual void operator()(Ptr quad) {} 36 | virtual void operator()(Ptr text) {} 37 | virtual void operator()(Ptr ui) {} 38 | virtual void operator()(Ptr decals) {} 39 | }; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /include/sfr/NullFunctor.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Empty functor implementation for performance testing */ 15 | class NullFunctor : public Node::Functor { 16 | public: 17 | void operator()(Ptr scene); 18 | void operator()(Ptr camera); 19 | void operator()(Ptr transform); 20 | void operator()(Ptr light); 21 | void operator()(Ptr object); 22 | void operator()(Ptr light); 23 | void operator()(Ptr light); 24 | }; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/sfr/ParticleRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders transparent particles with an alpha-blend technique. */ 15 | class ParticleRenderer : public Renderer { 16 | public: 17 | ParticleRenderer(Ptr manager); 18 | void operator()(Ptr particles); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | Ptr program_; 25 | Ptr buffer_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/Particles.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Color.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Program.hpp" 13 | 14 | namespace sfr { 15 | 16 | class Particle { 17 | public: 18 | GLvec3 position; // Position of the particle 19 | GLvec3 velocity; // Velocity of the particle 20 | GLvec4 color; // Color blend of the particle 21 | GLfloat size; // Size of the particle in scene coordinates 22 | GLfloat rotation; // Texture rotation about view z-axis 23 | }; 24 | 25 | /* Particle system */ 26 | class Particles : public Node { 27 | public: 28 | enum Attribute { POSITION, COLOR, SIZE, ROTATION }; 29 | enum ClearMode { MANUAL, AUTO }; 30 | enum BlendMode { ALPHA, ADDITIVE }; 31 | 32 | Particles(); 33 | Particle const& particle(GLuint index) const; 34 | Particle const* buffer() const { return &buffer_.front(); } 35 | GLuint particleCount() const { return GLuint(buffer_.size()); } 36 | Ptr texture() const { return texture_; } 37 | Color const& tint() const { return tint_; } 38 | ClearMode clearMode() const { return clearMode_; } 39 | BlendMode blendMode() const { return blendMode_; } 40 | bool isVisible() const { return texture_&&buffer_.size(); } 41 | 42 | void particleEnq(Particle const& particle); 43 | void particleIs(GLuint index, Particle const& particle); 44 | void particleDelAll(); 45 | void textureIs(Ptr texture); 46 | void tintIs(Color const& tint); 47 | void clearModeIs(ClearMode mode); 48 | void blendModeIs(BlendMode mode); 49 | 50 | private: 51 | virtual void operator()(Ptr functor); 52 | 53 | std::vector buffer_; 54 | Ptr texture_; 55 | Color tint_; 56 | ClearMode clearMode_; 57 | BlendMode blendMode_; 58 | }; 59 | 60 | class ParticleProgram : public Program { 61 | public: 62 | ParticleProgram(std::string const& name) : Program(name) {} 63 | 64 | GLint texture() const { return texture_; } 65 | GLint tint() const { return tint_; } 66 | GLint modelViewMatrix() const { return modelViewMatrix_; } 67 | GLint projectionMatrix() const { return projectionMatrix_; } 68 | GLint depthBuffer() const { return depthBuffer_; } 69 | GLint unprojectMatrix() const { return unprojectMatrix_; } 70 | 71 | private: 72 | void onLink(); 73 | 74 | GLint texture_ = -1; 75 | GLint depthBuffer_ = -1; 76 | GLint tint_ = -1; 77 | GLint modelViewMatrix_ = -1; 78 | GLint projectionMatrix_ = -1; 79 | GLint unprojectMatrix_ = -1; 80 | }; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /include/sfr/PointLight.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Color.hpp" 12 | 13 | namespace sfr { 14 | 15 | /* Simple point light with attenuation */ 16 | class PointLight : public Node { 17 | public: 18 | PointLight(); 19 | Color const& diffuseColor() const; 20 | Color const& specularColor() const; 21 | Scalar constantAttenuation() const; 22 | Scalar linearAttenuation() const; 23 | Scalar quadraticAttenuation() const; 24 | Scalar radiusOfEffect() const; 25 | bool isVisible() const; 26 | 27 | void diffuseColorIs(Color const& diffuse); 28 | void specularColorIs(Color const& specular); 29 | void constantAttenuationIs(Scalar atten); 30 | void linearAttenuationIs(Scalar atten); 31 | void quadraticAttenuationIs(Scalar atten); 32 | 33 | void operator()(Ptr functor); 34 | 35 | private: 36 | Color diffuseColor_; 37 | Color specularColor_; 38 | Scalar constantAttenuation_; 39 | Scalar linearAttenuation_; 40 | Scalar quadraticAttenuation_; 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /include/sfr/Program.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Manages a GPU program, which may have multiple shaders attached. */ 15 | class Program : public Interface { 16 | public: 17 | enum Status { LINKED, DIRTY }; 18 | enum UniformBuffer { CAMERA }; 19 | 20 | Program(std::string const& name); 21 | ~Program(); 22 | 23 | std::string const& name() const; 24 | Ptr fragmentShader() const; 25 | Ptr vertexShader() const; 26 | Ptr geometryShader() const; 27 | GLuint id() const; 28 | Status status() const; 29 | 30 | void fragmentShaderIs(Ptr shader); 31 | void vertexShaderIs(Ptr shader); 32 | void geometryShaderIs(Ptr shader); 33 | void statusIs(Status status); 34 | 35 | private: 36 | virtual void onLink() {} 37 | void linkShaders(); 38 | 39 | std::string name_; 40 | Ptr fragmentShader_; 41 | Ptr vertexShader_; 42 | Ptr geometryShader_; 43 | GLuint id_; 44 | Status status_; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /include/sfr/ProgramLoader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #pragma once 9 | 10 | #include "sfr/Common.hpp" 11 | #include "sfr/AssetTable.hpp" 12 | 13 | namespace sfr { 14 | 15 | /* Loads GLSL vertex and fragment shader programs */ 16 | class ProgramLoader : public AssetTable::Listener { 17 | public: 18 | ProgramLoader(Ptr notifier) : AssetTable::Listener(notifier) {} 19 | void onAsset(Ptr program); 20 | void onAsset(Ptr shader); 21 | }; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /include/sfr/Ptr.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Interface.hpp" 10 | 11 | namespace sfr { 12 | 13 | template 14 | using Ptr = std::shared_ptr; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/sfr/Quad.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Color.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Program.hpp" 13 | 14 | namespace sfr { 15 | 16 | class Quad : public Node { 17 | public: 18 | enum Mode { NORMAL, PARTICLE }; 19 | Quad(); 20 | Ptr texture() const { return texture_; } 21 | Scalar width() const { return width_; } 22 | Scalar height() const { return height_; } 23 | Mode mode() const { return mode_; } 24 | sfr::Color const& tint() const { return tint_; } 25 | 26 | void textureIs(Ptr texture); 27 | void widthIs(Scalar width); 28 | void heightIs(Scalar height); 29 | void modeIs(Mode mode); 30 | void tintIs(sfr::Color tint); 31 | private: 32 | void operator()(Ptr functor); 33 | 34 | Ptr texture_; 35 | Mode mode_; 36 | Scalar width_; 37 | Scalar height_; 38 | sfr::Color tint_; 39 | }; 40 | 41 | class QuadProgram : public Program { 42 | public: 43 | QuadProgram(std::string const& name) : Program(name) {} 44 | 45 | GLint texture() const { return texture_; } 46 | GLint transform() const { return transform_; } 47 | GLint tint() const { return tint_; } 48 | 49 | private: 50 | void onLink(); 51 | GLint texture_ = -1; 52 | GLint transform_ = -1; 53 | GLint tint_ = -1; 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /include/sfr/QuadRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders transparent billboards with an alpha-blend technique. */ 15 | class QuadRenderer : public Renderer { 16 | public: 17 | QuadRenderer(Ptr manager); 18 | void operator()(Ptr quad); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | Ptr program_; 25 | Ptr quad_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/Quaternion.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | std::ostream& operator<<(std::ostream& out, sfr::Quaternion const& quaternion); 12 | std::istream& operator>>(std::istream& in, sfr::Quaternion& quaternion); 13 | 14 | namespace sfr { 15 | 16 | class Quaternion { 17 | public: 18 | Quaternion(Scalar w, Scalar x, Scalar y, Scalar z); 19 | Quaternion(Vector const& axis, Scalar angle); // Radians! 20 | Quaternion(Vector const& x, Vector const& y, Vector const& z); 21 | Quaternion(Matrix const& matrix); 22 | Quaternion(Scalar w, Vector const& vector); 23 | Quaternion(); 24 | 25 | friend std::ostream& ::operator<<(std::ostream& out, Quaternion const& quaternion); 26 | friend std::istream& ::operator>>(std::istream& in, Quaternion& quaternion); 27 | 28 | Scalar length() const; 29 | Scalar lengthSquared() const; 30 | Scalar dot(Quaternion const& other) const; 31 | Vector operator*(Vector const& other) const; 32 | Quaternion operator*(Scalar s) const; 33 | Quaternion operator+(Quaternion const& other) const; 34 | Quaternion operator-(Quaternion const& other) const; 35 | Quaternion operator*(Quaternion const& other) const; 36 | Quaternion operator-() const; 37 | Quaternion slerp(Quaternion const& other, Scalar alpha) const; 38 | Quaternion inverse() const; 39 | Quaternion unit() const; 40 | bool operator==(const Quaternion other) const; 41 | bool operator!=(Quaternion const& other) const; 42 | Quaternion& operator+=(Quaternion const& other); 43 | Quaternion& operator-=(Quaternion const& other); 44 | 45 | static Quaternion IDENTITY; 46 | 47 | Scalar w; 48 | Scalar x; 49 | Scalar y; 50 | Scalar z; 51 | }; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /include/sfr/RenderTarget.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Interface.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Creates a texture suitable for binding to a frame buffer */ 15 | class RenderTarget : public Interface { 16 | public: 17 | RenderTarget(GLuint width, GLuint height, GLuint format); 18 | ~RenderTarget(); 19 | GLuint id() const { return id_; } 20 | 21 | private: 22 | GLuint id_; 23 | }; 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/sfr/Renderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #pragma once 9 | 10 | #include "sfr/Common.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Matrix.hpp" 13 | 14 | namespace sfr { 15 | 16 | /* Base class for all renderers. Keeps track of the scene transform */ 17 | class Renderer : public Node::Functor { 18 | public: 19 | enum State { ACTIVE, INACTIVE }; 20 | 21 | Matrix const& worldMatrix() const; // Current scene transform 22 | State state() const; 23 | Ptr scene() const; 24 | 25 | void worldMatrixIs(Matrix const& transform); 26 | void sceneIs(Ptr scene); 27 | void stateIs(State state); 28 | 29 | void operator()(Ptr scene); 30 | 31 | virtual void onState() {} 32 | 33 | private: 34 | Matrix worldMatrix_; 35 | State state_ = INACTIVE; 36 | Ptr scene_; 37 | }; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /include/sfr/ResourceException.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #pragma once 9 | 10 | #include "sfr/Common.hpp" 11 | 12 | namespace sfr { 13 | 14 | class ResourceException { 15 | public: 16 | ResourceException(std::string const& message); 17 | std::string const& message() const { return message_; } 18 | private: 19 | std::string message_; 20 | }; 21 | 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /include/sfr/Ribbon.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AttributeBuffer.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Vector.hpp" 13 | #include "sfr/Program.hpp" 14 | 15 | namespace sfr { 16 | 17 | class RibbonVertex { 18 | public: 19 | GLvec3 position; 20 | GLvec3 direction; 21 | GLint index; 22 | }; 23 | 24 | /* Ribbon trail system */ 25 | class Ribbon : public Node { 26 | public: 27 | enum Attribute { POSITION, DIRECTION, INDEX }; 28 | 29 | Ribbon(); 30 | GLuint pointCount() const { return std::min(tail_, pointQuota()); } 31 | GLint pointQuota() const { return pointQuota_; } 32 | GLint pointTail() const { return tail_; } 33 | RibbonVertex const* buffer() const { return &buffer_.front(); } 34 | Ptr texture() const { return texture_; } 35 | Scalar width() const { return width_; } 36 | Scalar minWidth() const { return minWidth_; } 37 | bool isVisible() const { return texture_&&buffer_.size(); } 38 | GLuint ribbonVertexCount() const { return GLuint(buffer_.size()); } 39 | 40 | void ribbonVertexIs(GLuint index, RibbonVertex const& rv); 41 | void pointQuotaIs(GLint quota); 42 | void pointTailIs(Vector const& point); 43 | void pointEnq(Vector const& point); 44 | void pointDelAll(); 45 | void textureIs(Ptr texture); 46 | void widthIs(Scalar width); 47 | void minWidthIs(Scalar width); 48 | 49 | private: 50 | virtual void operator()(Ptr functor); 51 | 52 | std::vector buffer_; 53 | Ptr texture_; 54 | GLint tail_; 55 | GLint pointQuota_; 56 | Scalar width_; 57 | Scalar minWidth_; 58 | 59 | RibbonVertex prev0_; 60 | RibbonVertex prev1_; 61 | }; 62 | 63 | class RibbonProgram : public Program { 64 | public: 65 | RibbonProgram(std::string const& name) : Program(name) {} 66 | 67 | GLint texture() { return texture_; } 68 | GLint projectionMatrix() { return projectionMatrix_; } 69 | GLint modelViewMatrix() { return modelViewMatrix_; } 70 | GLint normalMatrix() { return normalMatrix_; } 71 | GLint width() { return width_; } 72 | GLint minWidth() { return minWidth_; } 73 | GLint count() { return count_; } 74 | GLint tail() { return tail_; } 75 | 76 | private: 77 | void onLink(); 78 | 79 | GLint texture_ = -1; 80 | GLint projectionMatrix_ = -1; 81 | GLint modelViewMatrix_ = -1; 82 | GLint normalMatrix_ = -1; 83 | GLint width_ = -1; 84 | GLint minWidth_ = -1; 85 | GLint count_ = -1; 86 | GLint tail_ = -1; 87 | }; 88 | 89 | } 90 | -------------------------------------------------------------------------------- /include/sfr/RibbonRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders ribbons of triangles */ 15 | class RibbonRenderer : public Renderer { 16 | public: 17 | RibbonRenderer(Ptr manager); 18 | void operator()(Ptr ribbon); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | 25 | Ptr program_; 26 | Ptr buffer_; 27 | }; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /include/sfr/Scene.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Transform.hpp" 11 | 12 | namespace sfr { 13 | 14 | class RenderDesc { 15 | public: 16 | RenderDesc(Ptr node, Ptr program, Matrix const& worldMatrix); 17 | 18 | Ptr node() const { return node_; } 19 | Ptr program() const { return program_; } 20 | Matrix const& worldMatrix() const { return worldMatrix_; } 21 | bool operator<(RenderDesc const& other) const; 22 | 23 | private: 24 | Ptr node_; 25 | Ptr program_; 26 | Matrix worldMatrix_; 27 | }; 28 | 29 | class UiRenderDesc { 30 | public: 31 | UiRenderDesc(Ptr node, Ptr program, Rect const& rect); 32 | 33 | Ptr node() const { return node_; } 34 | Ptr program() const { return program_; } 35 | Rect const& rect() const { return rect_; } 36 | bool operator<(UiRenderDesc const& other) const; 37 | 38 | private: 39 | Ptr node_; 40 | Ptr program_; 41 | Rect rect_; 42 | }; 43 | 44 | /* Holds the root node and global scene data. */ 45 | class Scene : public Interface { 46 | public: 47 | Scene(); 48 | Ptr root() const; 49 | Ptr camera() const; 50 | Ptr skybox() const; 51 | Ptr ui() const; 52 | Iterator> renderDescs() const; 53 | Iterator> uiRenderDescs() const; 54 | 55 | void cameraIs(Ptr camera); 56 | void skyboxIs(Ptr cubemap); 57 | void renderDescIs(RenderDesc const& renderDesc); 58 | void renderDescDelAll(); 59 | void uiRenderDescIs(UiRenderDesc const& uiRenderDesc); 60 | void uiRenderDescDelAll(); 61 | 62 | void sort(); 63 | 64 | private: 65 | Ptr root_; 66 | Ptr camera_; 67 | Ptr skybox_; 68 | Ptr ui_; 69 | 70 | std::vector renderDesc_; 71 | std::vector uiRenderDesc_; 72 | }; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /include/sfr/Shader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Single GPU shader source file. */ 14 | class Shader : public Interface { 15 | public: 16 | enum Status { COMPILED, DIRTY }; 17 | 18 | Shader(std::string const& name, GLenum type); 19 | ~Shader(); 20 | 21 | std::string const& name() const; 22 | std::string const& source() const; 23 | GLenum type() const; 24 | Status status() const; 25 | GLuint id() const; 26 | 27 | void sourceIs(std::string const& name); 28 | void statusIs(Status status); 29 | 30 | private: 31 | std::string name_; 32 | std::string source_; 33 | GLenum type_; 34 | Status status_; 35 | GLuint id_; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/sfr/ShadowRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Shadow map renderer. */ 15 | class ShadowRenderer : public Renderer { 16 | public: 17 | ShadowRenderer(Ptr manager); 18 | void operator()(Ptr light); 19 | void operator()(Ptr light); 20 | void operator()(Ptr light); 21 | 22 | using Renderer::operator(); 23 | 24 | private: 25 | Ptr flatRenderer_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/SkyboxRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Sky box renderer. */ 15 | class SkyboxRenderer : public Renderer { 16 | public: 17 | SkyboxRenderer(Ptr manager); 18 | void operator()(Ptr scene); 19 | 20 | private: 21 | Ptr scene_; 22 | Ptr program_; 23 | Ptr unitSphere_; 24 | 25 | GLint transform_; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/sfr/SpotLight.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Color.hpp" 12 | #include "sfr/Vector.hpp" 13 | #include "sfr/Matrix.hpp" 14 | 15 | namespace sfr { 16 | 17 | /* Simple point light with attenuation */ 18 | class SpotLight : public Node { 19 | public: 20 | SpotLight(); 21 | Color const& diffuseColor() const; 22 | Color const& specularColor() const; 23 | Vector const& direction() const; 24 | Scalar constantAttenuation() const; 25 | Scalar linearAttenuation() const; 26 | Scalar quadraticAttenuation() const; 27 | Scalar spotCutoff() const; 28 | Scalar spotPower() const; 29 | Scalar radiusOfEffect() const; 30 | Ptr shadowMap() const; 31 | Matrix const& transform() const; 32 | bool isVisible() const; 33 | 34 | void diffuseColorIs(Color const& diffuse); 35 | void specularColorIs(Color const& specular); 36 | void directionIs(Vector const& direction); 37 | void constantAttenuationIs(Scalar atten); 38 | void linearAttenuationIs(Scalar atten); 39 | void quadraticAttenuationIs(Scalar atten); 40 | void spotCutoffIs(Scalar cutoff); 41 | void spotPowerIs(Scalar power); 42 | void shadowMapIs(Ptr target); 43 | void transformIs(Matrix const& matrix); 44 | 45 | void operator()(Ptr functor); 46 | 47 | private: 48 | Color diffuseColor_; 49 | Color specularColor_; 50 | Scalar constantAttenuation_; 51 | Scalar linearAttenuation_; 52 | Scalar quadraticAttenuation_; 53 | Scalar spotCutoff_; 54 | Scalar spotPower_; 55 | Vector direction_; 56 | Ptr shadowMap_; 57 | Matrix transform_; // Light-space transform (for shadow mappping) 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /include/sfr/StreamDrawBuffer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * March, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Provides an interface for efficiently streaming GPU data (e.g. particles) */ 14 | class StreamDrawBuffer : public Interface { 15 | public: 16 | static GLuint const SIZE = 8 * (1 << 20); // 8 MB 17 | 18 | StreamDrawBuffer(GLuint elementSize, GLuint size=SIZE); 19 | ~StreamDrawBuffer(); 20 | 21 | GLuint vertexArrayId() const { return vertexArrayId_; } 22 | GLuint id() const { return id_; } 23 | GLuint size() const { return size_; } 24 | void bufferDataIs(GLenum type, void const* buffer, GLuint elements); 25 | 26 | private: 27 | void reset(); 28 | GLuint elementSize_; 29 | GLuint vertexArrayId_; 30 | GLuint id_; 31 | GLuint offset_; 32 | GLuint size_; 33 | }; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/sfr/Text.hpp: -------------------------------------------------------------------------------- 1 | /* Simple, Fast Renderer (SFR) * 2 | * CS249b * 3 | * Matt Fichman * 4 | * February, 2014 * 5 | *****************************************************************************/ 6 | 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Color.hpp" 12 | #include "sfr/Program.hpp" 13 | #include "sfr/AttributeBuffer.hpp" 14 | 15 | namespace sfr { 16 | 17 | class TextVertex { 18 | public: 19 | GLvec2 position; 20 | GLvec2 texCoord; 21 | }; 22 | 23 | class Text : public Node { 24 | public: 25 | enum Status { SYNCED, DIRTY }; 26 | enum Attribute { POSITION, TEXCOORD, TEXSIZE }; 27 | Text(); 28 | ~Text(); 29 | 30 | std::string const& text() const { return text_; } 31 | Ptr font() const { return font_; } 32 | GLuint id() const { return id_; } 33 | Status status() const { return status_; } 34 | Color color() const { return color_; } 35 | GLfloat size() const { return size_; } 36 | Ptr buffer() const { return buffer_; } 37 | 38 | void textIs(std::string const& string); 39 | void fontIs(Ptr font); 40 | void statusIs(Status status); 41 | void colorIs(Color const& color); 42 | void sizeIs(GLfloat size); 43 | 44 | virtual void operator()(Ptr functor); 45 | private: 46 | void defAttribute(Attribute id, GLuint size, void* offset); 47 | void updateTextBuffer(); 48 | void syncHardwareBuffer(); 49 | 50 | std::string text_; 51 | Ptr font_; 52 | GLuint id_; 53 | Status status_; 54 | Color color_; 55 | GLfloat size_; 56 | Ptr> buffer_; 57 | }; 58 | 59 | class TextProgram : public Program { 60 | public: 61 | TextProgram(std::string const& name) : Program(name) {} 62 | 63 | GLint texture() const { return texture_; } 64 | GLint transform() const { return transform_; } 65 | GLint color() const { return color_; } 66 | GLint sdf() const { return sdf_; } 67 | 68 | private: 69 | void onLink(); 70 | 71 | GLint texture_ = -1; 72 | GLint transform_ = -1; 73 | GLint color_ = -1; 74 | GLint sdf_ = -1; // Signed distance field font if true 75 | }; 76 | 77 | } 78 | -------------------------------------------------------------------------------- /include/sfr/TextRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders text */ 15 | class TextRenderer : public Renderer { 16 | public: 17 | TextRenderer(Ptr manager); 18 | void operator()(Ptr text); 19 | 20 | using Renderer::operator(); 21 | 22 | private: 23 | void onState(); 24 | Ptr program_; 25 | }; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/sfr/Texture.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | namespace sfr { 12 | 13 | /* Manages texture data */ 14 | class Texture : public Interface { 15 | public: 16 | Texture(std::string const& name); 17 | ~Texture(); 18 | std::string const& name() const; 19 | GLuint width() const; 20 | GLuint height() const; 21 | GLuint id() const; 22 | 23 | void widthIs(GLuint width); 24 | void heightIs(GLuint height); 25 | void dataIs(const GLubyte* pixels); 26 | 27 | private: 28 | std::string name_; 29 | GLuint id_; 30 | GLuint width_; 31 | GLuint height_; 32 | }; 33 | 34 | }; 35 | -------------------------------------------------------------------------------- /include/sfr/TextureLoader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AssetTable.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Loads images using SFML */ 15 | class TextureLoader : public AssetTable::Listener { 16 | public: 17 | TextureLoader(Ptr notifier) : AssetTable::Listener(notifier) {} 18 | void onAsset(Ptr texture); 19 | void onAsset(Ptr cubemap); 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /include/sfr/Transform.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Quaternion.hpp" 12 | #include "sfr/Matrix.hpp" 13 | #include "sfr/Vector.hpp" 14 | #include "sfr/Iterator.hpp" 15 | 16 | namespace sfr { 17 | 18 | /* Rotation, translation, scaling node with children. */ 19 | class Transform : public Node { 20 | public: 21 | enum ShadowMode { SHADOWED, UNSHADOWED }; 22 | enum TransformMode { INHERIT, WORLD }; 23 | enum RenderMode { VISIBLE, INVISIBLE }; 24 | 25 | Transform(std::string const& name); 26 | 27 | Matrix const& transform() const; 28 | Vector position() const; 29 | Quaternion rotation() const; 30 | Iterator>> children(); 31 | std::string const& name() const; 32 | ShadowMode shadowMode() const; // Render shadows, or not? 33 | TransformMode transformMode() const; // Inherit transform from parent? 34 | RenderMode renderMode() const; // Render this node & children, or not? 35 | Ptr clone() const; 36 | Ptr nodeClone() const; 37 | 38 | void transformIs(Matrix const& transform); 39 | void positionIs(Vector const& position); 40 | void rotationIs(Quaternion const& rotation); 41 | void shadowModeIs(ShadowMode mode); 42 | void transformModeIs(TransformMode mode); 43 | void renderModeIs(RenderMode mode); 44 | 45 | template Ptr childIs(Arg... arg); 46 | template Ptr child(GLuint index) const; 47 | 48 | void childIs(Ptr child); 49 | void childDel(Ptr child); 50 | 51 | void operator()(Ptr functor); 52 | 53 | private: 54 | std::vector> children_; 55 | Matrix transform_; 56 | std::string name_; 57 | ShadowMode shadowMode_; 58 | TransformMode transformMode_; 59 | RenderMode renderMode_; 60 | }; 61 | 62 | template 63 | Ptr Transform::childIs(Arg... arg) { 64 | Ptr child(new T(arg...)); 65 | children_.push_back(child); 66 | return child; 67 | } 68 | 69 | template 70 | Ptr Transform::child(GLuint index) const { 71 | return std::dynamic_pointer_cast(children_[index]); 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /include/sfr/TransformUpdater.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Node.hpp" 11 | #include "sfr/Matrix.hpp" 12 | 13 | namespace sfr { 14 | 15 | /* Updates node transformations in the scene graph */ 16 | class TransformUpdater : public Node::Functor { 17 | public: 18 | void operator()(Ptr scene); 19 | void operator()(Ptr transform); 20 | void operator()(Ptr camera); 21 | void operator()(Ptr model); 22 | void operator()(Ptr light); 23 | void operator()(Ptr light); 24 | void operator()(Ptr light); 25 | void operator()(Ptr particles); 26 | void operator()(Ptr ribbon); 27 | void operator()(Ptr billboards); 28 | void operator()(Ptr quad); 29 | void operator()(Ptr text); 30 | void operator()(Ptr decals); 31 | void operator()(Ptr ui); 32 | void transformIs(Matrix const& transform); 33 | template void submit(Ptr obj, Matrix const& transform); 34 | private: 35 | Ptr scene_; 36 | Matrix transform_; 37 | Rect rect_; 38 | bool ui_; 39 | }; 40 | 41 | 42 | template 43 | void TransformUpdater::submit(Ptr obj, Matrix const& transform) { 44 | Matrix save = transform_; 45 | transform_ = transform; 46 | operator()(obj); 47 | transform_ = save; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /include/sfr/TransparencyRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Renderer.hpp" 11 | 12 | namespace sfr { 13 | 14 | /* Renders transparent meshes with a flat shading technique. */ 15 | class TransparencyRenderer : public Renderer { 16 | public: 17 | TransparencyRenderer(Ptr manager); 18 | void operator()(Ptr model); 19 | void operator()(Ptr mesh); 20 | void operator()(Ptr material); 21 | void operator()(Ptr buffer); 22 | void operator()(Ptr buffer); 23 | void operator()(Ptr buffer); 24 | 25 | using Renderer::operator(); 26 | 27 | private: 28 | virtual void onState(); 29 | Ptr program_; 30 | Ptr activeProgram_; 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /include/sfr/UiRenderer.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #pragma once 9 | 10 | #include "sfr/Common.hpp" 11 | #include "sfr/Node.hpp" 12 | #include "sfr/Matrix.hpp" 13 | #include "sfr/Ui.hpp" 14 | 15 | namespace sfr { 16 | 17 | /* Renders user-interface components, rooted at a "Ui"-type node */ 18 | class UiRenderer : public Node::Functor { 19 | public: 20 | UiRenderer(Ptr assets); 21 | void operator()(Ptr scene); 22 | void operator()(Ptr quad); 23 | void operator()(Ptr text); 24 | 25 | private: 26 | Ptr scene_; 27 | Ptr textProgram_; 28 | Ptr quadProgram_; 29 | Ptr quad_; 30 | Rect rect_; 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /include/sfr/Vector.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | 11 | std::ostream& operator<<(std::ostream& out, sfr::Vector const& vector); 12 | std::istream& operator>>(std::istream& in, sfr::Vector& vector); 13 | 14 | namespace sfr { 15 | 16 | /* 3-dimensional vector utility class */ 17 | class Vector { 18 | public: 19 | 20 | Vector(Scalar x, Scalar y, Scalar z); 21 | Vector(); 22 | 23 | Scalar length() const; 24 | Scalar lengthSquared() const; 25 | Scalar distance(Vector const& other) const; 26 | Scalar distanceSquared(Vector const& other) const; 27 | Scalar dot(Vector const& other) const; 28 | Vector cross(Vector const& other) const; 29 | Vector operator+(Vector const& other) const; 30 | Vector operator-(Vector const& other) const; 31 | Vector operator*(Vector const& other) const; 32 | Vector operator/(Vector const& other) const; 33 | Vector operator/(Scalar s) const; 34 | Vector operator-() const; 35 | Vector operator*(Scalar s) const; 36 | Vector& operator+=(Vector const& other); 37 | Vector& operator-=(Vector const& other); 38 | Vector project(Vector const& other) const; 39 | Vector unit() const; 40 | Vector orthogonal() const; 41 | Vector lerp(Vector const& other, Scalar alpha) const; 42 | GLvec3 vec3f() const; 43 | 44 | friend std::ostream& ::operator<<(std::ostream& out, Vector const& vector); 45 | friend std::istream& ::operator>>(std::istream& in, Vector& vector); 46 | 47 | bool operator<(Vector const& other) const; 48 | bool operator==(Vector const& other) const; 49 | bool operator!=(Vector const& other) const; 50 | 51 | static Vector ZERO; 52 | static Vector UNIT_X; 53 | static Vector UNIT_Y; 54 | static Vector UNIT_Z; 55 | 56 | Scalar x; 57 | Scalar y; 58 | Scalar z; 59 | }; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/sfr/WavefrontLoader.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | #pragma once 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AssetTable.hpp" 11 | #include "sfr/Vector.hpp" 12 | #include "sfr/Mesh.hpp" 13 | #include "sfr/AttributeBuffer.hpp" 14 | #include "sfr/Box.hpp" 15 | 16 | namespace sfr { 17 | 18 | /* Loads Wavefront OBJ files */ 19 | class WavefrontLoader : public AssetTable::Listener { 20 | public: 21 | WavefrontLoader(Ptr notifier) : AssetTable::Listener(notifier) {}; 22 | void onAsset(Ptr transform); 23 | 24 | private: 25 | void newModel(std::istream& in); 26 | void newMesh(); 27 | void newVertex(std::istream& in); 28 | void newTexCoord(std::istream& in); 29 | void newNormal(std::istream& in); 30 | void newMaterialLibrary(std::string const& name); 31 | void newMesh(std::string const& name); 32 | void newTriangle(std::istream& in); 33 | void newTriangle(MeshVertex face[3]); 34 | 35 | Ptr assetManager_; 36 | Ptr transform_; 37 | Ptr mesh_; 38 | Ptr material_; 39 | Ptr> attributeBuffer_; 40 | Ptr indexBuffer_; 41 | Ptr program_; 42 | std::map cache_; 43 | std::vector texCoord_; 44 | std::vector position_; 45 | std::vector normal_; 46 | Box bounds_; 47 | }; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /include/sfr/sfr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Matt Fichman 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, APEXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "AssetTable.hpp" 26 | #include "AssetLoader.hpp" 27 | #include "AttributeBuffer.hpp" 28 | #include "Billboards.hpp" 29 | #include "BillboardRenderer.hpp" 30 | #include "Camera.hpp" 31 | #include "Color.hpp" 32 | #include "Common.hpp" 33 | #include "Cubemap.hpp" 34 | #include "Decals.hpp" 35 | #include "DecalRenderer.hpp" 36 | #include "DeferredRenderer.hpp" 37 | #include "BoundsRenderer.hpp" 38 | #include "DepthRenderTarget.hpp" 39 | #include "Program.hpp" 40 | #include "ProgramLoader.hpp" 41 | #include "FlatRenderer.hpp" 42 | #include "Font.hpp" 43 | #include "FontLoader.hpp" 44 | #include "Frustum.hpp" 45 | #include "HemiLight.hpp" 46 | #include "IndexBuffer.hpp" 47 | #include "Interface.hpp" 48 | #include "Iterator.hpp" 49 | #include "LightRenderer.hpp" 50 | #include "Material.hpp" 51 | #include "ModelRenderer.hpp" 52 | #include "Matrix.hpp" 53 | #include "Mesh.hpp" 54 | #include "Model.hpp" 55 | #include "Node.hpp" 56 | #include "NullFunctor.hpp" 57 | #include "Particles.hpp" 58 | #include "ParticleRenderer.hpp" 59 | #include "PointLight.hpp" 60 | #include "Ptr.hpp" 61 | #include "Quad.hpp" 62 | #include "QuadRenderer.hpp" 63 | #include "Quaternion.hpp" 64 | #include "Ribbon.hpp" 65 | #include "RibbonRenderer.hpp" 66 | #include "Shader.hpp" 67 | #include "ShadowRenderer.hpp" 68 | #include "SkyboxRenderer.hpp" 69 | #include "SpotLight.hpp" 70 | #include "Text.hpp" 71 | #include "TextRenderer.hpp" 72 | #include "Texture.hpp" 73 | #include "TextureLoader.hpp" 74 | #include "Transform.hpp" 75 | #include "TransformUpdater.hpp" 76 | #include "TransparencyRenderer.hpp" 77 | #include "Ui.hpp" 78 | #include "UiRenderer.hpp" 79 | #include "Vector.hpp" 80 | #include "WavefrontLoader.hpp" 81 | #include "Scene.hpp" 82 | -------------------------------------------------------------------------------- /install-sfml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | wget http://www.sfml-dev.org/files/SFML-2.2-sources.zip 3 | unzip SFML-2.2-sources.zip 4 | cd SFML-2.2 && cmake -G "Unix Makefiles" && make && sudo make install 5 | -------------------------------------------------------------------------------- /meshes/Blade.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Blade.blend' 2 | # Material Count: 4 3 | 4 | newmtl Material 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | 13 | newmtl Material.001 14 | Ns 96.078431 15 | Ka 0.000000 0.000000 0.000000 16 | Kd 0.640000 0.640000 0.640000 17 | Ks 0.500000 0.500000 0.500000 18 | Ni 1.000000 19 | d 1.000000 20 | illum 2 21 | 22 | newmtl Material.002 23 | Ns 96.078431 24 | Ka 0.000000 0.000000 0.000000 25 | Kd 0.640000 0.640000 0.640000 26 | Ks 0.500000 0.500000 0.500000 27 | Ni 1.000000 28 | d 1.000000 29 | illum 2 30 | 31 | newmtl Material.004 32 | Ns 96.078431 33 | Ka 0.000000 0.000000 0.000000 34 | Kd 0.640000 0.640000 0.640000 35 | Ks 0.500000 0.500000 0.500000 36 | Ni 1.000000 37 | d 1.000000 38 | illum 2 39 | -------------------------------------------------------------------------------- /meshes/Insurrector.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Insurrector.blend' 2 | # Material Count: 4 3 | 4 | newmtl Material 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | 13 | newmtl Material.001 14 | Ns 96.078431 15 | Ka 0.000000 0.000000 0.000000 16 | Kd 0.640000 0.640000 0.640000 17 | Ks 0.500000 0.500000 0.500000 18 | Ni 1.000000 19 | d 1.000000 20 | illum 2 21 | 22 | newmtl Material.002 23 | Ns 96.078431 24 | Ka 0.000000 0.000000 0.000000 25 | Kd 0.640000 0.640000 0.640000 26 | Ks 0.500000 0.500000 0.500000 27 | Ni 1.000000 28 | d 1.000000 29 | illum 2 30 | 31 | newmtl Material.003 32 | Ns 96.078431 33 | Ka 0.000000 0.000000 0.000000 34 | Kd 0.640000 0.640000 0.640000 35 | Ks 0.500000 0.500000 0.500000 36 | Ni 1.000000 37 | d 1.000000 38 | illum 2 39 | -------------------------------------------------------------------------------- /meshes/Lexus.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/Lexus.blend -------------------------------------------------------------------------------- /meshes/LightShapes.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/LightShapes.blend -------------------------------------------------------------------------------- /meshes/LightShapes.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'LightShapes.blend' 2 | # Material Count: 1 3 | 4 | newmtl None 5 | Ns 0 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.8 0.8 0.8 8 | Ks 0.8 0.8 0.8 9 | d 1 10 | illum 2 11 | -------------------------------------------------------------------------------- /meshes/Outrider.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/Outrider.blend -------------------------------------------------------------------------------- /meshes/Outrider.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Outrider.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | -------------------------------------------------------------------------------- /meshes/Plane.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/Plane.blend -------------------------------------------------------------------------------- /meshes/Plane.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Plane.blend' 2 | # Material Count: 0 3 | newmtl Metal 4 | Kd 1.0 1.0 1.0 5 | Ks 1.0 1.0 1.0 6 | Ka 1.0 1.0 1.0 7 | Ns 10. 8 | map_Kd textures/SandDiffuse.png 9 | map_bump textures/MetalNormal.png 10 | 11 | -------------------------------------------------------------------------------- /meshes/Quad.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/Quad.blend -------------------------------------------------------------------------------- /meshes/Quad.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Quad.blend' 2 | # Material Count: 1 3 | 4 | newmtl None 5 | Ns 0 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.8 0.8 0.8 8 | Ks 0.8 0.8 0.8 9 | d 1 10 | illum 2 11 | -------------------------------------------------------------------------------- /meshes/Quad.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.69 (sub 0) OBJ File: 'Quad.blend' 2 | # www.blender.org 3 | mtllib Quad.mtl 4 | o Quad 5 | v -0.500000 -0.500000 -0.000000 6 | v 0.500000 -0.500000 0.000000 7 | v -0.500000 0.500000 -0.000000 8 | v 0.500000 0.500000 0.000000 9 | vt 1.000000 1.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 0.000000 12 | vt 0.000000 0.000000 13 | vn 0.000000 -0.000000 -1.000000 14 | usemtl None 15 | s off 16 | f 2/1/1 1/2/1 4/3/1 17 | f 1/2/1 3/4/1 4/3/1 18 | -------------------------------------------------------------------------------- /meshes/Shield.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Shield.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.000000 0.149146 0.800000 8 | Ks 0.000000 0.000000 0.000000 9 | Ni 1.000000 10 | d 0.2 11 | illum 1 12 | shader shaders/Shield 13 | -------------------------------------------------------------------------------- /meshes/SmoothSphere.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/SmoothSphere.blend -------------------------------------------------------------------------------- /meshes/SmoothSphere.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Plane.blend' 2 | # Material Count: 0 3 | newmtl Plane 4 | Kd 1.0 1.0 1.0 5 | Ks 1.0 1.0 1.0 6 | Ka 1.0 1.0 1.0 7 | Ns 40. 8 | map_Kd textures/MetalDiffuse.png 9 | map_Ks textures/MetalSpecular.png 10 | map_bump textures/MetalNormal.png 11 | -------------------------------------------------------------------------------- /meshes/UnitCube.mtl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/meshes/UnitCube.mtl -------------------------------------------------------------------------------- /shaders/Billboard.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform sampler2D tex; 11 | uniform vec4 tint; 12 | 13 | in vec2 texCoord; 14 | in vec4 color; 15 | 16 | out vec4 colorOut; 17 | 18 | void main() { 19 | colorOut = tint * color * texture(tex, texCoord); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /shaders/Billboard.geom: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform mat4 transform; 11 | 12 | layout (points) in; 13 | layout (triangle_strip) out; 14 | layout (max_vertices = 4) out; 15 | 16 | in Vertex { 17 | vec3 position; 18 | vec3 forward; 19 | vec3 right; 20 | vec4 color; 21 | float width; 22 | float height; 23 | } vertex[]; 24 | 25 | out vec2 texCoord; 26 | out vec4 color; 27 | 28 | void main() { 29 | vec3 pos = vertex[0].position; 30 | vec3 f = vertex[0].forward * vertex[0].width / 2; 31 | vec3 r = vertex[0].right * vertex[0].height / 2; 32 | 33 | color = vertex[0].color; 34 | 35 | gl_Position = transform * vec4(pos - f + r, 1); 36 | texCoord = vec2(0, 1); 37 | EmitVertex(); 38 | 39 | gl_Position = transform * vec4(pos - f - r, 1); 40 | texCoord = vec2(0, 0); 41 | EmitVertex(); 42 | 43 | gl_Position = transform * vec4(pos + f + r, 1); 44 | texCoord = vec2(1, 1); 45 | EmitVertex(); 46 | 47 | gl_Position = transform * vec4(pos + f - r, 1); 48 | texCoord = vec2(1, 0); 49 | EmitVertex(); 50 | } 51 | -------------------------------------------------------------------------------- /shaders/Billboard.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform mat4 transform; 11 | uniform mat4 normalMatrix; 12 | 13 | layout(location=0) in vec3 positionIn; 14 | layout(location=1) in vec3 forwardIn; 15 | layout(location=2) in vec3 rightIn; 16 | layout(location=3) in vec4 colorIn; 17 | layout(location=4) in float widthIn; 18 | layout(location=5) in float heightIn; 19 | 20 | out Vertex { 21 | vec3 position; 22 | vec3 forward; 23 | vec3 right; 24 | vec4 color; 25 | float width; 26 | float height; 27 | } vertex; 28 | 29 | /* Billboard shader */ 30 | void main() { 31 | // Simply pass vertices thru. We need to extrude 4 corners from the 32 | // position in the geometry shader, and this must be done in model space. 33 | vertex.position = positionIn; 34 | vertex.forward = forwardIn; 35 | vertex.right = rightIn; 36 | vertex.color = colorIn; 37 | vertex.width = widthIn; 38 | vertex.height = heightIn; 39 | } 40 | -------------------------------------------------------------------------------- /shaders/Camera.inc.glsl: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2016 * 6 | *****************************************************************************/ 7 | 8 | layout (std140) uniform camera { 9 | mat4 projectionMatrix; 10 | mat4 projectionMatrixInv; 11 | mat4 viewMatrix; 12 | mat4 viewMatrixInv; 13 | mat4 viewProjectionMatrix; 14 | mat4 viewProjectionMatrixInv; 15 | }; 16 | -------------------------------------------------------------------------------- /shaders/Decals.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Camera.inc.glsl" 10 | 11 | uniform sampler2D tex; 12 | uniform sampler2D depthBuffer; 13 | 14 | uniform mat4 decalMatrix; // From _view space_ (!!) to decal space 15 | 16 | in vec4 position; 17 | 18 | out vec4 color; 19 | 20 | void main() { 21 | // Normalize the coordinates 22 | vec2 normalized = position.xy/position.w; 23 | 24 | // Viewport (x, y) coordinates of pixel, range: [0, 1] 25 | vec2 viewport = (normalized.xy + 1.)/2.; 26 | 27 | // Sample the depth and reconstruct the fragment view coordinates. 28 | // Make sure the depth is unpacked into clip coordinates. 29 | float depth = texture(depthBuffer, viewport).r; 30 | 31 | // Reconstructed clip space coordinates of pixel, range: [-1, 1] 32 | vec3 clip = vec3(normalized, 2. * depth - 1.); 33 | 34 | // Transform the clip coordinates back into view space 35 | vec4 viewRaw = projectionMatrixInv * vec4(clip, 1.); 36 | vec3 view = viewRaw.xyz/viewRaw.w; 37 | 38 | // Transform to decal space (range: [0, 1]) 39 | vec4 decal = decalMatrix * vec4(view, 1); 40 | decal = (decal+1.f)/2.f; 41 | 42 | if (decal.z < 0 || decal.x < 0 || decal.z > 1 || decal.x > 1 || decal.y < 0 || decal.y > 1) { 43 | discard; 44 | } else { 45 | color = texture(tex, decal.xy); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shaders/Decals.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform mat4 transform; 11 | 12 | layout(location=0) in vec3 positionIn; 13 | 14 | out vec4 position; 15 | 16 | /* Deferred render point light shader */ 17 | void main() { 18 | // Transform the vertex to get the clip-space position of the vertex 19 | gl_Position = position = transform * vec4(positionIn, 1); 20 | } 21 | -------------------------------------------------------------------------------- /shaders/Flat.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | out vec4 color; 11 | 12 | /* Very fast simple solid-color shader for rendering to depth */ 13 | void main() { 14 | color = vec4(1., 1., 1., 1.); 15 | } 16 | -------------------------------------------------------------------------------- /shaders/Flat.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | 13 | /* Very fast simple solid-color shader for rendering to depth */ 14 | void main() { 15 | // Transform the vertex to get the clip-space position of the vertex 16 | gl_Position = transform * vec4(positionIn, 1); 17 | } 18 | -------------------------------------------------------------------------------- /shaders/HemiLight.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.frag" 10 | 11 | uniform float atten0; 12 | uniform float atten1; 13 | uniform float atten2; 14 | uniform vec3 Ld; // Diffuse light intensity 15 | uniform vec3 Ldb; // Diffuse light intensity (back) 16 | uniform vec3 Ls; // Specular light intensity 17 | uniform vec3 La; // Ambient light intensity 18 | uniform vec3 direction; 19 | 20 | in vec3 lightPosition; 21 | 22 | out vec4 color; 23 | 24 | /* Deferred point light shader */ 25 | void main() { 26 | LightingInfo li = lightingInfo(); 27 | float shadow = shadowDefault(li); 28 | 29 | // Sample the normal and the view vector 30 | vec3 V = normalize(li.view); 31 | vec3 R = reflect(V, li.N); 32 | vec3 L = normalize(-direction); 33 | float D = length(li.view - lightPosition); 34 | float atten = 1./(atten0 + atten1 * D + atten2 * D * D); 35 | 36 | float Rd = dot(li.N, L); 37 | //float Rd = clamp(dot(li.N, L), 0, 1); 38 | //float Rd = (dot(li.N, L)+1)/2; 39 | // 1: front light color 40 | // -1: back light color 41 | 42 | // Calculate the diffuse color coefficient by mixing front & back 43 | 44 | // Calculate specular color coefficient 45 | vec3 specular = li.Ks * Ls * pow(max(0., dot(L, R)), li.alpha); 46 | 47 | if (Rd > 0) { 48 | vec3 diffuse = li.Kd * Ld * Rd;//* mix(Ldb, Ld, Rd); 49 | color.rgb = (diffuse + specular) * shadow; 50 | } else { 51 | vec3 diffuse = li.Kd * Ldb * -Rd;//* mix(Ldb, Ld, Rd); 52 | color.rgb = diffuse; 53 | // FIXME: Two-sided lighting model: Need to shadow the unlit side as 54 | // well. Currently, on the unlit side, we just ignore the shadow value. 55 | } 56 | color.rgb += li.Ke; // Emissive 57 | color.rgb += La * li.Kd; // Ambient 58 | color.a = 1; 59 | } 60 | -------------------------------------------------------------------------------- /shaders/HemiLight.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.vert" 10 | -------------------------------------------------------------------------------- /shaders/Light.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | uniform mat4 modelViewMatrix; 9 | uniform mat4 transform; 10 | 11 | layout(location=0) in vec3 positionIn; 12 | 13 | out vec4 position; 14 | out vec3 lightPosition; 15 | 16 | /* Deferred render point light shader */ 17 | void main() { 18 | // Transform the vertex to get the clip-space position of the vertex 19 | gl_Position = position = transform * vec4(positionIn, 1); 20 | lightPosition = (modelViewMatrix * vec4(0, 0, 0, 1)).xyz; 21 | } 22 | -------------------------------------------------------------------------------- /shaders/Mesh.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | 9 | layout(location=0) in vec3 positionIn; 10 | layout(location=1) in vec3 normalIn; 11 | layout(location=2) in vec3 tangentIn; 12 | layout(location=3) in vec2 texCoordIn; 13 | 14 | -------------------------------------------------------------------------------- /shaders/Model.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform sampler2D diffuseMap; 11 | uniform sampler2D specularMap; 12 | uniform sampler2D normalMap; 13 | uniform sampler2D emissiveMap; 14 | 15 | uniform vec3 Kd; 16 | uniform vec3 Ks; 17 | uniform vec3 Ka; 18 | uniform vec3 Ke; 19 | uniform float alpha; 20 | 21 | in vec3 normal; 22 | in vec3 tangent; 23 | in vec2 texCoord; 24 | 25 | layout(location=0) out vec3 material; 26 | layout(location=1) out vec4 specular; 27 | layout(location=2) out vec3 normalOut; 28 | layout(location=3) out vec3 emissive; 29 | 30 | /* Deferred render shader with normal, specular, and diffuse mapping */ 31 | void main() { 32 | 33 | // Get the normal from the normal map texture and unpack it 34 | vec3 Tn = normalize((texture(normalMap, texCoord) * 2. - 1.).xyz); 35 | 36 | // Create the TBN matrix from the normalized T and N vectors 37 | vec3 N = normalize(normal); 38 | vec3 T = normalize(tangent); 39 | vec3 B = cross(N, T); 40 | mat3 TBN = mat3(T, B, N); 41 | 42 | // Sample the diffuse and specular texture 43 | vec3 Td = texture(diffuseMap, texCoord).rgb; 44 | vec3 Ts = texture(specularMap, texCoord).rgb; 45 | vec3 Te = texture(emissiveMap, texCoord).rgb; 46 | 47 | // Save diffuse material parameters 48 | material = Td * Kd; 49 | 50 | // Save the specular material parameters (with shininess) 51 | specular.rgb = Ts * Ks; 52 | specular.a = alpha/1024; 53 | // Shininess must be in the range [0-1000]. This is required to scale down 54 | // the shininess to 8 bits, so that "converted" shininess above 1.0f 55 | // doesn't get clamped. 56 | 57 | // Save the normal vector in view space 58 | normalOut = (TBN * Tn + 1.) / 2.; 59 | 60 | // Emissive color 61 | emissive = Te * Ke; 62 | } 63 | -------------------------------------------------------------------------------- /shaders/Model.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | uniform mat3 normalMatrix; 13 | 14 | out vec3 normal; 15 | out vec3 tangent; 16 | out vec2 texCoord; 17 | 18 | /* Deferred render shader with normal, specular, and diffuse mapping */ 19 | void main() { 20 | // Transform the vertex to get the clip-space position of the vertex 21 | gl_Position = transform * vec4(positionIn, 1); 22 | 23 | // Transform the normal and tangent by the normal matrix 24 | normal = normalMatrix * normalIn; 25 | tangent = normalMatrix * tangentIn; 26 | 27 | // Simply copy the texture coordinates over to the fragment shader 28 | texCoord = texCoordIn; 29 | } 30 | -------------------------------------------------------------------------------- /shaders/Particles.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Camera.inc.glsl" 10 | 11 | uniform sampler2D tex; 12 | uniform sampler2D depthBuffer; 13 | uniform vec4 tint; 14 | 15 | in float alpha; 16 | in float rotation; 17 | in float viewZ; 18 | in vec2 texCoord; 19 | in vec4 color; 20 | in vec4 position; 21 | 22 | out vec4 colorOut; 23 | 24 | void main() { 25 | float x = texCoord.s - 0.5; 26 | float y = texCoord.t - 0.5; 27 | float s = x * cos(rotation) - y * sin(rotation) + 0.5; 28 | float t = x * sin(rotation) + y * cos(rotation) + 0.5; 29 | 30 | // Soft particles 31 | vec2 normalized = position.xy/position.w; 32 | vec2 viewport = (normalized.xy + 1.)/2.; 33 | 34 | float depth = texture(depthBuffer, viewport).r; 35 | vec3 clip = vec3(normalized, 2. * depth - 1.); 36 | vec4 view = projectionMatrixInv * vec4(clip, 1.); 37 | view /= view.w; 38 | 39 | float scale = 4.f; 40 | float fade = clamp((viewZ - view.z) * scale, 0, 1); 41 | 42 | colorOut = color * tint * texture(tex, vec2(s, t)); 43 | colorOut.a *= fade; // Soft particles 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /shaders/Particles.geom: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Camera.inc.glsl" 10 | 11 | layout (points) in; 12 | layout (triangle_strip) out; 13 | layout (max_vertices = 4) out; 14 | 15 | in Vertex { 16 | vec4 position; 17 | vec4 color; 18 | float rotation; 19 | float size; 20 | } vertex[]; 21 | 22 | out vec4 color; 23 | out vec2 texCoord; 24 | out float alpha; 25 | out float rotation; 26 | out vec4 position; // Clip-space position for soft particles 27 | out float viewZ; // View-space z coordinate for soft particles 28 | 29 | void main() { 30 | 31 | if (vertex[0].color.a <= 0) { 32 | return; // Discard invisible primitives 33 | } 34 | 35 | vec3 pos = vertex[0].position.xyz; 36 | color = vertex[0].color; 37 | rotation = vertex[0].rotation; 38 | viewZ = vertex[0].position.z; 39 | 40 | float s = vertex[0].size / 2; 41 | 42 | gl_Position = position = projectionMatrix * vec4(pos + vec3(-s, -s, 0), 1); 43 | texCoord = vec2(0, 1); 44 | EmitVertex(); 45 | 46 | gl_Position = position = projectionMatrix * vec4(pos + vec3(s, -s, 0), 1); 47 | texCoord = vec2(0, 0); 48 | EmitVertex(); 49 | 50 | gl_Position = position = projectionMatrix * vec4(pos + vec3(-s, s, 0), 1); 51 | texCoord = vec2(1, 1); 52 | EmitVertex(); 53 | 54 | gl_Position = position = projectionMatrix * vec4(pos + vec3(s, s, 0), 1); 55 | texCoord = vec2(1, 0); 56 | EmitVertex(); 57 | } 58 | -------------------------------------------------------------------------------- /shaders/Particles.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform mat4 modelViewMatrix; 11 | 12 | layout(location=0) in vec3 positionIn; 13 | layout(location=1) in vec4 colorIn; 14 | layout(location=2) in float sizeIn; 15 | layout(location=3) in float rotationIn; 16 | 17 | out Vertex { 18 | vec4 position; 19 | vec4 color; 20 | float rotation; 21 | float size; 22 | } vertex; 23 | 24 | 25 | /* Particle shader */ 26 | void main() { 27 | vertex.position = modelViewMatrix * vec4(positionIn, 1); 28 | vertex.color = colorIn; 29 | vertex.rotation = rotationIn; 30 | vertex.size = sizeIn; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /shaders/PointLight.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.frag" 10 | 11 | uniform float atten0; 12 | uniform float atten1; 13 | uniform float atten2; 14 | uniform vec3 Ld; 15 | uniform vec3 Ls; 16 | 17 | in vec3 lightPosition; 18 | 19 | out vec4 color; 20 | 21 | /* Deferred point light shader */ 22 | void main() { 23 | LightingInfo li = lightingInfo(); 24 | 25 | vec3 V = normalize(-li.view); 26 | vec3 R = reflect(-V, li.N); 27 | vec3 L = lightPosition - li.view; 28 | float D = length(L); 29 | float atten = 1./(atten0 + atten1 * D + atten2 * D * D); 30 | L = normalize(L); 31 | 32 | float Rd = dot(li.N, L); 33 | if (Rd > 0.) { 34 | // Calculate the diffuse color coefficient 35 | vec3 diffuse = li.Kd * Ld * Rd; 36 | 37 | // Calculate the specular color coefficient 38 | vec3 specular = li.Ks * Ls * pow(max(0., dot(L, R)), li.alpha); 39 | 40 | color = vec4(diffuse + specular, 1.); 41 | color.rgb *= atten; 42 | } else { 43 | color = vec4(0., 0., 0., 1.); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /shaders/PointLight.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.vert" 10 | -------------------------------------------------------------------------------- /shaders/Quad.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform sampler2D tex; 11 | uniform vec4 tint; 12 | 13 | in vec2 texCoord; 14 | out vec4 color; 15 | 16 | void main() { 17 | color = tint * texture(tex, texCoord); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /shaders/Quad.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | 13 | out vec2 texCoord; 14 | 15 | /* Particle shader */ 16 | void main() { 17 | gl_Position = transform * vec4(positionIn, 1); 18 | texCoord = texCoordIn; 19 | } 20 | -------------------------------------------------------------------------------- /shaders/Ribbon.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform sampler2D tex; 11 | 12 | in vec2 texCoord; 13 | in float alpha; 14 | out vec4 color; 15 | 16 | void main() { 17 | color = texture(tex, texCoord); 18 | color.a *= alpha; 19 | } 20 | -------------------------------------------------------------------------------- /shaders/Ribbon.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Camera.inc.glsl" 10 | 11 | uniform mat4 modelViewMatrix; 12 | uniform mat3 normalMatrix; 13 | uniform float width; 14 | uniform float minWidth; 15 | uniform int tail; 16 | uniform int count; 17 | 18 | layout(location=0) in vec3 positionIn; 19 | layout(location=1) in vec3 directionIn; 20 | layout(location=2) in int indexIn; 21 | 22 | out vec2 texCoord; 23 | out float alpha; 24 | 25 | void main() { 26 | 27 | float t = 1. - float(tail-indexIn) / float(count+1); 28 | float side = float((2 * (indexIn % 2)) - 1); 29 | // If the index is 0 mod 2, then set side == -1; else side == +1. This 30 | // basically causes the triangle strip vertices to alternate in zig-zag 31 | // fashion to either side of the center points of the ribbon. 32 | 33 | vec4 pos = modelViewMatrix * vec4(positionIn, 1); 34 | float w = minWidth + (width-minWidth) * t; 35 | vec3 forward = normalize(normalMatrix * directionIn); 36 | vec3 look = normalize(pos.xyz); 37 | vec3 right = normalize(cross(look, forward)); 38 | 39 | gl_Position = projectionMatrix * vec4(pos + vec4(right * side * w / 2, 0)); 40 | 41 | texCoord = vec2(.5, indexIn % 2); 42 | alpha = 4 * t; 43 | } 44 | -------------------------------------------------------------------------------- /shaders/Shield.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform vec3 Kd; 11 | uniform float alpha; 12 | 13 | in vec3 normal; 14 | 15 | out vec4 color; 16 | 17 | /* Transparency forward-rendered shader (no lighting :( ) */ 18 | void main() { 19 | color = vec4(Kd, alpha); 20 | 21 | float a = clamp(dot(normalize(normal), vec3(0, 0, 1)), 0, 1); 22 | 23 | //color.a *= a; 24 | //color = vec4(a); 25 | color.a *= 1-pow(a, .5);//pow(a, );//pow(a, 4); 26 | //color.a = a(1-a); 27 | //color = vec4(normalize(normal), 1.); 28 | } 29 | -------------------------------------------------------------------------------- /shaders/Shield.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | uniform mat3 normalMatrix; 13 | 14 | out vec3 normal; 15 | 16 | /* Deferred render point light shader */ 17 | void main() { 18 | // Transform the vertex to get the clip-space position of the vertex 19 | gl_Position = transform * vec4(positionIn, 1); 20 | normal = normalize(normalMatrix * normalIn); 21 | } 22 | -------------------------------------------------------------------------------- /shaders/Skybox.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform samplerCube cubeMap; 11 | in vec3 texCoord; 12 | out vec4 color; 13 | 14 | void main() { 15 | color = texture(cubeMap, normalize(texCoord)); 16 | vec3 oj = vec3(1, .8, .5); 17 | vec3 oj2 = vec3(1, .6, 0); 18 | color.rgb += 2. * oj * pow(max(0, dot(normalize(texCoord), vec3(-1, 0, 0))), 200); 19 | //color.rgb += .9 * oj2 * max(0, dot(normalize(texCoord), vec3(-1, 0, 0))); 20 | //color.rgb += .2 * oj2; 21 | } 22 | -------------------------------------------------------------------------------- /shaders/Skybox.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | 13 | out vec3 texCoord; 14 | 15 | void main() { 16 | gl_Position = transform * vec4(positionIn, 1); 17 | // Set z=w so that the skydome is always on the far z plane 18 | gl_Position.z = gl_Position.w; // Requires glDepthFunc(GL_LEQUAL): 19 | 20 | // Use the skymesh vertex position, in local space, 21 | // as an index into the cubemap 22 | texCoord = positionIn; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /shaders/SpotLight.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.frag" 10 | 11 | uniform float atten0; 12 | uniform float atten1; 13 | uniform float atten2; 14 | uniform vec3 Ld; // Diffuse light intensity 15 | uniform vec3 Ls; // Specular light intensity 16 | uniform float spotCutoff; 17 | uniform float spotPower; 18 | uniform vec3 direction; 19 | 20 | in vec3 lightPosition; 21 | 22 | out vec4 color; // Output to color buffer 23 | 24 | /* Deferred spot light shader */ 25 | void main() { 26 | LightingInfo li = lightingInfo(); 27 | float shadow = shadowPoissonPcf(li); 28 | 29 | // Sample the normal and the view vector 30 | vec3 V = normalize(li.view); // View vec 31 | vec3 R = reflect(V, li.N); 32 | vec3 L = lightPosition - li.view; 33 | float D = length(L); 34 | float atten = 1./(atten0 + atten1 * D + atten2 * D * D); 35 | L = normalize(L); 36 | 37 | float Rd = dot(li.N, L); 38 | float spotEffect = clamp(dot(direction, -L), 0., 1.); 39 | 40 | if (Rd > 0. && spotEffect > spotCutoff) { 41 | // Calculate the diffuse color coefficient 42 | vec3 diffuse = li.Kd * Ld * Rd; 43 | 44 | // Calculate the specular color coefficient 45 | vec3 specular = li.Ks * Ls * pow(max(0., dot(L, R)), li.alpha); 46 | 47 | // Calculate the shadow coord 48 | color = vec4(diffuse + specular, 1.); 49 | color.rgb *= shadow * atten * pow(spotEffect, spotPower); 50 | } else { 51 | color = vec4(0., 0., 0., 1.); 52 | } 53 | // FIXME: Luminance mapping (make optional) 54 | // float lum = 0.2216*color.r + 0.7152*color.g + 0.0722*color.b; 55 | // float lumd = lum / (1+lum); 56 | 57 | //color.rgb *= lumd; 58 | } 59 | -------------------------------------------------------------------------------- /shaders/SpotLight.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Light.vert" 10 | -------------------------------------------------------------------------------- /shaders/Text.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform sampler2D tex; 11 | uniform vec4 color; 12 | uniform bool sdf; 13 | 14 | in vec2 texCoord; 15 | 16 | out vec4 colorOut; 17 | 18 | void signedDistanceField() { 19 | float mask = texture(tex, texCoord).r; 20 | float alpha; 21 | if (mask < .5) { 22 | alpha = 0.; 23 | } else { 24 | alpha = 1.; 25 | } 26 | //alpha *= smoothstep(.1, .9, mask); 27 | alpha *= smoothstep(.25, .75, mask); 28 | colorOut.rgb = color.rgb; 29 | colorOut.a = alpha * color.a; 30 | } 31 | 32 | void standard() { 33 | float alpha = texture(tex, texCoord).r; 34 | colorOut.rgb = color.rgb; 35 | colorOut.a = alpha * color.a; 36 | } 37 | 38 | void main() { 39 | if (sdf) { 40 | signedDistanceField(); 41 | } else { 42 | standard(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /shaders/Text.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform mat4 transform; 11 | 12 | layout(location=0) in vec2 positionIn; 13 | layout(location=1) in vec2 texCoordIn; 14 | 15 | out vec2 texCoord; 16 | 17 | /* Text shader */ 18 | void main() { 19 | gl_Position = transform * vec4(positionIn, 0, 1); 20 | texCoord = texCoordIn; 21 | } 22 | -------------------------------------------------------------------------------- /shaders/Texture.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | 9 | #version 330 10 | 11 | uniform sampler2D diffuseMap; 12 | 13 | in vec2 texCoord; 14 | 15 | out vec4 color; 16 | 17 | 18 | 19 | void main() { 20 | color = texture(diffuseMap, texCoord); 21 | color = vec4(1., 0., 0., 1.); 22 | } 23 | -------------------------------------------------------------------------------- /shaders/Texture.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | out vec2 texCoord; 12 | 13 | /* Simple shader for rendering a full-screen quad */ 14 | void main() { 15 | gl_Position = vec4(positionIn, 1.); 16 | texCoord = texCoordIn; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /shaders/Transparency.frag: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | 10 | uniform vec3 Kd; 11 | uniform float alpha; 12 | 13 | out vec4 color; 14 | 15 | /* Transparency forward-rendered shader (no lighting :( ) */ 16 | void main() { 17 | color = vec4(Kd, alpha); 18 | } 19 | -------------------------------------------------------------------------------- /shaders/Transparency.vert: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #version 330 9 | #pragma include "shaders/Mesh.vert" 10 | 11 | uniform mat4 transform; 12 | 13 | /* Deferred render point light shader */ 14 | void main() { 15 | // Transform the vertex to get the clip-space position of the vertex 16 | gl_Position = transform * vec4(positionIn, 1); 17 | } 18 | -------------------------------------------------------------------------------- /src/AlphaRenderer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/AlphaRenderer.hpp" 10 | #include "sfr/BillboardRenderer.hpp" 11 | #include "sfr/ParticleRenderer.hpp" 12 | #include "sfr/RibbonRenderer.hpp" 13 | #include "sfr/QuadRenderer.hpp" 14 | #include "sfr/TextRenderer.hpp" 15 | #include "sfr/TransparencyRenderer.hpp" 16 | 17 | using namespace sfr; 18 | 19 | AlphaRenderer::AlphaRenderer(Ptr assets) { 20 | transparencyRenderer_.reset(new TransparencyRenderer(assets)); 21 | particleRenderer_.reset(new ParticleRenderer(assets)); 22 | ribbonRenderer_.reset(new RibbonRenderer(assets)); 23 | billboardRenderer_.reset(new BillboardRenderer(assets)); 24 | quadRenderer_.reset(new QuadRenderer(assets)); 25 | textRenderer_.reset(new TextRenderer(assets)); 26 | } 27 | 28 | void AlphaRenderer::onState() { 29 | if (state() == Renderer::ACTIVE) { 30 | // Nothing 31 | } else if (state() == Renderer::INACTIVE) { 32 | rendererIs(0); 33 | } else { 34 | assert(!"Invalid state"); 35 | } 36 | } 37 | 38 | void AlphaRenderer::rendererIs(Ptr renderer) { 39 | if (renderer_ != renderer) { 40 | if (renderer_) { 41 | renderer_->stateIs(Renderer::INACTIVE); 42 | } 43 | renderer_ = renderer; 44 | if (renderer_) { 45 | renderer_->sceneIs(scene()); 46 | renderer_->stateIs(Renderer::ACTIVE); 47 | } 48 | } 49 | if (renderer_) { 50 | renderer_->worldMatrixIs(worldMatrix()); 51 | } 52 | } 53 | 54 | void AlphaRenderer::operator()(Ptr model) { 55 | rendererIs(transparencyRenderer_); 56 | transparencyRenderer_->operator()(model); 57 | } 58 | 59 | void AlphaRenderer::operator()(Ptr particles) { 60 | rendererIs(particleRenderer_); 61 | particleRenderer_->operator()(particles); 62 | } 63 | 64 | void AlphaRenderer::operator()(Ptr ribbon) { 65 | rendererIs(ribbonRenderer_); 66 | ribbonRenderer_->operator()(ribbon); 67 | } 68 | 69 | void AlphaRenderer::operator()(Ptr billboards) { 70 | rendererIs(billboardRenderer_); 71 | billboardRenderer_->operator()(billboards); 72 | } 73 | 74 | void AlphaRenderer::operator()(Ptr quad) { 75 | rendererIs(quadRenderer_); 76 | quadRenderer_->operator()(quad); 77 | } 78 | 79 | void AlphaRenderer::operator()(Ptr text) { 80 | rendererIs(textRenderer_); 81 | textRenderer_->operator()(text); 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/AssetLoader.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2014 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/AssetLoader.hpp" 10 | #include "sfr/FontLoader.hpp" 11 | #include "sfr/ProgramLoader.hpp" 12 | #include "sfr/TextureLoader.hpp" 13 | #include "sfr/WavefrontLoader.hpp" 14 | 15 | using namespace sfr; 16 | 17 | AssetLoader::AssetLoader(Ptr assets) { 18 | fontLoader_.reset(new FontLoader(assets)); 19 | meshLoader_.reset(new WavefrontLoader(assets)); 20 | programLoader_.reset(new ProgramLoader(assets)); 21 | textureLoader_.reset(new TextureLoader(assets)); 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/AttributeBuffer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/AttributeBuffer.hpp" 10 | 11 | using namespace sfr; 12 | 13 | AttributeBuffer::AttributeBuffer(std::string const& name, GLenum usage) { 14 | name_ = name; 15 | id_ = 0; 16 | status_ = DIRTY; 17 | usage_ = usage; 18 | } 19 | 20 | AttributeBuffer::~AttributeBuffer() { 21 | if (id_) { 22 | glDeleteBuffers(1, &id_); 23 | } 24 | } 25 | 26 | GLuint AttributeBuffer::id() const { 27 | return id_; 28 | } 29 | 30 | std::string const& AttributeBuffer::name() const { 31 | return name_; 32 | } 33 | 34 | void AttributeBuffer::statusIs(Status status) { 35 | if (status_ == status) { 36 | return; 37 | } 38 | if (SYNCED == status) { 39 | syncHardwareBuffers(); 40 | } 41 | 42 | status_ = status; 43 | } 44 | 45 | void AttributeBuffer::syncHardwareBuffers() { 46 | if (!id_) { 47 | glGenBuffers(1, &id_); 48 | } 49 | GLuint size = elementCount()*elementSize(); 50 | glBindBuffer(GL_ARRAY_BUFFER, id_); 51 | glBufferData(GL_ARRAY_BUFFER, size, 0, usage_); 52 | glBufferData(GL_ARRAY_BUFFER, size, data(), usage_); 53 | } 54 | -------------------------------------------------------------------------------- /src/Billboards.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Billboards.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Billboards::Billboards() { 14 | clearMode_ = MANUAL; 15 | blendMode_ = ADDITIVE; 16 | tint_ = Color(1., 1., 1., 1.); 17 | } 18 | 19 | Billboard const& Billboards::billboard(GLuint index) const { 20 | return buffer_[index]; 21 | } 22 | 23 | void Billboards::billboardEnq(Billboard const& billboard) { 24 | buffer_.push_back(billboard); 25 | } 26 | 27 | void Billboards::billboardIs(GLuint index, Billboard const& billboard) { 28 | if (buffer_.size() <= index) { 29 | buffer_.resize(index+1); 30 | } 31 | buffer_[index] = billboard; 32 | } 33 | 34 | void Billboards::billboardDelAll() { 35 | buffer_.clear(); 36 | } 37 | 38 | void Billboards::textureIs(Ptr texture) { 39 | texture_ = texture; 40 | } 41 | 42 | void Billboards::tintIs(sfr::Color tint) { 43 | tint_ = tint; 44 | } 45 | 46 | void Billboards::clearModeIs(ClearMode mode) { 47 | clearMode_ = mode; 48 | } 49 | 50 | void Billboards::blendModeIs(BlendMode mode) { 51 | blendMode_ = mode; 52 | } 53 | 54 | void Billboards::operator()(Ptr functor) { 55 | functor->operator()(std::static_pointer_cast(shared_from_this())); 56 | } 57 | 58 | void BillboardProgram::onLink() { 59 | texture_ = glGetUniformLocation(id(), "tex"); 60 | transform_ = glGetUniformLocation(id(), "transform"); 61 | tint_ = glGetUniformLocation(id(), "tint"); 62 | 63 | // Set texture samplers 64 | glUniform1i(texture_, 0); 65 | } 66 | -------------------------------------------------------------------------------- /src/Box.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Box.hpp" 11 | #include "sfr/Frustum.hpp" 12 | 13 | using namespace sfr; 14 | 15 | Box::Box(Frustum const& frustum) { 16 | Scalar inf = std::numeric_limits::max(); 17 | min = sfr::Vector(inf, inf, inf); 18 | max = sfr::Vector(-inf, -inf, -inf); 19 | 20 | pointIs(frustum.nearTopLeft); 21 | pointIs(frustum.nearTopRight); 22 | pointIs(frustum.nearBottomLeft); 23 | pointIs(frustum.nearBottomRight); 24 | 25 | pointIs(frustum.farTopLeft); 26 | pointIs(frustum.farTopRight); 27 | pointIs(frustum.farBottomLeft); 28 | pointIs(frustum.farBottomRight); 29 | 30 | } 31 | 32 | void Box::pointIs(Vector const& point) { 33 | if (point.x < min.x) { 34 | min.x = point.x; 35 | } else if (point.x > max.x) { 36 | max.x = point.x; 37 | } 38 | if (point.y < min.y) { 39 | min.y = point.y; 40 | } else if (point.y > max.y) { 41 | max.y = point.y; 42 | } 43 | if (point.z < min.z) { 44 | min.z = point.z; 45 | } else if (point.z > max.z) { 46 | max.z = point.z; 47 | } 48 | } 49 | 50 | Vector Box::center() const { 51 | Vector center; 52 | center.x = (max.x+min.x)/2.f; 53 | center.y = (max.y+min.y)/2.f; 54 | center.z = (max.z+min.z)/2.f; 55 | return center; 56 | } 57 | -------------------------------------------------------------------------------- /src/Color.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Color.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Color::Color() : 14 | red(0.0f), 15 | green(0.0f), 16 | blue(0.0f), 17 | alpha(1.0f) { 18 | } 19 | 20 | Color::Color(Scalar red, Scalar green, Scalar blue, Scalar alpha) : 21 | red(red), 22 | green(green), 23 | blue(blue), 24 | alpha(alpha) { 25 | } 26 | 27 | GLvec4 28 | Color::vec4f() const { 29 | return GLvec4(red, green, blue, alpha); 30 | } 31 | 32 | Color Color::operator*(Scalar scale) const { 33 | return Color(red*scale, green*scale, blue*scale, alpha*scale); 34 | } 35 | 36 | Color Color::operator+(Color const& other) const { 37 | return Color(red+other.red, blue+other.blue, green+other.green, alpha+other.alpha); 38 | } 39 | 40 | std::ostream& operator<<(std::ostream& out, Color const& color) { 41 | return out << color.red << " " << color.blue << " " 42 | << color.green << " " << color.alpha; 43 | } 44 | 45 | std::istream& operator>>(std::istream& in, Color& color) { 46 | return in >> color.red >> color.green >> color.blue; 47 | } 48 | -------------------------------------------------------------------------------- /src/Common.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | // This file exists solely to generate precompiled headers for the rest of 9 | // the project 10 | #include "sfr/Common.hpp" 11 | -------------------------------------------------------------------------------- /src/Cubemap.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Cubemap.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Cubemap::Cubemap(std::string const& name) { 14 | name_ = name; 15 | width_ = 0; 16 | height_ = 0; 17 | glGenTextures(1, &id_); 18 | glBindTexture(GL_TEXTURE_CUBE_MAP, id_); 19 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 20 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 21 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 22 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 23 | } 24 | 25 | Cubemap::~Cubemap() { 26 | glDeleteTextures(1, &id_); 27 | } 28 | 29 | std::string const& Cubemap::name() const { 30 | return name_; 31 | } 32 | 33 | GLuint Cubemap::width() const { 34 | return width_; 35 | } 36 | 37 | GLuint Cubemap::height() const { 38 | return height_; 39 | } 40 | 41 | GLuint Cubemap::id() const { 42 | return id_; 43 | } 44 | 45 | void Cubemap::widthIs(GLuint width) { 46 | width_ = width; 47 | } 48 | 49 | void Cubemap::heightIs(GLuint height) { 50 | height_ = height; 51 | } 52 | 53 | void Cubemap::dataIs(const GLubyte* pixels) { 54 | glBindTexture(GL_TEXTURE_CUBE_MAP, id_); 55 | for (GLuint i = 0; i < 6; ++i) { 56 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA8, width_, height_, 57 | 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 58 | } 59 | glGenerateMipmap(GL_TEXTURE_CUBE_MAP); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/Decals.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Decals.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Decal const& Decals::decal(GLuint index) const { 14 | return decal_[index]; 15 | } 16 | 17 | void Decals::decalEnq(Decal const& decal) { 18 | decal_.push_back(decal); 19 | } 20 | 21 | void Decals::decalIs(GLuint index, Decal const& decal) { 22 | if (decal_.size() <= index) { 23 | decal_.resize(index+1); 24 | } 25 | decal_[index] = decal; 26 | } 27 | 28 | void Decals::decalDelAll() { 29 | decal_.clear(); 30 | } 31 | 32 | void Decals::textureIs(Ptr texture) { 33 | texture_ = texture; 34 | } 35 | 36 | void Decals::operator()(Ptr functor) { 37 | functor->operator()(std::static_pointer_cast(shared_from_this())); 38 | } 39 | 40 | void DecalProgram::onLink() { 41 | transform_ = glGetUniformLocation(id(), "transform"); 42 | texture_ = glGetUniformLocation(id(), "tex"); 43 | depthBuffer_ = glGetUniformLocation(id(), "depthBuffer"); 44 | unproject_ = glGetUniformLocation(id(), "unprojectMatrix"); 45 | decalMatrix_ = glGetUniformLocation(id(), "decalMatrix"); 46 | 47 | // Set texture samplers 48 | glUniform1i(texture_, 0); 49 | // FIXME: This depends on the depth component being bound to location 4 50 | glUniform1i(depthBuffer_, 4); 51 | } 52 | -------------------------------------------------------------------------------- /src/FlatRenderer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/AssetTable.hpp" 10 | #include "sfr/AttributeBuffer.hpp" 11 | #include "sfr/Camera.hpp" 12 | #include "sfr/FlatRenderer.hpp" 13 | #include "sfr/IndexBuffer.hpp" 14 | #include "sfr/Material.hpp" 15 | #include "sfr/Mesh.hpp" 16 | #include "sfr/Model.hpp" 17 | #include "sfr/Scene.hpp" 18 | 19 | using namespace sfr; 20 | 21 | FlatRenderer::FlatRenderer(Ptr manager, bool shadowPass) { 22 | program_ = manager->assetIs("shaders/Flat"); 23 | program_->statusIs(Program::LINKED); 24 | shadowPass_ = shadowPass; 25 | } 26 | 27 | void FlatRenderer::onState() { 28 | if (state() == Renderer::ACTIVE) { 29 | glUseProgram(program_->id()); 30 | glEnable(GL_DEPTH_TEST); 31 | } else if (state() == Renderer::INACTIVE) { 32 | glDisable(GL_DEPTH_TEST); 33 | } else { 34 | assert(!"Invalid state"); 35 | } 36 | } 37 | 38 | void FlatRenderer::operator()(Ptr model) { 39 | if (shadowPass_ && model->material()->opacity() < 1.f) { 40 | return; 41 | } 42 | operator()(model->mesh()); 43 | } 44 | 45 | void FlatRenderer::operator()(Ptr mesh) { 46 | if (!mesh || !mesh->indexBuffer() || !scene() || !scene()->camera()) { 47 | return; 48 | } 49 | mesh->statusIs(Mesh::SYNCED); 50 | 51 | // Pass the model matrix to the vertex shader 52 | Ptr camera = scene()->camera(); 53 | Matrix const transform = camera->viewProjectionMatrix() * worldMatrix(); 54 | glUniformMatrix4fv(program_->transform(), 1, 0, transform.mat4f()); 55 | 56 | // Render the mesh 57 | Ptr buffer = mesh->indexBuffer(); 58 | glBindVertexArray(mesh->id()); 59 | glDrawElements(GL_TRIANGLES, buffer->elementCount(), GL_UNSIGNED_INT, 0); 60 | glBindVertexArray(0); 61 | } 62 | -------------------------------------------------------------------------------- /src/IndexBuffer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/IndexBuffer.hpp" 10 | 11 | using namespace sfr; 12 | 13 | IndexBuffer::IndexBuffer(std::string const& name) { 14 | name_ = name; 15 | id_ = 0; 16 | status_ = DIRTY; 17 | } 18 | 19 | IndexBuffer::~IndexBuffer() { 20 | if (id_) { 21 | glDeleteBuffers(1, &id_); 22 | } 23 | } 24 | 25 | GLuint IndexBuffer::id() const { 26 | return id_; 27 | } 28 | 29 | std::string const& IndexBuffer::name() const { 30 | return name_; 31 | } 32 | 33 | GLuint IndexBuffer::elementCount() const { 34 | return GLuint(element_.size()); 35 | } 36 | 37 | GLuint IndexBuffer::elementSize() const { 38 | return sizeof(GLuint); 39 | } 40 | 41 | GLuint const& IndexBuffer::element(GLuint index) const { 42 | return element_[index]; 43 | } 44 | 45 | void IndexBuffer::statusIs(Status status) { 46 | if (status_ == status) { 47 | return; 48 | } 49 | if (SYNCED == status) { 50 | syncHardwareBuffers(); 51 | } 52 | 53 | status_ = status; 54 | } 55 | 56 | void IndexBuffer::elementCountIs(GLuint count) { 57 | if (count == element_.size()) { 58 | return; 59 | } 60 | element_.resize(count); 61 | statusIs(DIRTY); 62 | } 63 | 64 | void IndexBuffer::elementIs(GLuint index, GLuint element) { 65 | if (index >= elementCount()) { 66 | elementCountIs(index + 1); 67 | } 68 | element_[index] = element; 69 | statusIs(DIRTY); 70 | } 71 | 72 | void IndexBuffer::syncHardwareBuffers() { 73 | if (!id_) { 74 | glGenBuffers(1, &id_); 75 | } 76 | GLuint size = elementCount()*elementSize(); 77 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id_); 78 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data(), GL_STATIC_DRAW); 79 | } 80 | 81 | const void* IndexBuffer::data() const { 82 | return element_.empty() ? 0 : &element_[0]; 83 | } 84 | -------------------------------------------------------------------------------- /src/Light.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Light.hpp" 10 | 11 | namespace sfr { 12 | 13 | void LightProgram::onLink() { 14 | shadowMap_ = glGetUniformLocation(id(), "shadowMap"); 15 | shadowMapSize_ = glGetUniformLocation(id(), "shadowMapSize"); 16 | diffuseBuffer_ = glGetUniformLocation(id(), "diffuseBuffer"); 17 | specularBuffer_ = glGetUniformLocation(id(), "specularBuffer"); 18 | normalBuffer_ = glGetUniformLocation(id(), "normalBuffer"); 19 | emissiveBuffer_ = glGetUniformLocation(id(), "emissiveBuffer"); 20 | depthBuffer_ = glGetUniformLocation(id(), "depthBuffer"); 21 | diffuse_ = glGetUniformLocation(id(), "Ld"); 22 | specular_ = glGetUniformLocation(id(), "Ls"); 23 | ambient_ = glGetUniformLocation(id(), "La"); 24 | backDiffuse_ = glGetUniformLocation(id(), "Ldb"); 25 | atten0_ = glGetUniformLocation(id(), "atten0"); 26 | atten1_ = glGetUniformLocation(id(), "atten1"); 27 | atten2_ = glGetUniformLocation(id(), "atten2"); 28 | spotCutoff_ = glGetUniformLocation(id(), "spotCutoff"); 29 | spotPower_ = glGetUniformLocation(id(), "spotPower"); 30 | direction_ = glGetUniformLocation(id(), "direction"); 31 | transform_ = glGetUniformLocation(id(), "transform"); 32 | modelView_ = glGetUniformLocation(id(), "modelViewMatrix"); 33 | unproject_ = glGetUniformLocation(id(), "unprojectMatrix"); 34 | light_ = glGetUniformLocation(id(), "lightMatrix"); 35 | 36 | // Set texture samplers: FixMe: This depends on DeferredRenderTarget! 37 | glUniform1i(diffuseBuffer_, 0); 38 | glUniform1i(specularBuffer_, 1); 39 | glUniform1i(normalBuffer_, 2); 40 | glUniform1i(emissiveBuffer_, 3); 41 | glUniform1i(depthBuffer_, 4); 42 | glUniform1i(shadowMap_, 5); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/Model.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Model.hpp" 10 | #include "sfr/Material.hpp" 11 | 12 | using namespace sfr; 13 | 14 | Model::Model() { 15 | userData_ = 0; 16 | } 17 | 18 | Ptr Model::material() const { 19 | return material_; 20 | } 21 | 22 | Ptr Model::mesh() const { 23 | return mesh_; 24 | } 25 | 26 | Ptr Model::clone() const { 27 | Ptr clone(new Model); 28 | clone->materialIs(material()->clone()); 29 | clone->meshIs(mesh()); 30 | clone->programIs(program()); 31 | return clone; 32 | } 33 | 34 | Ptr Model::program() const { 35 | return program_; 36 | } 37 | 38 | Ptr Model::nodeClone() const { 39 | return Ptr(clone()); 40 | } 41 | 42 | void* Model::userData() const { 43 | return userData_; 44 | } 45 | 46 | void Model::materialIs(Ptr material) { 47 | material_ = material; 48 | } 49 | 50 | void Model::meshIs(Ptr mesh) { 51 | mesh_ = mesh; 52 | } 53 | 54 | void Model::programIs(Ptr program) { 55 | program_ = program; 56 | } 57 | 58 | void Model::userDataIs(void* data) { 59 | userData_ = data; 60 | } 61 | 62 | void Model::operator()(Ptr functor) { 63 | functor->operator()(std::static_pointer_cast(shared_from_this())); 64 | } 65 | 66 | void ModelProgram::onLink() { 67 | diffuseMap_ = glGetUniformLocation(id(), "diffuseMap"); 68 | specularMap_ = glGetUniformLocation(id(), "specularMap"); 69 | normalMap_ = glGetUniformLocation(id(), "normalMap"); 70 | emissiveMap_ = glGetUniformLocation(id(), "emissiveMap"); 71 | ambient_ = glGetUniformLocation(id(), "Ka"); 72 | diffuse_ = glGetUniformLocation(id(), "Kd"); 73 | specular_ = glGetUniformLocation(id(), "Ks"); 74 | emissive_ = glGetUniformLocation(id(), "Ke"); 75 | shininess_ = glGetUniformLocation(id(), "alpha"); 76 | opacity_ = glGetUniformLocation(id(), "alpha"); 77 | normalMatrix_ = glGetUniformLocation(id(), "normalMatrix"); 78 | transform_ = glGetUniformLocation(id(), "transform"); 79 | 80 | // Set texture samplers 81 | glUniform1i(diffuseMap_, 0); 82 | glUniform1i(specularMap_, 1); 83 | glUniform1i(normalMap_, 2); 84 | } 85 | -------------------------------------------------------------------------------- /src/NullFunctor.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/NullFunctor.hpp" 10 | #include "sfr/Scene.hpp" 11 | 12 | using namespace sfr; 13 | 14 | 15 | void NullFunctor::operator()(Ptr scene) { 16 | scene->root()->operator()(std::static_pointer_cast(shared_from_this())); 17 | } 18 | 19 | void NullFunctor::operator()(Ptr camera) { 20 | } 21 | 22 | void NullFunctor::operator()(Ptr transform) { 23 | for (Iterator>> node = transform->children(); node; node++) { 24 | node(std::static_pointer_cast(shared_from_this())); 25 | } 26 | } 27 | 28 | void NullFunctor::operator()(Ptr light) { 29 | } 30 | 31 | void NullFunctor::operator()(Ptr object) { 32 | } 33 | 34 | void NullFunctor::operator()(Ptr light) { 35 | } 36 | 37 | void NullFunctor::operator()(Ptr light) { 38 | } 39 | -------------------------------------------------------------------------------- /src/Particles.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/Particles.hpp" 11 | 12 | using namespace sfr; 13 | 14 | Particles::Particles() { 15 | clearMode_ = MANUAL; 16 | blendMode_ = ADDITIVE; 17 | tint_ = Color(1., 1., 1., 1.); 18 | } 19 | 20 | void Particles::particleEnq(Particle const& particle) { 21 | buffer_.push_back(particle); 22 | } 23 | 24 | void Particles::particleIs(GLuint index, Particle const& particle) { 25 | if (buffer_.size() <= index) { 26 | buffer_.resize(index+1); 27 | } 28 | buffer_[index] = particle; 29 | } 30 | 31 | void Particles::particleDelAll() { 32 | buffer_.clear(); 33 | } 34 | 35 | Particle const& Particles::particle(GLuint index) const { 36 | return buffer_[index]; 37 | } 38 | 39 | void Particles::textureIs(Ptr texture) { 40 | texture_ = texture; 41 | } 42 | 43 | void Particles::tintIs(Color const& tint) { 44 | tint_ = tint; 45 | } 46 | 47 | void Particles::clearModeIs(ClearMode mode) { 48 | clearMode_ = mode; 49 | } 50 | 51 | void Particles::blendModeIs(BlendMode mode) { 52 | blendMode_ = mode; 53 | } 54 | 55 | void Particles::operator()(Ptr functor) { 56 | functor->operator()(std::static_pointer_cast(shared_from_this())); 57 | } 58 | 59 | void ParticleProgram::onLink() { 60 | texture_ = glGetUniformLocation(id(), "tex"); 61 | tint_ = glGetUniformLocation(id(), "tint"); 62 | modelViewMatrix_ = glGetUniformLocation(id(), "modelViewMatrix"); 63 | projectionMatrix_ = glGetUniformLocation(id(), "projectionMatrix"); 64 | depthBuffer_ = glGetUniformLocation(id(), "depthBuffer"); 65 | unprojectMatrix_ = glGetUniformLocation(id(), "unprojectMatrix"); 66 | 67 | glUniform1i(texture_, 0); 68 | glUniform1i(depthBuffer_, 4); 69 | // FIXME: Depends on deferred renderer texture defs 70 | } 71 | -------------------------------------------------------------------------------- /src/PointLight.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/PointLight.hpp" 10 | 11 | using namespace sfr; 12 | 13 | PointLight::PointLight() { 14 | constantAttenuation_ = 1.0f; 15 | linearAttenuation_ = 1.; 16 | quadraticAttenuation_ = 0.0f; 17 | specularColor_ = Color(1.f, 1.f, 1.f, 1.f); 18 | diffuseColor_ = Color(1.f, 1.f, 1.f, 1.f); 19 | } 20 | 21 | bool PointLight::isVisible() const { 22 | return diffuseColor_.red > 0 || diffuseColor_.green > 0 || diffuseColor_.blue > 0 23 | || specularColor_.red > 0 || specularColor_.green > 0 || specularColor_.blue > 0; 24 | } 25 | 26 | Color const& PointLight::diffuseColor() const { 27 | return diffuseColor_; 28 | } 29 | 30 | Color const& PointLight::specularColor() const { 31 | return specularColor_; 32 | } 33 | 34 | Scalar PointLight::constantAttenuation() const { 35 | return constantAttenuation_; 36 | } 37 | 38 | Scalar PointLight::linearAttenuation() const { 39 | return linearAttenuation_; 40 | } 41 | 42 | Scalar PointLight::quadraticAttenuation() const { 43 | return quadraticAttenuation_; 44 | } 45 | 46 | Scalar PointLight::radiusOfEffect() const { 47 | Scalar a = quadraticAttenuation(); 48 | Scalar b = linearAttenuation(); 49 | Scalar c = constantAttenuation(); 50 | Scalar minIntensity = 0.01f; 51 | 52 | if (a != 0) { 53 | // Quadratic equation to find distance at which intensity 54 | // is below the threshold 55 | Scalar d1 = -b + sqrt(b*b - 4*a*(c - 1/minIntensity))/2/a; 56 | Scalar d2 = -b - sqrt(b*b - 4*a*(c - 1/minIntensity))/2/a; 57 | 58 | return std::max(d1, d2); 59 | } else { 60 | // If a == 0, then we use the slope instead. 61 | return (1 - minIntensity*c)/(minIntensity*b); 62 | } 63 | } 64 | 65 | void PointLight::diffuseColorIs(Color const& diffuse) { 66 | diffuseColor_ = diffuse; 67 | } 68 | 69 | void PointLight::specularColorIs(Color const& specular) { 70 | specularColor_ = specular; 71 | } 72 | 73 | void PointLight::constantAttenuationIs(Scalar atten) { 74 | constantAttenuation_ = atten; 75 | } 76 | 77 | void PointLight::linearAttenuationIs(Scalar atten) { 78 | linearAttenuation_ = atten; 79 | } 80 | 81 | void PointLight::quadraticAttenuationIs(Scalar atten) { 82 | quadraticAttenuation_ = atten; 83 | } 84 | 85 | void PointLight::operator()(Ptr functor) { 86 | functor->operator()(std::static_pointer_cast(shared_from_this())); 87 | } 88 | -------------------------------------------------------------------------------- /src/ProgramLoader.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/ProgramLoader.hpp" 10 | #include "sfr/Program.hpp" 11 | #include "sfr/Shader.hpp" 12 | 13 | using namespace sfr; 14 | 15 | void ProgramLoader::onAsset(Ptr program) { 16 | Ptr fragShader(notifier_->assetIs(program->name()+".frag", GL_FRAGMENT_SHADER)); 17 | Ptr vertShader(notifier_->assetIs(program->name()+".vert", GL_VERTEX_SHADER)); 18 | Ptr geomShader; 19 | 20 | if (assetExists(program->name()+".geom")) { 21 | geomShader = notifier_->assetIs(program->name()+".geom", GL_GEOMETRY_SHADER); 22 | } 23 | program->fragmentShaderIs(fragShader); 24 | program->vertexShaderIs(vertShader); 25 | program->geometryShaderIs(geomShader); 26 | program->statusIs(Program::LINKED); 27 | } 28 | 29 | void ProgramLoader::onAsset(Ptr shader) { 30 | std::string source = assetContents(shader->name()); 31 | 32 | size_t i = 0; 33 | while (i != std::string::npos) { 34 | std::string include; 35 | std::string const pragma = "#pragma include"; 36 | size_t start = i = source.find(pragma, i); 37 | if (i == std::string::npos) { continue; } 38 | i = i + pragma.size(); 39 | while (i != std::string::npos && source[i] == ' ') { 40 | ++i; // Skip whitespace 41 | } 42 | if (i != std::string::npos && source[i] == '"') { 43 | ++i; 44 | } else { 45 | continue; 46 | } 47 | while (i != std::string::npos && source[i] != '"' && source[i] != '\n') { 48 | include += source[i]; 49 | ++i; 50 | } 51 | i += 1; 52 | Ptr inc(notifier_->assetIs(include, shader->type())); 53 | source.replace(start, i-start, inc->source()); 54 | } 55 | 56 | shader->sourceIs(source); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/Quad.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Quad.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Quad::Quad() { 14 | mode_ = NORMAL; 15 | width_ = 1.f; 16 | height_ = 1.f; 17 | tint_ = sfr::Color(1.f, 1.f, 1.f, 1.f); 18 | } 19 | 20 | void Quad::textureIs(Ptr texture) { 21 | texture_ = texture; 22 | } 23 | 24 | void Quad::widthIs(Scalar width) { 25 | width_ = width; 26 | } 27 | 28 | void Quad::heightIs(Scalar height) { 29 | height_ = height; 30 | } 31 | 32 | void Quad::modeIs(Mode mode) { 33 | mode_ = mode; 34 | } 35 | 36 | void Quad::tintIs(sfr::Color tint) { 37 | tint_ = tint; 38 | } 39 | 40 | void Quad::operator()(Ptr functor) { 41 | functor->operator()(std::static_pointer_cast(shared_from_this())); 42 | } 43 | 44 | void QuadProgram::onLink() { 45 | texture_ = glGetUniformLocation(id(), "tex"); 46 | transform_ = glGetUniformLocation(id(), "transform"); 47 | tint_ = glGetUniformLocation(id(), "tint"); 48 | 49 | // Set texture samplers 50 | glUniform1i(texture_, 0); 51 | } 52 | -------------------------------------------------------------------------------- /src/RenderTarget.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * April, 2014 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/RenderTarget.hpp" 10 | 11 | using namespace sfr; 12 | 13 | RenderTarget::RenderTarget(GLuint width, GLuint height, GLuint format) { 14 | id_ = 0; 15 | glGenTextures(1, &id_); 16 | glBindTexture(GL_TEXTURE_2D, id_); 17 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 18 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 19 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 20 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 21 | 22 | if (format == GL_DEPTH_COMPONENT24) { 23 | // FIXME: Check for other depth component types 24 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); 25 | } else if (format == GL_DEPTH24_STENCIL8) { 26 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); 27 | } else { 28 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 29 | } 30 | } 31 | 32 | RenderTarget::~RenderTarget() { 33 | glDeleteTextures(1, &id_); 34 | } 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/Renderer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Renderer.hpp" 10 | #include "sfr/Transform.hpp" 11 | #include "sfr/Scene.hpp" 12 | 13 | namespace sfr { 14 | 15 | void Renderer::operator()(Ptr scene) { 16 | stateIs(ACTIVE); 17 | sceneIs(scene); 18 | for(Iterator> i = scene->renderDescs(); i; i++) { 19 | worldMatrixIs(i->worldMatrix()); 20 | i->node()->operator()(std::static_pointer_cast(shared_from_this())); 21 | } 22 | stateIs(Renderer::INACTIVE); 23 | } 24 | 25 | void Renderer::worldMatrixIs(Matrix const& transform) { 26 | worldMatrix_ = transform; 27 | } 28 | 29 | void Renderer::sceneIs(Ptr scene) { 30 | scene_ = scene; 31 | } 32 | 33 | void Renderer::stateIs(State state) { 34 | if (state_ != state) { 35 | state_ = state; 36 | onState(); 37 | } 38 | } 39 | 40 | Matrix const& Renderer::worldMatrix() const { 41 | return worldMatrix_; 42 | } 43 | 44 | Ptr Renderer::scene() const { 45 | return scene_; 46 | } 47 | 48 | Renderer::State Renderer::state() const { 49 | return state_; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/ResourceException.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/ResourceException.hpp" 10 | 11 | namespace sfr { 12 | 13 | ResourceException::ResourceException(std::string const& message) { 14 | message_ = message; 15 | std::cerr << "error: " << message << std::endl; 16 | #ifdef _WIN32 17 | #pragma warning(disable: 4996) // For getenv 18 | #endif 19 | if (!getenv("SFR_NO_DEBUG_EXCEPTIONS")) { 20 | abort(); 21 | } 22 | // By default, exceptions will abort the process, as per SFR's "panic" 23 | // -based exception model (exceptions indicate a programming error or 24 | // unrecoverable missing resource). However, this behavior can be changed 25 | // via the above environment variable. 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/Shader.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Shader.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Shader::Shader(std::string const& name, GLenum type) { 14 | name_ = name; 15 | id_ = 0; 16 | status_ = DIRTY; 17 | type_ = type; 18 | 19 | id_ = glCreateShader(type_); 20 | } 21 | 22 | Shader::~Shader() { 23 | glDeleteShader(id_); 24 | } 25 | 26 | std::string const& Shader::name() const { 27 | return name_; 28 | } 29 | 30 | GLenum Shader::type() const { 31 | return type_; 32 | } 33 | 34 | std::string const& Shader::source() const { 35 | return source_; 36 | } 37 | 38 | Shader::Status Shader::status() const { 39 | return status_; 40 | } 41 | 42 | GLuint Shader::id() const { 43 | return id_; 44 | } 45 | 46 | void Shader::sourceIs(std::string const& source) { 47 | if (source == source_) { 48 | return; 49 | } 50 | source_ = source; 51 | statusIs(DIRTY); 52 | } 53 | 54 | void Shader::statusIs(Status status) { 55 | if (status_ == status) { 56 | return; 57 | } 58 | if (COMPILED == status) { 59 | const GLchar* strings = source_.c_str(); 60 | GLint lengths = GLint(source_.length()); 61 | glShaderSource(id_, 1, &strings, &lengths); 62 | glCompileShader(id_); 63 | } 64 | status_ = status; 65 | } 66 | -------------------------------------------------------------------------------- /src/SkyboxRenderer.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Simple, Fast Renderer (SFR) * 4 | * CS249b * 5 | * Matt Fichman * 6 | * February, 2011 * 7 | *****************************************************************************/ 8 | 9 | #include "sfr/Common.hpp" 10 | #include "sfr/AssetTable.hpp" 11 | #include "sfr/Camera.hpp" 12 | #include "sfr/Cubemap.hpp" 13 | #include "sfr/IndexBuffer.hpp" 14 | #include "sfr/Mesh.hpp" 15 | #include "sfr/Program.hpp" 16 | #include "sfr/Scene.hpp" 17 | #include "sfr/SkyboxRenderer.hpp" 18 | 19 | using namespace sfr; 20 | 21 | SkyboxRenderer::SkyboxRenderer(Ptr manager) { 22 | program_ = manager->assetIs("shaders/Skybox"); 23 | program_->statusIs(Program::LINKED); 24 | unitSphere_ = manager->assetIs("meshes/LightShapes.obj/Sphere"); 25 | 26 | glUseProgram(program_->id()); 27 | transform_ = glGetUniformLocation(program_->id(), "transform"); 28 | glUseProgram(0); 29 | } 30 | 31 | 32 | void SkyboxRenderer::operator()(Ptr scene) { 33 | Ptr camera = scene->camera(); 34 | Ptr cubemap = scene->skybox(); 35 | if (!camera) { return; } 36 | if (!cubemap) { return; } 37 | 38 | glUseProgram(program_->id()); 39 | glEnable(GL_DEPTH_TEST); 40 | glDepthMask(GL_FALSE); 41 | glDepthFunc(GL_LEQUAL); 42 | scene_ = scene; 43 | 44 | Matrix const viewMatrix = Matrix::rotate(camera->viewMatrix().rotation()); 45 | Matrix const viewProjectionMatrix = camera->projectionMatrix() * viewMatrix; 46 | glUniformMatrix4fv(transform_, 1, 0, viewProjectionMatrix.mat4f()); 47 | 48 | glActiveTexture(GL_TEXTURE0); 49 | glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap->id()); 50 | 51 | Ptr mesh = unitSphere_; 52 | mesh->statusIs(Mesh::SYNCED); 53 | Ptr buffer = mesh->indexBuffer(); 54 | glBindVertexArray(mesh->id()); 55 | glDrawElements(GL_TRIANGLES, buffer->elementCount(), GL_UNSIGNED_INT, 0); 56 | glBindVertexArray(0); 57 | 58 | glDisable(GL_DEPTH_TEST); 59 | glDepthMask(GL_TRUE); 60 | glUseProgram(0); 61 | } 62 | -------------------------------------------------------------------------------- /src/StreamDrawBuffer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * March, 2014 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/StreamDrawBuffer.hpp" 10 | 11 | using namespace sfr; 12 | 13 | StreamDrawBuffer::StreamDrawBuffer(GLuint elementSize, GLuint size) { 14 | elementSize_ = elementSize; 15 | size_ = size; 16 | offset_ = 0; 17 | 18 | glGenBuffers(1, &id_); 19 | glGenVertexArrays(1, &vertexArrayId_); 20 | reset(); 21 | } 22 | 23 | StreamDrawBuffer::~StreamDrawBuffer() { 24 | glDeleteBuffers(1, &id_); 25 | glDeleteVertexArrays(1, &vertexArrayId_); 26 | } 27 | 28 | void StreamDrawBuffer::reset() { 29 | // Orphan or re-create the buffer 30 | glBindBuffer(GL_ARRAY_BUFFER, id_); 31 | glBufferData(GL_ARRAY_BUFFER, size_, 0, GL_STREAM_DRAW); // Orphan 32 | offset_ = 0; 33 | } 34 | 35 | void StreamDrawBuffer::bufferDataIs(GLenum type, void const* buffer, GLuint elements) { 36 | // Copy the buffer data to the CPU and issue a draw command 37 | GLuint const size = elements * elementSize_; 38 | GLuint const free = size_ - offset_; 39 | assert(size <= size_ && "stream draw buffer is too small"); 40 | if (free < size) { 41 | reset(); // Calls glBindBuffer 42 | } else { 43 | glBindBuffer(GL_ARRAY_BUFFER, id_); 44 | } 45 | 46 | GLint const flags = GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT|GL_MAP_INVALIDATE_RANGE_BIT; 47 | void* const map = glMapBufferRange(GL_ARRAY_BUFFER, offset_, size, flags); 48 | memcpy(map, buffer, size); 49 | glUnmapBuffer(GL_ARRAY_BUFFER); 50 | glBindVertexArray(vertexArrayId_); 51 | glDrawArrays(type, offset_/elementSize_, elements); 52 | glBindVertexArray(0); 53 | offset_ += size; 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/TextRenderer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/AssetTable.hpp" 10 | #include "sfr/AttributeBuffer.hpp" 11 | #include "sfr/Camera.hpp" 12 | #include "sfr/Font.hpp" 13 | #include "sfr/Text.hpp" 14 | #include "sfr/TextRenderer.hpp" 15 | #include "sfr/Scene.hpp" 16 | 17 | using namespace sfr; 18 | 19 | TextRenderer::TextRenderer(Ptr assets) { 20 | program_ = assets->assetIs("shaders/Text"); 21 | program_->statusIs(Program::LINKED); 22 | } 23 | 24 | void TextRenderer::onState() { 25 | if (state() == Renderer::ACTIVE) { 26 | glUseProgram(program_->id()); 27 | glEnable(GL_BLEND); 28 | glEnable(GL_DEPTH_TEST); 29 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 30 | glDepthMask(GL_FALSE); 31 | } else if (state() == Renderer::INACTIVE) { 32 | glDisable(GL_BLEND); 33 | glDisable(GL_DEPTH_TEST); 34 | glBlendFunc(GL_ONE, GL_ZERO); 35 | glDepthMask(GL_TRUE); 36 | } else { 37 | assert(!"Invalid state"); 38 | } 39 | } 40 | 41 | void TextRenderer::operator()(Ptr text) { 42 | Ptr camera = scene()->camera(); 43 | Ptr font = text->font(); 44 | if (!font) { return; } 45 | 46 | text->statusIs(Text::SYNCED); 47 | 48 | glActiveTexture(GL_TEXTURE0); 49 | glBindTexture(GL_TEXTURE_2D, font->id()); 50 | 51 | glUniform4fv(program_->color(), 1, text->color().vec4f()); 52 | glUniform1i(program_->sdf(), font->type()==Font::SDF); 53 | 54 | // Pass the matrices to the vertex shader 55 | Matrix const worldViewProjectionMatrix = camera->viewProjectionMatrix() * worldMatrix(); 56 | glUniformMatrix4fv(program_->transform(), 1, 0, worldViewProjectionMatrix.mat4f()); 57 | 58 | // Render the particles 59 | Ptr buffer = text->buffer(); 60 | glBindVertexArray(text->id()); 61 | glDrawArrays(GL_TRIANGLES, 0, buffer->elementCount()); 62 | glBindVertexArray(0); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/Texture.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Texture.hpp" 10 | 11 | using namespace sfr; 12 | 13 | Texture::Texture(std::string const& name) { 14 | name_ = name; 15 | width_ = 0; 16 | height_ = 0; 17 | glGenTextures(1, &id_); 18 | glBindTexture(GL_TEXTURE_2D, id_); 19 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 20 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 21 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 22 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 23 | } 24 | 25 | Texture::~Texture() { 26 | glDeleteTextures(1, &id_); 27 | } 28 | 29 | std::string const& Texture::name() const { 30 | return name_; 31 | } 32 | 33 | GLuint Texture::width() const { 34 | return width_; 35 | } 36 | 37 | GLuint Texture::height() const { 38 | return height_; 39 | } 40 | 41 | GLuint Texture::id() const { 42 | return id_; 43 | } 44 | 45 | void Texture::widthIs(GLuint width) { 46 | width_ = width; 47 | } 48 | 49 | void Texture::heightIs(GLuint height) { 50 | height_ = height; 51 | } 52 | 53 | void Texture::dataIs(const GLubyte* pixels) { 54 | glBindTexture(GL_TEXTURE_2D, id_); 55 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width_, height_, 0, GL_RGBA, 56 | GL_UNSIGNED_BYTE, pixels); 57 | glGenerateMipmap(GL_TEXTURE_2D); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/TextureLoader.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Simple, Fast Renderer (SFR) * 3 | * CS249b * 4 | * Matt Fichman * 5 | * February, 2011 * 6 | *****************************************************************************/ 7 | 8 | #include "sfr/Common.hpp" 9 | #include "sfr/Assets.hpp" 10 | #include "sfr/Cubemap.hpp" 11 | #include "sfr/Texture.hpp" 12 | #include "sfr/TextureLoader.hpp" 13 | #include 14 | 15 | using namespace sfr; 16 | 17 | void TextureLoader::onAsset(Ptr texture) { 18 | 19 | sf::Image image; 20 | std::ifstream in(texture->name()); 21 | if (in) { 22 | if (!image.loadFromFile(texture->name())) { 23 | throw ResourceException("couldn't load image: "+texture->name()); 24 | } 25 | } else { 26 | Asset const* data = sfr::assetPtr(texture->name()); 27 | if (!data) { 28 | throw ResourceException("couldn't load image: "+texture->name()); 29 | } 30 | if (!image.loadFromMemory(data->data, data->len)) { 31 | throw ResourceException("couldn't load image: "+texture->name()); 32 | } 33 | } 34 | 35 | texture->widthIs(image.getSize().x); 36 | texture->heightIs(image.getSize().y); 37 | texture->dataIs(image.getPixelsPtr()); 38 | } 39 | 40 | void TextureLoader::onAsset(Ptr cubemap) { 41 | 42 | sf::Image image; 43 | std::ifstream in(cubemap->name()); 44 | if (in) { 45 | if (!image.loadFromFile(cubemap->name())) { 46 | throw ResourceException("couldn't load image: "+cubemap->name()); 47 | } 48 | } else { 49 | Asset const* data = sfr::assetPtr(cubemap->name()); 50 | if (!data) { 51 | throw ResourceException("couldn't load image: "+cubemap->name()); 52 | } 53 | if (!image.loadFromMemory(data->data, data->len)) { 54 | throw ResourceException("couldn't load image: "+cubemap->name()); 55 | } 56 | } 57 | 58 | cubemap->widthIs(image.getSize().x); 59 | cubemap->heightIs(image.getSize().y); 60 | cubemap->dataIs(image.getPixelsPtr()); 61 | } 62 | -------------------------------------------------------------------------------- /textures/Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/Blue.png -------------------------------------------------------------------------------- /textures/BurstGold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/BurstGold.png -------------------------------------------------------------------------------- /textures/Checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/Checkerboard.png -------------------------------------------------------------------------------- /textures/Grill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/Grill.jpg -------------------------------------------------------------------------------- /textures/IncandescentBlue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/IncandescentBlue.png -------------------------------------------------------------------------------- /textures/LOGO.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/LOGO.jpg -------------------------------------------------------------------------------- /textures/MetalDiffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/MetalDiffuse.png -------------------------------------------------------------------------------- /textures/MetalNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/MetalNormal.png -------------------------------------------------------------------------------- /textures/MetalSpecular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/MetalSpecular.png -------------------------------------------------------------------------------- /textures/Nebula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/Nebula.png -------------------------------------------------------------------------------- /textures/PARTS.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/PARTS.jpg -------------------------------------------------------------------------------- /textures/SandDiffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/SandDiffuse.png -------------------------------------------------------------------------------- /textures/SandNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/SandNormal.png -------------------------------------------------------------------------------- /textures/TIRE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/TIRE.jpg -------------------------------------------------------------------------------- /textures/White.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfichman/sfr/93eb7818cefa41f113414080ca306662647932a1/textures/White.png --------------------------------------------------------------------------------