├── DF_24.png ├── PBROpenGL.sln ├── PBROpenGL ├── Debug │ ├── PBRMesh.obj │ ├── PBROpenGL.log │ ├── PBROpenGL.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── PBROpenGL.lastbuildstate │ │ ├── link.command.1.tlog │ │ ├── link.read.1.tlog │ │ └── link.write.1.tlog │ ├── PBRTexture.obj │ ├── main.obj │ ├── vc141.idb │ └── vc141.pdb ├── Deferred.ps ├── Deferred.vs ├── Light.ps ├── Light.vs ├── PBRMesh.cpp ├── PBRMesh.h ├── PBROpenGL.h ├── PBROpenGL.vcxproj ├── PBROpenGL.vcxproj.filters ├── PBROpenGL.vcxproj.user ├── PBRTexture.cpp ├── PBRTexture.h └── main.cpp └── README.md /DF_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/DF_24.png -------------------------------------------------------------------------------- /PBROpenGL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2015 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PBROpenGL", "PBROpenGL\PBROpenGL.vcxproj", "{61A3B25D-4B97-4240-8367-2CE78EA9892D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Debug|x64.ActiveCfg = Debug|x64 17 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Debug|x64.Build.0 = Debug|x64 18 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Debug|x86.Build.0 = Debug|Win32 20 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Release|x64.ActiveCfg = Release|x64 21 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Release|x64.Build.0 = Release|x64 22 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Release|x86.ActiveCfg = Release|Win32 23 | {61A3B25D-4B97-4240-8367-2CE78EA9892D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7E50566B-7D63-4703-A00D-FFECC11F3046} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBRMesh.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBRMesh.obj -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.log: -------------------------------------------------------------------------------- 1 |  main.cpp 2 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(456): warning C4251: 'Magick::DrawableBezier::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::DrawableBezier' 3 | with 4 | [ 5 | _Ty=Magick::Coordinate 6 | ] 7 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 8 | with 9 | [ 10 | _Ty=Magick::Coordinate 11 | ] 12 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(498): warning C4251: 'Magick::DrawablePushClipPath::_id': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawablePushClipPath' 13 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 14 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(526): warning C4251: 'Magick::DrawableClipPath::_id': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawableClipPath' 15 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 16 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(959): warning C4251: 'Magick::DrawableFont::_font': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawableFont' 17 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 18 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(960): warning C4251: 'Magick::DrawableFont::_family': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawableFont' 19 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 20 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1128): warning C4251: 'Magick::DrawablePath::_path': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::DrawablePath' 21 | with 22 | [ 23 | _Ty=Magick::VPath 24 | ] 25 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(257): note: see declaration of 'std::list>' 26 | with 27 | [ 28 | _Ty=Magick::VPath 29 | ] 30 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1217): warning C4251: 'Magick::DrawablePolygon::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::DrawablePolygon' 31 | with 32 | [ 33 | _Ty=Magick::Coordinate 34 | ] 35 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 36 | with 37 | [ 38 | _Ty=Magick::Coordinate 39 | ] 40 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1237): warning C4251: 'Magick::DrawablePolyline::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::DrawablePolyline' 41 | with 42 | [ 43 | _Ty=Magick::Coordinate 44 | ] 45 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 46 | with 47 | [ 48 | _Ty=Magick::Coordinate 49 | ] 50 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1321): warning C4251: 'Magick::DrawablePushPattern::_id': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawablePushPattern' 51 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 52 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1923): warning C4251: 'Magick::DrawableText::_text': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawableText' 53 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 54 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(1924): warning C4251: 'Magick::DrawableText::_encoding': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::DrawableText' 55 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 56 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2255): warning C4251: 'Magick::PathArcAbs::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathArcAbs' 57 | with 58 | [ 59 | _Ty=Magick::PathArcArgs 60 | ] 61 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2220): note: see declaration of 'std::list>' 62 | with 63 | [ 64 | _Ty=Magick::PathArcArgs 65 | ] 66 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2277): warning C4251: 'Magick::PathArcRel::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathArcRel' 67 | with 68 | [ 69 | _Ty=Magick::PathArcArgs 70 | ] 71 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2220): note: see declaration of 'std::list>' 72 | with 73 | [ 74 | _Ty=Magick::PathArcArgs 75 | ] 76 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2428): warning C4251: 'Magick::PathCurvetoAbs::_args': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathCurvetoAbs' 77 | with 78 | [ 79 | _Ty=Magick::PathCurvetoArgs 80 | ] 81 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2394): note: see declaration of 'std::list>' 82 | with 83 | [ 84 | _Ty=Magick::PathCurvetoArgs 85 | ] 86 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2451): warning C4251: 'Magick::PathCurvetoRel::_args': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathCurvetoRel' 87 | with 88 | [ 89 | _Ty=Magick::PathCurvetoArgs 90 | ] 91 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2394): note: see declaration of 'std::list>' 92 | with 93 | [ 94 | _Ty=Magick::PathCurvetoArgs 95 | ] 96 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2475): warning C4251: 'Magick::PathSmoothCurvetoAbs::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathSmoothCurvetoAbs' 97 | with 98 | [ 99 | _Ty=Magick::Coordinate 100 | ] 101 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 102 | with 103 | [ 104 | _Ty=Magick::Coordinate 105 | ] 106 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2500): warning C4251: 'Magick::PathSmoothCurvetoRel::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathSmoothCurvetoRel' 107 | with 108 | [ 109 | _Ty=Magick::Coordinate 110 | ] 111 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 112 | with 113 | [ 114 | _Ty=Magick::Coordinate 115 | ] 116 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2609): warning C4251: 'Magick::PathQuadraticCurvetoAbs::_args': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathQuadraticCurvetoAbs' 117 | with 118 | [ 119 | _Ty=Magick::PathQuadraticCurvetoArgs 120 | ] 121 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2575): note: see declaration of 'std::list>' 122 | with 123 | [ 124 | _Ty=Magick::PathQuadraticCurvetoArgs 125 | ] 126 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2633): warning C4251: 'Magick::PathQuadraticCurvetoRel::_args': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathQuadraticCurvetoRel' 127 | with 128 | [ 129 | _Ty=Magick::PathQuadraticCurvetoArgs 130 | ] 131 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2575): note: see declaration of 'std::list>' 132 | with 133 | [ 134 | _Ty=Magick::PathQuadraticCurvetoArgs 135 | ] 136 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2657): warning C4251: 'Magick::PathSmoothQuadraticCurvetoAbs::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathSmoothQuadraticCurvetoAbs' 137 | with 138 | [ 139 | _Ty=Magick::Coordinate 140 | ] 141 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 142 | with 143 | [ 144 | _Ty=Magick::Coordinate 145 | ] 146 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2681): warning C4251: 'Magick::PathSmoothQuadraticCurvetoRel::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathSmoothQuadraticCurvetoRel' 147 | with 148 | [ 149 | _Ty=Magick::Coordinate 150 | ] 151 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 152 | with 153 | [ 154 | _Ty=Magick::Coordinate 155 | ] 156 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2709): warning C4251: 'Magick::PathLinetoAbs::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathLinetoAbs' 157 | with 158 | [ 159 | _Ty=Magick::Coordinate 160 | ] 161 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 162 | with 163 | [ 164 | _Ty=Magick::Coordinate 165 | ] 166 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2733): warning C4251: 'Magick::PathLinetoRel::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathLinetoRel' 167 | with 168 | [ 169 | _Ty=Magick::Coordinate 170 | ] 171 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 172 | with 173 | [ 174 | _Ty=Magick::Coordinate 175 | ] 176 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2875): warning C4251: 'Magick::PathMovetoAbs::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathMovetoAbs' 177 | with 178 | [ 179 | _Ty=Magick::Coordinate 180 | ] 181 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 182 | with 183 | [ 184 | _Ty=Magick::Coordinate 185 | ] 186 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(2899): warning C4251: 'Magick::PathMovetoRel::_coordinates': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::PathMovetoRel' 187 | with 188 | [ 189 | _Ty=Magick::Coordinate 190 | ] 191 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(83): note: see declaration of 'std::list>' 192 | with 193 | [ 194 | _Ty=Magick::Coordinate 195 | ] 196 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\exception.h(22): warning C4275: non dll-interface class 'std::exception' used as base for dll-interface class 'Magick::Exception' 197 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\vcruntime_exception.h(43): note: see declaration of 'std::exception' 198 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\exception.h(21): note: see declaration of 'Magick::Exception' 199 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\exception.h(31): warning C4251: 'Magick::Exception::_what': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Exception' 200 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 201 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\coderinfo.h(65): warning C4251: 'Magick::CoderInfo::_name': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::CoderInfo' 202 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 203 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\coderinfo.h(66): warning C4251: 'Magick::CoderInfo::_description': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::CoderInfo' 204 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 205 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\montage.h(90): warning C4251: 'Magick::Montage::_fileName': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Montage' 206 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 207 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\montage.h(92): warning C4251: 'Magick::Montage::_font': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Montage' 208 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 209 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\montage.h(95): warning C4251: 'Magick::Montage::_label': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Montage' 210 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 211 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\montage.h(99): warning C4251: 'Magick::Montage::_texture': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Montage' 212 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 213 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\montage.h(101): warning C4251: 'Magick::Montage::_title': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::Montage' 214 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 215 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(134): warning C4251: 'Magick::annotateImage::_text': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::annotateImage' 216 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 217 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(213): warning C4251: 'Magick::cdlImage::_cdl': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::cdlImage' 218 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 219 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(273): warning C4251: 'Magick::commentImage::_comment': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::commentImage' 220 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 221 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(385): warning C4251: 'Magick::drawImage::_drawableList': class 'std::list>' needs to have dll-interface to be used by clients of class 'Magick::drawImage' 222 | with 223 | [ 224 | _Ty=Magick::Drawable 225 | ] 226 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\drawable.h(177): note: see declaration of 'std::list>' 227 | with 228 | [ 229 | _Ty=Magick::Drawable 230 | ] 231 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(651): warning C4251: 'Magick::labelImage::_label': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::labelImage' 232 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 233 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1299): warning C4251: 'Magick::backgroundTextureImage::_backgroundTexture': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::backgroundTextureImage' 234 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 235 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1474): warning C4251: 'Magick::fileNameImage::_fileName': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::fileNameImage' 236 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 237 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1498): warning C4251: 'Magick::fontImage::_font': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::fontImage' 238 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 239 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1558): warning C4251: 'Magick::magickImage::_magick': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::magickImage' 240 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 241 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1817): warning C4251: 'Magick::tileNameImage::_tileName': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::tileNameImage' 242 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 243 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1854): warning C4251: 'Magick::viewImage::_view': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::viewImage' 244 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 245 | c:\users\parku\source\repos\thirdparty\include\imagemagick-6\magick++\stl.h(1867): warning C4251: 'Magick::x11DisplayImage::_display': class 'std::basic_string,std::allocator>' needs to have dll-interface to be used by clients of class 'Magick::x11DisplayImage' 246 | c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.13.26128\include\xstring(4273): note: see declaration of 'std::basic_string,std::allocator>' 247 | c:\users\parku\source\repos\pbropengl\pbropengl\pbrmesh.h(67): warning C4240: nonstandard extension used: access to 'Mesh::MeshEntry' now defined to be 'private', previously it was defined to be 'public' 248 | c:\users\parku\source\repos\pbropengl\pbropengl\pbrmesh.h(46): note: see declaration of 'Mesh::MeshEntry' 249 | c:\users\parku\source\repos\pbropengl\pbropengl\main.cpp(164): warning C4101: 'uboAlignment_': unreferenced local variable 250 | c:\users\parku\source\repos\pbropengl\pbropengl\main.cpp(485): warning C4305: '-=': truncation from 'double' to 'float' 251 | c:\users\parku\source\repos\pbropengl\pbropengl\main.cpp(488): warning C4305: '+=': truncation from 'double' to 'float' 252 | PBROpenGL.vcxproj -> C:\Users\parku\source\repos\PBROpenGL\Debug\PBROpenGL.exe 253 | -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/PBROpenGL.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0 2 | Debug|Win32|C:\Users\parku\source\repos\PBROpenGL\| 3 | -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBROpenGL.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBROpenGL.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /PBROpenGL/Debug/PBRTexture.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/PBRTexture.obj -------------------------------------------------------------------------------- /PBROpenGL/Debug/main.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/main.obj -------------------------------------------------------------------------------- /PBROpenGL/Debug/vc141.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/vc141.idb -------------------------------------------------------------------------------- /PBROpenGL/Debug/vc141.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelClear/Deferred-renderer/71ba015449db4e515c96e0e27d6ed42f51ed7e2a/PBROpenGL/Debug/vc141.pdb -------------------------------------------------------------------------------- /PBROpenGL/Deferred.ps: -------------------------------------------------------------------------------- 1 | #version 430 2 | in vec2 v_TexCoord; 3 | in vec3 v_WorldPos; 4 | in vec3 v_WorldNormal; 5 | 6 | layout (location = 0) out vec3 WorldPosOut; 7 | layout (location = 1) out vec3 DiffuseOut; 8 | layout (location = 2) out vec3 NormalOut; 9 | layout (location = 3) out vec3 TexCoordOut; 10 | 11 | uniform sampler2D gSampler; 12 | 13 | void main() 14 | { 15 | WorldPosOut = v_WorldPos; 16 | DiffuseOut = texture(gSampler, v_TexCoord).xyz; 17 | NormalOut = normalize(v_WorldNormal); 18 | TexCoordOut = vec3(v_TexCoord, 0.0); 19 | } -------------------------------------------------------------------------------- /PBROpenGL/Deferred.vs: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout (location = 0) in vec3 in_Vertex; 3 | layout (location = 1) in vec2 in_TexCoord; 4 | layout (location = 2) in vec3 in_Normal; 5 | 6 | 7 | 8 | uniform mat4 u_Model; 9 | uniform mat4 u_View; 10 | uniform mat4 u_Projection; 11 | 12 | out vec2 v_TexCoord; 13 | out vec3 v_WorldNormal; 14 | out vec3 v_WorldPos; 15 | 16 | void main() 17 | { 18 | gl_Position = u_Projection * u_View * u_Model * vec4(in_Vertex, 1.0f); 19 | mat3 normalMatrix = transpose(inverse(mat3(u_Model))); 20 | v_WorldPos = (u_Model * vec4(in_Vertex,1.0f)).xyz; 21 | v_TexCoord = in_TexCoord; 22 | v_WorldNormal = normalMatrix * in_Normal; 23 | } -------------------------------------------------------------------------------- /PBROpenGL/Light.ps: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | uniform sampler2D u_PositionMap; 4 | uniform sampler2D u_ColorMap; 5 | uniform sampler2D u_NormalMap; 6 | uniform sampler2D u_TextureCoordMap; 7 | 8 | const float DirectionalLight = 0.0f; 9 | const float PointLight = 1.0f; 10 | 11 | out vec4 out_FragColor; 12 | 13 | struct LightProperties 14 | { 15 | float lightType; 16 | vec4 lightColor; 17 | vec3 lightPos; 18 | vec3 lightDir; 19 | float lightRadius; 20 | float diffuseIntensity; 21 | vec3 v_WorldPos; 22 | vec3 v_WorldNormal; 23 | 24 | }; 25 | 26 | struct LightBuffer 27 | { 28 | vec4 lightPos_; 29 | vec4 lightParams_; //(x - radius, y - spot outer, z - spot inner , w - light type) 30 | vec4 lightIntensityParams_; //( x - - diffuse intensity, yzw - not used) 31 | vec4 lightDir_; 32 | vec4 lightColor_; 33 | }; 34 | 35 | layout (std140 , binding = 0) uniform Light 36 | { 37 | LightBuffer u_Lights[20]; 38 | }; 39 | 40 | vec2 getTexCoord() 41 | { 42 | return gl_FragCoord.xy / vec2(1350,700); 43 | } 44 | 45 | float getAttenuation(float lightRadius, float distanceToLight) 46 | { 47 | float I = distanceToLight / lightRadius; 48 | return max(1.0 - I * I, 0.0); 49 | } 50 | 51 | float getDiffuseFactor(vec3 toLight, vec3 normal) 52 | { 53 | float d = dot(toLight, normal); 54 | 55 | return clamp(d, 0.0, 1.0); 56 | } 57 | 58 | float calculatePointLight(LightProperties lp) 59 | { 60 | vec3 toLight = lp.lightPos- lp.v_WorldPos.xyz; 61 | 62 | float distanceToLight = length(toLight); 63 | float attenuation = getAttenuation(lp.lightRadius, distanceToLight); 64 | 65 | return attenuation * lp.diffuseIntensity * getDiffuseFactor(normalize(toLight), normalize(lp.v_WorldNormal)); 66 | } 67 | 68 | float calculateDirectionalLight(LightProperties lp) 69 | { 70 | return lp.diffuseIntensity * getDiffuseFactor(-normalize(lp.lightDir), normalize(lp.v_WorldNormal)); 71 | } 72 | 73 | vec4 calculateFinalColor(LightBuffer buf) 74 | { 75 | LightProperties lp; 76 | lp.lightType = buf.lightParams_.w; 77 | lp.lightColor = buf.lightColor_; 78 | lp.lightPos = buf.lightPos_.xyz; 79 | lp.lightDir = buf.lightDir_.xyz; 80 | lp.lightRadius = buf.lightParams_.x; 81 | lp.diffuseIntensity = buf.lightIntensityParams_.x; 82 | lp.v_WorldPos = texture(u_PositionMap, getTexCoord()).xyz; 83 | lp.v_WorldNormal = texture(u_NormalMap, getTexCoord()).xyz; 84 | 85 | vec4 Kp = lp.lightColor; 86 | 87 | Kp *= calculatePointLight(lp); 88 | 89 | return Kp; 90 | } 91 | 92 | void main() 93 | { 94 | vec2 uv = texture(u_TextureCoordMap, getTexCoord()).xy; 95 | vec4 Kp; 96 | for(int i = 0 ; i < 20; i++) 97 | { 98 | Kp += calculateFinalColor(u_Lights[i]); 99 | } 100 | 101 | 102 | LightProperties lp; 103 | lp.lightColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); 104 | lp.lightDir = vec3(-50.0f, -600.0f, -950.0f); 105 | lp.v_WorldNormal = texture(u_NormalMap, getTexCoord()).xyz; 106 | lp.diffuseIntensity = 0.3f; 107 | 108 | vec4 Kd = lp.lightColor * calculateDirectionalLight(lp); 109 | 110 | float gamma = 2.2; 111 | Kp.rgb = pow(Kp.rgb, vec3(1.0/gamma)); 112 | 113 | out_FragColor = texture(u_ColorMap, getTexCoord()) * (Kp + Kd); 114 | } -------------------------------------------------------------------------------- /PBROpenGL/Light.vs: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout (location = 0) in vec3 in_Vertex; 3 | 4 | void main() 5 | { 6 | gl_Position = vec4(in_Vertex, 1.0f); 7 | } 8 | -------------------------------------------------------------------------------- /PBROpenGL/PBRMesh.cpp: -------------------------------------------------------------------------------- 1 | #include "PBRMesh.h" 2 | 3 | Mesh::Mesh() 4 | { 5 | 6 | } 7 | 8 | Mesh::~Mesh() 9 | { 10 | Clear(); 11 | } 12 | 13 | Mesh::MeshEntry::MeshEntry() 14 | { 15 | VB = INVALID_OGL_VALUE; 16 | IB = INVALID_OGL_VALUE; 17 | NumIndices = 0; 18 | MaterialIndex = INVALID_MATERIAL; 19 | } 20 | 21 | Mesh::MeshEntry::~MeshEntry() 22 | { 23 | if (VB != INVALID_OGL_VALUE) 24 | { 25 | glDeleteBuffers(1, &VB); 26 | } 27 | 28 | if (IB != INVALID_OGL_VALUE) 29 | { 30 | glDeleteBuffers(1, &IB); 31 | } 32 | } 33 | 34 | bool Mesh::MeshEntry::Init(const std::vector& Vertices, const std::vector& Indices) 35 | { 36 | NumIndices = Indices.size(); 37 | 38 | glGenBuffers(1, &VB); 39 | glBindBuffer(GL_ARRAY_BUFFER, VB); 40 | glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW); 41 | 42 | glGenBuffers(1, &IB); 43 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB); 44 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * NumIndices, &Indices[0], GL_STATIC_DRAW); 45 | 46 | return true; 47 | } 48 | 49 | bool Mesh::LoadMesh(const std::string& fileName) 50 | { 51 | //Release previously loaded mesh 52 | Clear(); 53 | bool ret = false; 54 | Assimp::Importer Importer; 55 | 56 | const aiScene* pScene = Importer.ReadFile(fileName.c_str(), aiProcess_Triangulate | 57 | aiProcess_GenSmoothNormals | 58 | aiProcess_FlipUVs); 59 | 60 | if (pScene) 61 | { 62 | ret = InitFromScene(pScene, fileName); 63 | } 64 | else 65 | { 66 | std::cout << "Error parsing'%s' : '%s' \n" << fileName.c_str() << Importer.GetErrorString() << "\n"; 67 | } 68 | 69 | return ret; 70 | } 71 | 72 | void Mesh::Render(MeshEntry& m) 73 | { 74 | glEnableVertexAttribArray(0); 75 | glEnableVertexAttribArray(1); 76 | glEnableVertexAttribArray(2); 77 | 78 | glBindBuffer(GL_ARRAY_BUFFER, m.VB); 79 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); 80 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); 81 | glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); 82 | 83 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m.IB); 84 | 85 | const unsigned int MaterialIndex = m.MaterialIndex; 86 | 87 | if (MaterialIndex < m_textures.size() && m_textures[MaterialIndex]) { 88 | m_textures[MaterialIndex]->Bind(GL_TEXTURE0); 89 | } 90 | 91 | glDrawElements(GL_TRIANGLES, m.NumIndices, GL_UNSIGNED_INT, 0); 92 | 93 | glDisableVertexAttribArray(0); 94 | glDisableVertexAttribArray(1); 95 | glDisableVertexAttribArray(2); 96 | } 97 | 98 | void Mesh::Render() 99 | { 100 | glEnableVertexAttribArray(0); 101 | glEnableVertexAttribArray(1); 102 | glEnableVertexAttribArray(2); 103 | 104 | for (unsigned int i = 0; i < m_Entries.size(); i++) { 105 | glBindBuffer(GL_ARRAY_BUFFER, m_Entries[i].VB); 106 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); 107 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); 108 | glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20); 109 | 110 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Entries[i].IB); 111 | 112 | const unsigned int MaterialIndex = m_Entries[i].MaterialIndex; 113 | 114 | if (MaterialIndex < m_textures.size() && m_textures[MaterialIndex]) { 115 | m_textures[MaterialIndex]->Bind(GL_TEXTURE0); 116 | } 117 | 118 | glDrawElements(GL_TRIANGLES, m_Entries[i].NumIndices, GL_UNSIGNED_INT, 0); 119 | } 120 | 121 | glDisableVertexAttribArray(0); 122 | glDisableVertexAttribArray(1); 123 | glDisableVertexAttribArray(2); 124 | } 125 | 126 | bool Mesh::InitFromScene(const aiScene* pScene, const std::string& fileName) 127 | { 128 | m_Entries.resize(pScene->mNumMeshes); 129 | m_textures.resize(pScene->mNumMaterials); 130 | 131 | //Initialize the mesh in scene 132 | for (unsigned int i = 0; i < m_Entries.size(); i++) 133 | { 134 | const aiMesh* paiMesh = pScene->mMeshes[i]; 135 | InitMesh(i, paiMesh); 136 | } 137 | 138 | return InitMaterials(pScene, fileName); 139 | } 140 | 141 | void Mesh::InitMesh(unsigned int Index, const aiMesh* pMesh) 142 | { 143 | m_Entries[Index].MaterialIndex = pMesh->mMaterialIndex; 144 | 145 | std::vector Vertices; 146 | std::vector Indices; 147 | 148 | const aiVector3D Zero3D(0.0, 0.0, 0.0); 149 | 150 | for (unsigned int i = 0; i < pMesh->mNumVertices; i++) 151 | { 152 | const aiVector3D* pPos = &(pMesh->mVertices[i]); 153 | const aiVector3D* pNormal = &(pMesh->mNormals[i]); 154 | const aiVector3D* pTexCoord = pMesh->HasTextureCoords(0) ? &(pMesh->mTextureCoords[0][i]) : &Zero3D; 155 | const aiVector3D* pTangent = &(pMesh->mTangents[i]); 156 | 157 | Vertex v(vec3(pPos->x, pPos->y, pPos->z), 158 | vec2(pTexCoord->x, pTexCoord->y), 159 | vec3(pNormal->x, pNormal->y, pNormal->z)); 160 | 161 | Vertices.push_back(v); 162 | } 163 | 164 | for (unsigned int i = 0; i < pMesh->mNumFaces; i++) 165 | { 166 | const aiFace& Face = pMesh->mFaces[i]; 167 | assert(Face.mNumIndices == 3); 168 | Indices.push_back(Face.mIndices[0]); 169 | Indices.push_back(Face.mIndices[1]); 170 | Indices.push_back(Face.mIndices[2]); 171 | 172 | } 173 | 174 | m_Entries[Index].Init(Vertices, Indices); 175 | } 176 | 177 | bool Mesh::InitMaterials(const aiScene* pScene, const std::string& fileName) 178 | { 179 | std::string::size_type SlashIndex = fileName.find_last_of("/"); 180 | std::string Dir; 181 | 182 | if (SlashIndex == std::string::npos) 183 | { 184 | Dir = "."; 185 | } 186 | else if (SlashIndex == 0) 187 | { 188 | Dir = "/"; 189 | } 190 | else 191 | { 192 | Dir = fileName.substr(0, SlashIndex); 193 | } 194 | 195 | bool ret = true; 196 | 197 | for (unsigned int i = 0; i < pScene->mNumMaterials; i++) 198 | { 199 | const aiMaterial* pMaterial = pScene->mMaterials[i]; 200 | m_textures[i] = NULL; 201 | 202 | if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) 203 | { 204 | aiString Path; 205 | if (pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) 206 | { 207 | std::string fullPath = Dir + "/" + Path.data; 208 | m_textures[i] = new Texture(GL_TEXTURE_2D, fullPath.c_str()); 209 | 210 | if (!m_textures[i]->Load()) 211 | { 212 | std::cout << "Error Loading texure '%s' \n" << fullPath.c_str() << "\n"; 213 | delete m_textures[i]; 214 | m_textures[i] = nullptr; 215 | ret = false; 216 | } 217 | else 218 | { 219 | std::cout << "Loaded Texture '%s'" << fullPath.c_str() << "\n"; 220 | ret = true; 221 | } 222 | } 223 | } 224 | 225 | } 226 | 227 | return ret; 228 | } 229 | 230 | void Mesh::Clear() 231 | { 232 | for (unsigned int i = 0; i < m_textures.size(); i++) { 233 | delete m_textures[i]; 234 | m_textures[i] = nullptr; 235 | } 236 | } -------------------------------------------------------------------------------- /PBROpenGL/PBRMesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "PBRTexture.h" 14 | 15 | #define PI 3.14159265f 16 | #define INVALID_UNIFORM_LOCATION 0xffffffff 17 | #define INVALID_OGL_VALUE 0xffffffff 18 | 19 | //Maths 20 | using vec2 = glm::vec2; 21 | using vec3 = glm::vec3; 22 | using vec4 = glm::vec4; 23 | using mat4 = glm::mat4; 24 | using mat3 = glm::mat3; 25 | 26 | struct Vertex 27 | { 28 | vec3 m_pos; 29 | vec2 m_tex; 30 | vec3 m_normal; 31 | 32 | Vertex() {} 33 | 34 | Vertex(const vec3& pos, const vec2& tex, const vec3& normal) 35 | { 36 | m_pos = pos; 37 | m_tex = tex; 38 | m_normal = normal; 39 | 40 | } 41 | }; 42 | 43 | class Mesh 44 | { 45 | public: 46 | struct MeshEntry; 47 | 48 | Mesh(); 49 | 50 | ~Mesh(); 51 | 52 | bool LoadMesh(const std::string& fileName); 53 | 54 | void Render(); 55 | void Render(MeshEntry& m); 56 | 57 | private: 58 | 59 | bool InitFromScene(const aiScene* pScene, const std::string& fileName); 60 | void InitMesh(unsigned int Index, const aiMesh* pMesh); 61 | bool InitMaterials(const aiScene* pScene, const std::string& fileName); 62 | void Clear(); 63 | 64 | #define INVALID_MATERIAL 0xFFFFFFFF 65 | 66 | struct MeshEntry 67 | { 68 | MeshEntry(); 69 | ~MeshEntry(); 70 | 71 | bool Init(const std::vector& Vertices, const std::vector& Indices); 72 | 73 | uint32_t VB; 74 | uint32_t IB; 75 | unsigned int NumIndices; 76 | unsigned int MaterialIndex; 77 | }; 78 | 79 | public: 80 | 81 | std::vector m_Entries; 82 | std::vector m_textures; 83 | }; 84 | -------------------------------------------------------------------------------- /PBROpenGL/PBROpenGL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "PBRMesh.h" 10 | 11 | enum Passes{ Deferred, LightPass, TotalPasses }; 12 | 13 | //Shader compilation 14 | GLuint vs[TotalPasses]; 15 | GLuint fs[TotalPasses]; 16 | GLuint ps[TotalPasses]; 17 | 18 | //Normal Uniforms 19 | mat4 view; 20 | mat4 projection; 21 | mat4 model = mat4(1.0f); 22 | 23 | GLuint modelLocation; 24 | GLuint viewLocation; 25 | GLuint projLocation; 26 | GLuint textureLocation; 27 | 28 | //Window variables 29 | unsigned int windowHeight; 30 | unsigned int windowWidth; 31 | 32 | //Ubo 33 | GLuint ubo; 34 | GLuint uboIndex; 35 | 36 | struct LightProperties 37 | { 38 | vec4 lightPos_ = vec4(1.0f); 39 | vec4 lightParams_ = vec4(1.0f); 40 | vec4 lightIntensityParams_ = vec4(1.0f); 41 | vec4 lightDir_ = vec4(1.0f); 42 | vec4 lightColor_ = vec4(1.0f); 43 | }; 44 | 45 | //Mesh 46 | Mesh* sphere; 47 | Mesh* quad; 48 | Texture* groundTexture; 49 | 50 | // All GBuffer Related Data 51 | enum GBUFFER_TEXTURES 52 | { 53 | POSITION_TEXTURE, 54 | DIFFUSE_TEXTURE, 55 | NORMAL_TEXTURE, 56 | TEXCOORD_TEXTURE, 57 | NUM_GBUFFER_TEXTURES 58 | }; 59 | 60 | GLuint g_textures[NUM_GBUFFER_TEXTURES]; 61 | GLuint g_fbo; 62 | GLuint g_depthTexture; 63 | GLuint mapLocations[NUM_GBUFFER_TEXTURES]; 64 | 65 | //Full quad pass 66 | GLuint quadVAO; 67 | GLuint quadVBO; 68 | GLuint quadIBO; 69 | 70 | GLfloat quadVertices[] = { 71 | 1.0f, -1.0f, 0.0f, 72 | 1.0f, 1.0f, 0.0f , 73 | -1.0f, -1.0f, 0.0f, 74 | -1.0f, 1.0f, 0.0f 75 | }; 76 | 77 | const GLushort quadIndices[] = 78 | { 79 | 0,1,2,2,3,1 80 | }; 81 | -------------------------------------------------------------------------------- /PBROpenGL/PBROpenGL.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {61A3B25D-4B97-4240-8367-2CE78EA9892D} 24 | PBROpenGL 25 | 10.0.16299.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v141 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v141 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | Disabled 77 | true 78 | true 79 | ../../ThirdParty/Include; ../../ThirdParty/Include/ImageMagick-6 80 | 81 | 82 | ../../ThirdParty/Lib 83 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;freeglut.lib;glew32.lib;CORE_DB_Magick++_.lib;assimp.lib;%(AdditionalDependencies) 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | true 91 | true 92 | 93 | 94 | 95 | 96 | Level3 97 | MaxSpeed 98 | true 99 | true 100 | true 101 | true 102 | 103 | 104 | true 105 | true 106 | 107 | 108 | 109 | 110 | Level3 111 | MaxSpeed 112 | true 113 | true 114 | true 115 | true 116 | 117 | 118 | true 119 | true 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /PBROpenGL/PBROpenGL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /PBROpenGL/PBROpenGL.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /PBROpenGL/PBRTexture.cpp: -------------------------------------------------------------------------------- 1 | #include "PBRTexture.h" 2 | 3 | Texture::Texture(GLenum TextureTarget, const std::string& FileName) 4 | { 5 | m_textureTarget = TextureTarget; 6 | m_fileName = FileName; 7 | } 8 | 9 | 10 | bool Texture::Load() 11 | { 12 | try { 13 | m_image.read(m_fileName); 14 | m_image.write(&m_blob, "RGBA"); 15 | } 16 | catch (Magick::Error& Error) { 17 | std::cout << "Error loading texture '" << m_fileName << "': " << Error.what() << std::endl; 18 | return false; 19 | } 20 | 21 | glGenTextures(1, &m_textureObj); 22 | glBindTexture(m_textureTarget, m_textureObj); 23 | glTexImage2D(m_textureTarget, 0, GL_RGBA, m_image.columns(), m_image.rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_blob.data()); 24 | glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 25 | glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 26 | glBindTexture(m_textureTarget, 0); 27 | 28 | return true; 29 | } 30 | 31 | void Texture::Bind(GLenum TextureUnit) 32 | { 33 | glActiveTexture(TextureUnit); 34 | glBindTexture(m_textureTarget, m_textureObj); 35 | } 36 | 37 | void Texture::Unbind() 38 | { 39 | glActiveTexture(0); 40 | glBindTexture(m_textureTarget, 0); 41 | } -------------------------------------------------------------------------------- /PBROpenGL/PBRTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | /* Image Library Related Includes*/ 7 | #include 8 | 9 | 10 | #define COLOR_TEXTURE_UNIT GL_TEXTURE0 11 | #define COLOR_TEXTURE_UNIT_INDEX 0 12 | #define SHADOW_TEXTURE_UNIT GL_TEXTURE1 13 | #define SHADOW_TEXTURE_UNIT_INDEX 1 14 | #define NORMAL_TEXTURE_UNIT GL_TEXTURE2 15 | #define NORMAL_TEXTURE_UNIT_INDEX 2 16 | #define RANDOM_TEXTURE_UNIT GL_TEXTURE3 17 | #define RANDOM_TEXTURE_UNIT_INDEX 3 18 | #define DISPLACEMENT_TEXTURE_UNIT GL_TEXTURE4 19 | #define DISPLACEMENT_TEXTURE_UNIT_INDEX 4 20 | #define MOTION_TEXTURE_UNIT GL_TEXTURE5 21 | #define MOTION_TEXTURE_UNIT_INDEX 5 22 | 23 | class Texture 24 | { 25 | public: 26 | Texture(GLenum TextureTarget, const std::string& FileName); 27 | 28 | bool Load(); 29 | 30 | void Bind(GLenum TextureUnit); 31 | 32 | void Unbind(); 33 | 34 | private: 35 | std::string m_fileName; 36 | GLenum m_textureTarget; 37 | GLuint m_textureObj; 38 | Magick::Image m_image; 39 | Magick::Blob m_blob; 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /PBROpenGL/main.cpp: -------------------------------------------------------------------------------- 1 | #include "PBROpenGL.h" 2 | 3 | //#define _DebugDeferred 1 4 | 5 | float camera = 0.0f; 6 | 7 | double RangedRand(double range_min, double range_max) 8 | { 9 | double u = (double)rand() / (RAND_MAX + 1) * (range_max - range_min) 10 | + range_min; 11 | return u; 12 | } 13 | 14 | void getLightStruct(std::vector& l) 15 | { 16 | float x = -100.0f; 17 | float y = -300.0f; 18 | float z = -1700.0f; 19 | float offset = 0.0f; 20 | float radius = 350.0f; 21 | 22 | for (int i = 0; i < 4; i++) 23 | { 24 | LightProperties lp; 25 | lp.lightColor_ = vec4(RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), 1.0f); 26 | lp.lightPos_ = vec4(400.0, -300.0f, -1700.0f + offset, 0.0f); 27 | lp.lightDir_ = vec4(0.0f, -1.0f, 0.0f, 0.0f); 28 | lp.lightParams_ = vec4(radius, 0.0f, 0.0f, 1.0f); 29 | lp.lightIntensityParams_ = vec4(0.9f, 0.0f, 0.0f, 0.0f); 30 | 31 | l.push_back(lp); 32 | if (i == 0)offset += 400.0f; 33 | if (i == 1)offset += 350.0f; 34 | if (i == 2)offset += 300.0f; 35 | if (i == 3)offset += 250.0f; 36 | } 37 | 38 | offset = 0.0f; 39 | for (int i = 0; i < 4; i++) 40 | { 41 | LightProperties lp; 42 | lp.lightColor_ = vec4(RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), 1.0f); 43 | lp.lightPos_ = vec4(-270.0, -300.0f, -1700.0f + offset, 0.0f); 44 | lp.lightDir_ = vec4(0.0f, -1.0f, 0.0f, 0.0f); 45 | lp.lightParams_ = vec4(radius, 0.0f, 0.0f, 1.0f); 46 | lp.lightIntensityParams_ = vec4(0.9f, 0.0f, 0.0f, 0.0f); 47 | 48 | l.push_back(lp); 49 | if (i == 0)offset += 400.0f; 50 | if (i == 1)offset += 350.0f; 51 | if (i == 2)offset += 300.0f; 52 | if (i == 3)offset += 250.0f; 53 | } 54 | 55 | offset = 0.0f; 56 | for (int i = 0; i < 4; i++) 57 | { 58 | LightProperties lp; 59 | lp.lightColor_ = vec4(RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), 1.0f); 60 | lp.lightPos_ = vec4(-50.0f, -300.0f, -1700.0f + offset, 0.0f); 61 | lp.lightDir_ = vec4(0.0f, -1.0f, 0.0f, 0.0f); 62 | lp.lightParams_ = vec4(radius, 0.0f, 0.0f, 1.0f); 63 | lp.lightIntensityParams_ = vec4(0.9f, 0.0f, 0.0f, 0.0f); 64 | 65 | l.push_back(lp); 66 | if (i == 0)offset += 400.0f; 67 | if (i == 1)offset += 350.0f; 68 | if (i == 2)offset += 300.0f; 69 | if (i == 3)offset += 250.0f; 70 | } 71 | 72 | offset = 0.0f; 73 | for (int i = 0; i < 4; i++) 74 | { 75 | LightProperties lp; 76 | lp.lightColor_ = vec4(RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), 1.0f); 77 | lp.lightPos_ = vec4(-500.0, -900.0f, -1700.0f + offset, 0.0f); 78 | lp.lightDir_ = vec4(0.0f, -1.0f, 0.0f, 0.0f); 79 | lp.lightParams_ = vec4(1000.0f, 0.0f, 0.0f, 1.0f); 80 | lp.lightIntensityParams_ = vec4(0.9f, 0.0f, 0.0f, 0.0f); 81 | 82 | l.push_back(lp); 83 | if (i == 0)offset += 400.0f; 84 | if (i == 1)offset += 350.0f; 85 | if (i == 2)offset += 300.0f; 86 | if (i == 3)offset += 250.0f; 87 | } 88 | 89 | offset = 0.0f; 90 | for (int i = 0; i < 4; i++) 91 | { 92 | LightProperties lp; 93 | lp.lightColor_ = vec4(RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), RangedRand(0.0f, 1.0f), 1.0f); 94 | lp.lightPos_ = vec4(-50.0, -3000.0f, -1700.0f + offset, 0.0f); 95 | lp.lightDir_ = vec4(1.0f, 0.0f, 0.0f, 0.0f); 96 | lp.lightParams_ = vec4(3500.0f, 0.0f, 0.0f, 1.0f); 97 | lp.lightIntensityParams_ = vec4(0.9f, 0.0f, 0.0f, 0.0f); 98 | 99 | l.push_back(lp); 100 | if (i == 0)offset += 400.0f; 101 | if (i == 1)offset += 350.0f; 102 | if (i == 2)offset += 300.0f; 103 | if (i == 3)offset += 250.0f; 104 | } 105 | } 106 | 107 | void PrepareFullQuadVAO() 108 | { 109 | glGenVertexArrays(1, &quadVAO); 110 | glBindVertexArray(quadVAO); 111 | 112 | glGenBuffers(1, &quadIBO); 113 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadIBO); 114 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadIndices), quadIndices, GL_STATIC_DRAW); 115 | 116 | glGenBuffers(1, &quadVBO); 117 | glBindBuffer(GL_ARRAY_BUFFER, quadVBO); 118 | glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW); 119 | glEnableVertexAttribArray(0); 120 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); 121 | 122 | glBindBuffer(GL_ARRAY_BUFFER, 0); 123 | glBindVertexArray(0); 124 | } 125 | 126 | bool prepareGBuffer() 127 | { 128 | glGenFramebuffers(1, &g_fbo); 129 | glBindFramebuffer(GL_FRAMEBUFFER, g_fbo); 130 | 131 | glGenTextures(NUM_GBUFFER_TEXTURES, g_textures); 132 | glGenTextures(1, &g_depthTexture); 133 | 134 | for (unsigned int i = 0; i< NUM_GBUFFER_TEXTURES; i++) 135 | { 136 | glBindTexture(GL_TEXTURE_2D, g_textures[i]); 137 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, windowWidth, windowHeight, 0, GL_RGB, GL_FLOAT, NULL); 138 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 139 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 140 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, g_textures[i], 0); 141 | } 142 | 143 | glBindTexture(GL_TEXTURE_2D, g_depthTexture); 144 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, windowWidth, windowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); 145 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, g_depthTexture, 0); 146 | 147 | GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1,GL_COLOR_ATTACHMENT2,GL_COLOR_ATTACHMENT3 }; 148 | 149 | glDrawBuffers(4, DrawBuffers); 150 | 151 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 152 | if (status != GL_FRAMEBUFFER_COMPLETE) 153 | { 154 | std::cerr << "FB Error\n"; 155 | return false; 156 | } 157 | 158 | glBindFramebuffer(GL_DRAW_BUFFER, 0); 159 | return true; 160 | } 161 | 162 | bool initLightUBO() 163 | { 164 | GLint uboAlignment_; 165 | std::vector lp; 166 | getLightStruct(lp); 167 | 168 | 169 | glGenBuffers(1, &ubo); 170 | glBindBuffer(GL_UNIFORM_BUFFER, ubo); 171 | glBufferData(GL_UNIFORM_BUFFER, sizeof(LightProperties) * lp.size(),lp.data(), GL_DYNAMIC_DRAW); 172 | glBindBuffer(GL_UNIFORM_BUFFER, 0); 173 | return true; 174 | } 175 | 176 | bool bindUboIndex(GLuint ps) 177 | { 178 | uboIndex = glGetUniformBlockIndex(ps, "Light"); 179 | 180 | if (uboIndex != GL_INVALID_INDEX) 181 | { 182 | glUniformBlockBinding(ps, uboIndex, 0); 183 | return true; 184 | } 185 | 186 | return false; 187 | } 188 | 189 | void bindUbo() 190 | { 191 | glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo); 192 | } 193 | 194 | bool initScene() 195 | { 196 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 197 | 198 | sphere = new Mesh(); 199 | quad = new Mesh(); 200 | groundTexture = new Texture(GL_TEXTURE_2D, "../../ThirdParty/Content/test1.jpg"); 201 | 202 | if (!groundTexture->Load()) 203 | { 204 | std::cerr << " Unable to load texture \n"; 205 | return false; 206 | } 207 | 208 | if (!sphere->LoadMesh("../../ThirdParty/Content/sphere.obj")) 209 | { 210 | std::cerr << " Unable to load Sphere \n"; 211 | return false; 212 | } 213 | 214 | if (!quad->LoadMesh("../../ThirdParty/Content/crytek_sponza/sponza.obj")) 215 | { 216 | return false; 217 | std::cerr << " Unable to load quad \n"; 218 | } 219 | 220 | return true; 221 | } 222 | 223 | bool readFile(const char* pFileName, std::string& outFile) 224 | { 225 | std::ifstream f(pFileName); 226 | 227 | bool ret = false; 228 | 229 | if (f.is_open()) { 230 | std::string line; 231 | while (getline(f, line)) { 232 | outFile.append(line); 233 | outFile.append("\n"); 234 | } 235 | 236 | f.close(); 237 | 238 | ret = true; 239 | } 240 | else { 241 | std::cout << "Error Loading file"; 242 | } 243 | 244 | return ret; 245 | } 246 | 247 | bool prepareShaders(const std::string& v, const std::string& f, Passes pass) 248 | { 249 | GLint success; 250 | std::string vShaderSource{}; 251 | std::string fShaderSource{}; 252 | 253 | readFile(v.c_str(), vShaderSource); 254 | readFile(f.c_str(), fShaderSource); 255 | 256 | const char* vString[1]; 257 | vString[0] = vShaderSource.c_str(); 258 | 259 | vs[pass] = glCreateShader(GL_VERTEX_SHADER); 260 | glShaderSource(vs[pass], 1, vString, NULL); 261 | glCompileShader(vs[pass]); 262 | 263 | glGetShaderiv(vs[pass], GL_COMPILE_STATUS, &success); 264 | 265 | if (!success) 266 | { 267 | char info[1024]; 268 | glGetShaderInfoLog(vs[pass], 1024, NULL, info); 269 | std::cerr << std::string{ info }; 270 | return false; 271 | } 272 | 273 | const char* fString[1]; 274 | fString[0] = fShaderSource.c_str(); 275 | 276 | fs[pass] = glCreateShader(GL_FRAGMENT_SHADER); 277 | glShaderSource(fs[pass], 1, fString, NULL); 278 | glCompileShader(fs[pass]); 279 | glGetShaderiv(fs[pass], GL_COMPILE_STATUS, &success); 280 | 281 | if (!success) 282 | { 283 | char info[1024]; 284 | glGetShaderInfoLog(fs[pass], 1024, NULL, info); 285 | std::cerr << std::string{ info }; 286 | return false; 287 | } 288 | 289 | ps[pass] = glCreateProgram(); 290 | glAttachShader(ps[pass], vs[pass]); 291 | glAttachShader(ps[pass], fs[pass]); 292 | glLinkProgram(ps[pass]); 293 | glGetProgramiv(ps[pass], GL_LINK_STATUS, &success); 294 | 295 | if (!success) { 296 | char InfoLog[1024]; 297 | glGetShaderInfoLog(ps[pass], 1024, NULL, InfoLog); 298 | fprintf(stderr, "Error linking : '%s'\n", InfoLog); 299 | return false; 300 | } 301 | 302 | glUseProgram(ps[pass]); 303 | 304 | if (pass == Passes::Deferred) 305 | { 306 | modelLocation = glGetUniformLocation(ps[pass], "u_Model"); 307 | viewLocation = glGetUniformLocation(ps[pass], "u_View"); 308 | projLocation = glGetUniformLocation(ps[pass], "u_Projection"); 309 | textureLocation = glGetUniformLocation(ps[pass], "gSampler"); 310 | 311 | if (modelLocation == INVALID_UNIFORM_LOCATION || 312 | viewLocation == INVALID_UNIFORM_LOCATION || 313 | projLocation == INVALID_UNIFORM_LOCATION || 314 | textureLocation == INVALID_UNIFORM_LOCATION) 315 | return false; 316 | } 317 | 318 | if (pass == Passes::LightPass) 319 | { 320 | initLightUBO(); 321 | bindUboIndex(ps[pass]); 322 | 323 | mapLocations[POSITION_TEXTURE] = glGetUniformLocation(ps[pass], "u_PositionMap"); 324 | mapLocations[DIFFUSE_TEXTURE] = glGetUniformLocation(ps[pass], "u_ColorMap"); 325 | mapLocations[NORMAL_TEXTURE] = glGetUniformLocation(ps[pass], "u_NormalMap"); 326 | mapLocations[TEXCOORD_TEXTURE] = glGetUniformLocation(ps[pass], "u_TextureCoordMap"); 327 | 328 | } 329 | 330 | glDetachShader(ps[pass], vs[pass]); 331 | glDetachShader(ps[pass], fs[pass]); 332 | glUseProgram(0); 333 | return true; 334 | } 335 | 336 | bool loadShaders() 337 | { 338 | if (!prepareShaders("Deferred.vs", "Deferred.ps", Passes::Deferred)) 339 | { 340 | std::cerr << "Error Loading Deferred Shaders!!!\n"; 341 | return false; 342 | } 343 | 344 | if (!prepareShaders("Light.vs", "Light.ps", Passes::LightPass)) 345 | { 346 | std::cerr << "Error Loading LightPass shaders!!!\n"; 347 | return false; 348 | } 349 | return true; 350 | } 351 | 352 | void debugDeferredPass() 353 | { 354 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 355 | glDisable(GL_DEPTH); 356 | glDisable(GL_DEPTH_TEST); 357 | glDisable(GL_CULL_FACE); 358 | 359 | 360 | glBindFramebuffer(GL_READ_FRAMEBUFFER, g_fbo); 361 | 362 | GLsizei halfWidth = static_cast(windowWidth / 2.0f); 363 | GLsizei halfheight = static_cast(windowHeight / 2.0f); 364 | 365 | /*Draw Position texture*/ 366 | glReadBuffer(GL_COLOR_ATTACHMENT0 + POSITION_TEXTURE); 367 | glBlitFramebuffer(0, 0, windowWidth, windowHeight, 0, 0, halfWidth, halfheight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 368 | 369 | glReadBuffer(GL_COLOR_ATTACHMENT0 + DIFFUSE_TEXTURE); 370 | glBlitFramebuffer(0, 0, windowWidth, windowHeight, 0, halfheight, halfWidth, windowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 371 | 372 | glReadBuffer(GL_COLOR_ATTACHMENT0 + NORMAL_TEXTURE); 373 | glBlitFramebuffer(0, 0, windowWidth, windowHeight, halfWidth, halfheight, windowWidth, windowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 374 | 375 | glReadBuffer(GL_COLOR_ATTACHMENT0 + TEXCOORD_TEXTURE); 376 | glBlitFramebuffer(0, 0, windowWidth, windowHeight, halfWidth, 0, windowWidth, halfheight, GL_COLOR_BUFFER_BIT, GL_LINEAR); 377 | 378 | 379 | glEnable(GL_DEPTH); 380 | glEnable(GL_DEPTH_TEST); 381 | glEnable(GL_CULL_FACE); 382 | 383 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 384 | 385 | } 386 | 387 | void renderDeferredPass(int i) 388 | { 389 | glUseProgram(ps[Passes::Deferred]); 390 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, g_fbo); 391 | glDepthMask(GL_TRUE); 392 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 393 | glEnable(GL_DEPTH_TEST); 394 | glDisable(GL_BLEND); 395 | 396 | //mat4 model = glm::scale(mat4(1.0f), vec3(3.1f, 3.1f, 3.1f)); 397 | model = glm::translate(mat4(1.0f), vec3(-150.0f, -600.0f, -800.0f+camera)); 398 | model = glm::rotate(model, 30.0f, vec3(0.0f, 1.0f, 0.0f)); 399 | 400 | mat4 view = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, -5.0), glm::vec3(0.0, 1.0, 0.0)); 401 | 402 | glUniformMatrix4fv(modelLocation, 1, GL_FALSE, &model[0][0]); 403 | glUniformMatrix4fv(viewLocation, 1, GL_FALSE, &view[0][0]); 404 | glUniformMatrix4fv(projLocation, 1, GL_FALSE, &projection[0][0]); 405 | glUniform1i(textureLocation, 0); 406 | 407 | quad->Render(); 408 | 409 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); 410 | glUseProgram(0); 411 | glDepthMask(GL_FALSE); 412 | glDisable(GL_DEPTH_TEST); 413 | } 414 | 415 | void renderLightPass() 416 | { 417 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 418 | glClear(GL_COLOR_BUFFER_BIT); 419 | glEnable(GL_BLEND); 420 | glBlendEquation(GL_FUNC_ADD); 421 | glBlendFunc(GL_ONE, GL_ONE); 422 | 423 | glUseProgram(ps[Passes::LightPass]); 424 | glBindVertexArray(quadVAO); 425 | bindUbo(); 426 | 427 | for (unsigned int i = 0; i < NUM_GBUFFER_TEXTURES; i++) { 428 | glActiveTexture(GL_TEXTURE1 + i); 429 | glBindTexture(GL_TEXTURE_2D, g_textures[POSITION_TEXTURE + i]); 430 | } 431 | 432 | 433 | glUniform1i(mapLocations[POSITION_TEXTURE], 1); 434 | glUniform1i(mapLocations[DIFFUSE_TEXTURE], 2); 435 | glUniform1i(mapLocations[NORMAL_TEXTURE], 3); 436 | glUniform1i(mapLocations[TEXCOORD_TEXTURE], 4); 437 | 438 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 439 | 440 | glUseProgram(0); 441 | glBindVertexArray(0); 442 | 443 | glEnable(GL_DEPTH_TEST); 444 | glBindTexture(GL_TEXTURE_2D, 0); 445 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 446 | 447 | } 448 | 449 | void display() 450 | { 451 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 452 | glGenerateMipmap(GL_TEXTURE_2D); 453 | glEnable(GL_MULTISAMPLE); 454 | 455 | //for (int i = 0; i < quad->m_Entries.size(); i++) 456 | { 457 | 458 | renderDeferredPass(0); 459 | 460 | #ifdef _DebugDeferred 461 | debugDeferredPass(); 462 | #else 463 | renderLightPass(); 464 | #endif 465 | } 466 | 467 | glutSwapBuffers(); 468 | glutPostRedisplay(); 469 | } 470 | 471 | void changeSize(int w, int h) 472 | { 473 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 474 | glViewport(0, 0, w, h); 475 | projection = glm::perspective(45.0f, w / (float)h, 0.1f, 10000.0f); 476 | windowWidth = w; 477 | windowHeight = h; 478 | } 479 | 480 | void key(unsigned char key, int x, int y) 481 | { 482 | switch (key) 483 | { 484 | case 'z': 485 | camera -= 1.1; 486 | break; 487 | case 'a': 488 | camera += 1.1; 489 | break; 490 | case 'r': 491 | break; 492 | case 'w': 493 | break; 494 | } 495 | } 496 | 497 | void clear() 498 | { 499 | 500 | } 501 | 502 | int main(int argc, char* argv[]) 503 | { 504 | glutInit(&argc, argv); 505 | glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE); 506 | windowWidth = 1350; 507 | windowHeight = 700; 508 | glutInitWindowPosition(0, 0); 509 | glutInitContextVersion(4, 3); 510 | glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); 511 | glutInitWindowSize(windowWidth, windowHeight); 512 | glutCreateWindow("TeslaTessellate"); 513 | 514 | GLenum res = glewInit(); 515 | if (res != GLEW_OK) { 516 | std::cout << "Error: '%s'\n" << glewGetErrorString(res); 517 | return false; 518 | } 519 | 520 | glutDisplayFunc(display); 521 | glutKeyboardFunc(key); 522 | glutReshapeFunc(changeSize); 523 | 524 | //Set initial state and load models 525 | if (!initScene()) 526 | return -1; 527 | 528 | //Load shaders 529 | if (!loadShaders()) 530 | return -1; 531 | 532 | //Prepare Gbuffer 533 | if (!prepareGBuffer()) 534 | return -1; 535 | 536 | PrepareFullQuadVAO(); 537 | 538 | glutMainLoop(); 539 | 540 | clear(); 541 | return 0; 542 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deferred-renderer 2 | Deferred Renderer with many point lights. 3 | 4 | ![Alt text](https://github.com/PixelClear/Deferred-renderer/blob/master/DF_24.png) 5 | 6 | 7 | Youtube Demo: 8 | 9 | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/4VFJP1MRuUs/0.jpg)](https://www.youtube.com/watch?v=4VFJP1MRuUs) 10 | --------------------------------------------------------------------------------