Friday, November 24, 2017

[Hlsl] Parallax Mapping Tutorial

If you don't have a clue what Tangent Space is about, read this.

This time, Parallax Mapping will be discussed.

Theory
Well, what is a Parallax supposed to be anyway? It's quite a common phenomenon. Actually, it's so common most people wouldn't even notice it as anything out of the ordinary. Let's take a spedometer as a common example for people not sitting behind the steering wheel.

Let's suppose dad's driving at 100km/h. His spedometer also shows that amount more or less. But mom sitting next to him, will see him driving a tad slower. Why, you might ask? Well, it's because dad's viewing the spedometer from the front, so the pointer will sit on top of '100'. From the point of view of mom, it'll be hovering above, let's say, 95km/h. This is because she is viewing it at an angle and there's a depth difference between the needle and the text.

here.


/* VERTEX SHADER
outVS.toeyetangent = mul((camerapos - worldpos),tbnMatrix);
*/


// PIXEL SHADER
float3 toeyetangent = normalize(toeyetangentin);


// The only thing we're doing here is skewing textures. We're only moving 
// textures around. The higher a specific texel is, the more we move it. 
// We'll be skewing in the direction of the view vector too.


// This is a texture coordinate offset. As I said it increases when height
// increases. Also required and worth mentioning is that we're moving along with
// the viewing direction, so multiply the offset by it.
// We also need to specify an effect multiplier. This normaly needs to about 0.4
float2 offset = toeyetangentin.xy*height*0.04f;
texcoordin += offset;


In its most basic form, this is all you need to do Parallax Mapping working. Let's sum things up, shall we?
  • Textures lack depth. Depth is necessary to bring back a 3D feel to it.
  • An important part of the depth illusion is Parallax. We want to bring it back into our textures.
  • To do that, we need to obtain texel depth and the viewing direction. The viewing direction needs to be supplied in Tangent Space to the pixel shader.
  • To do that we need to supply normals, binormals and tangents to the vertex shader. Combining these to a matrix and transposing it gives us the opportunity to transform from world to texture space.
  • Then supply texture coordinates and the tangent space view vector to the pixel shader.
  • Then sample depth from a regular heightmap. Multiply it by the view vector.
  • And tada, you've got your texture coordinate offset. You're then supposed to use this texture coordinate for further sampling.
Let's post a couple of screenshots then. First the one without any parallax mapping.


Now it does include a Parallax Map. It uses a multiplier of 0.4 and a single sample.


Yes, a single sample is all you need. No need to do PCF averaging or anything. Just a single tex instruction per pixel. But as you can see in the latter picture, there are some minor artifacts, especially on steeper viewing angles. To partially fix this, you need to include an offset constant, like this:


float2 offset = toeyetangentin.xy*(height*0.04f-0.01f);
texcoordin += offset;



With this result:


Well, that's pretty much all there is to it. Have fun with it!

Dev-C++ 4.9.9.3 Released

After a couple of years working with this fast and portable C/C++ IDE, I've decided to give it an update. That's because the compiler was getting ancient, and it contained a few bugs here and there. It took a while to get the hang of Delphi, but hereby I present to you Dev-C++ 4.9.9.3:




Changes - Version 4.9.9.3 - 24 Juni 2011
  • Upgraded the Default Compiler to GCC 4.5.2.
  • When encountering an error, Dev will now point you to the error line and (new) positions the cursor next to it.
  • Added new -march optimization options (core2, k8-sse3, amdfam10). Also added 'native' and 'generic'.
  • Cleaned up the explicit -m(some instruction set) options, and added some important ones.
  • Cleaned up the TODO viewer.
  • Fixed a bug in the GCC output parser: it used to read 1 byte too much afer the \0 of each line, causing crashes.
  • Added a column column in the Compiler log.
  • Tweaked the default settings. Enable line numbers by default for example.
  • Fixed a bug in the Compiler Set creator: it didn't feel like storing command line options for each Compiler.
  • Added more UI controls for frequently used GCC flags like -Wall, -Wextra and -pedantic.
  • Moved warning related flag options to a new section called 'Code Warnings'.
  • Removed the silly optimization controls. Now has a proper None/Low/Med/High combobox.
  • Updated the default directory listings to GCC 4.5.2's directories.
  • Removed the [Compiler] section from the ini file. Instead of saving the current Compiler Set twice, it saves a Compiler index to refer to.
  • By default GCC4 omits required runtime DLL's from executables. I told it to link them by default.
  • And some more stuff I forgot about.


Important notices
  1. The options format has changed. If you want to reuse an old config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3 project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.


Download
The setup can be downloaded here. The source code can be found here.


Problems
  • FIXED: There seems to be a persoalan with the default relative include paths not being used properly. I seriously need to fix that soon (this weekend probably, after vacation). Together with a few more things to do, I of course also need to post the source code somewhere.

Dev-C++ 4.9.9.4 Released

Time for an update then. The last version was not-so portable in many ways. This one is. Together with doing a lot of portablizating, I've done a bunch of cleaning up, housekeeping and restyling.




Changes - Version 4.9.9.4 - 12 Juli 2011
  • Added a %path% macro to every path. Use this string in the config files to add relative paths to Compiler Directories.
  • Fixed a bug in the Code Completion Cache Creator (CCCC :D): it used to add 2 copies of every file (one relatively referred to and one referred to with a full path).
  • Cleaned up a few duplicate and unused headers and binaries. The installer is now a whopping 200KiB smaller.
  • Updated the make.exe searcher to check for GCC 4.5.2's make.exe.
  • Added a few install profiles: minimalist and portable.
  • Fixed a few grammar errors.
  • Updated the About window.
  • Added an icon to the installer.


Important notices
  1. The options format has changed. If you want to reuse an old config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3 project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.
  3. This version is now fully portable. If you also don't want Dev to leave anything behind in the registry, please select "Portable" or "Minimal" in the setup options.


Download
The setup can be downloaded here (includes full and portable versions). The source code can be found here.


Problems
  • FIXED: Need to add some processing code for a few rare output messages new to GCC 4.

Dev-C++ 4.9.9.5 Released

Yes, another update. This one comes with a few more urgent fixes and a portable version (the previous setup left some marks on PC's) can be downloaded in a zip format.




Changes - Version 4.9.9.5 - 16 Juli 2011
  • Added column reporting for a few more error types.
  • Made a proper portable version this time: it comes in a 7zip file, saving a few more registry entries compared to 4.9.9.4's portable setup.
  • The uninstaller now adds itself to Windows' "Programs and Features" list.


Important notices
  1. The options format has changed. If you want to reuse an old config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3 project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.
  3. This version is now fully portable. If you also don't want Dev to leave anything behind in the registry, please select "Portable" or "Minimal" in the setup options.


Download
The setup can be downloaded here. The Portable zip version can be downloaded here. The source code can be found here.


Problems
  • FIXED: The NSIS installer overestimates the installation size before unpacking by 50MiB. Don't have a clue why.
  • FIXED: Some old (pre-4.9.9.3) setup code forces users to not install Dev in a path which includes spaces. However, when I tried running the portable version from inside "Program Files (x86)", everything worked just fine. Bottom line: I need to do some housekeeping in that NSIS code.

Dev-C++ 4.9.9.6 Released

Well, times for some fixes then. This version fixes all the bugs I'm aware of and comes with an upgraded versioning system.




Changes - Version 4.9.9.6 - 20 Juli 2011
  • Fixed the language option in the executable information tab. It didn't properly set the listbox to the saved setting (losing settings upon next save).
  • Fixed a bug in the file association code: icons were missing.
  • Lines like 'in member function', 'in constructor' and 'in destructor' are now properly formatted in the Compiler Tab (no line and col numbers anymore).
  • Added line and column formatting for 'In static member function'.
  • Fixed the file version string: it now keeps in sync with incremented build numbers.
  • The spin edits which control the Project file version are now kept in sync with the strings below.
  • Added an option to synchronize product and file versions.
  • Set the default installation directory to C:\Program Files (x86)\Dev-Cpp instead of C:\Dev-Cpp.


Important notices
  1. The options format has changed. If you want to reuse an old config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3 project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.
  3. This version is now fully portable. If you also don't want Dev to leave anything behind in the registry, please select "Portable" or "Minimal" in the setup options.
  4. For ultimate portable programming, please launch devcppPortable.exe.lnk located in the main folder of the portable zip download. This will make dev save its configuration files in the same folder as the executable.


Download
The setup can be downloaded here. The Portable zip version can be downloaded here. The source code can be found here.


Problems
  • FIXED: 'Candidates are' is gone when compiler suggests functions.
  • FIXED: 'include\sys\' and 'include\' auto-include directories are conflicting.
  • FIXED: Current line and column are not set when opening a file.
  • FIXED: error: (instead of note:) Candidate is: is not properly formatted.

Dev-C++ 4.9.9.7 Released

This one fixes some urgent stuff I found with the debugger together with a load of other stuff. Oh, by the way, this version has been tested extra long and comes with the first user reported bug!




Changes - Version 4.9.9.7 - 26 Juli 2011
  • Function candidates are now properly listed and formatted.
  • When code completion was disabled, block tabs/untabs weren't working.
  • Added formatting for the rare 'candidate is' (when there's one candidate of course) message.
  • Removed the include\sys directory from default auto includes. It was conflicting with ctime/time.h.
  • Updated a few English window and control captions.
  • Removed a faulty cast the Delhpi Debugger pointed me to.
  • Projects now open the first instead of no file in the list by default.
  • When switching between files, the statusbar (line:col and number of lines) now gets updated automatically.
  • Added formatting for "error: candidate is:".
  • Fixed a bug in the directory scanner: it used to omit every first file in any given directory.
  • Block indentation is now only triggered by tab when multiple lines are selected.
  • devDirs now saves relative paths too.


Important notices
  1. The options format has changed. If you want to reuse an old pre-4.9.9.3 config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3+ project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.
  3. This version is now fully portable. If you also don't want Dev to leave anything behind in the registry, please select "Portable" or "Minimal" in the setup options.
  4. For ultimate portable programming, please launch devcppPortable.exe.lnk located in the main folder of the portable zip download. This will make dev save its configuration files in the same folder as the executable.


Download
The setup can be downloaded here. The Portable zip version can be downloaded here. The source code can be found here.


Problems
  • FIXED: The uninstaller's version string is lagging (it reports 4.9.9.5).
  • FIXED: 'unknown escape character' lacks formatting.
  • FIXED: Portable configuration files are now saved in root\config instead of root. Dev 4.9.9.7 refuses to create config folders (and root was getting messy).
  • FIXED: The Simple Window example now has a working project (main.c should be main.cpp).
  • NOT FIXED: Dev-C++ crashes when it tries to terminate console programs running inside cmd/conhost
  • FIXED: Added the flags to the compiler option descriptions.
  • FIXED: The compiler now correctly remembers if it has created debug symbols.





Thursday, November 23, 2017

Dev-C++ 4.9.9.8 Released

This one is the last one developed in my lots of free time. Got a job now and I'm going to college within a month, so I probably won't be fixing as fast as before. But nevertheless, this version comes with yet another bunch of fixes.




Changes - Version 4.9.9.8 - 1 Augustus 2011
  • Fixed the uninstallers name: it used to report '4.9.9.5'.
  • Added formatting for 'unknown escape sequence:'.
  • Portable configurations are now saved in .\config\ instead of '.\'. Looks much cleaner this way.
  • The Simple Window example now works correctly.
  • Added the flags that are actually set to Compiler Options.
  • The compiler now correctly remembers if it has created debug symbols.
  • And some more stuff I forgot about.


Important notices
  1. The options format has changed. If you want to reuse an old pre-4.9.9.3 config file (NOT recommended), or, more importantly, when you're overriding Compiler Options in your project, you need to re-set these project settings once and save the project. You'll then have an updated 4.9.9.3+ project file.
  2. This version has GCC built-in instead of being an aditional package. It also contains D3D9/10/11, GDI, Win32 and OpenGL headers and libraries in that flavor.
  3. This version is now fully portable. If you also don't want Dev to leave anything behind in the registry, please select "Portable" or "Minimal" in the setup options.
  4. For ultimate portable programming, please launch devcppPortable.exe.lnk located in the main folder of the portable zip download. This will make dev save its configuration files in the same folder as the executable.


Download
The setup can be downloaded here. The Portable zip version can be downloaded here. The source code can be found here.


Problems
  • NOT FIXED: Dev-C++ stalls when it tries to terminate console programs waiting at "Press any key" lines.
  • FIXED: Typing stuff like foo[bar.member] spawns the completion tooltip of foo when typing the '.' after bar.
  • FIXED: Control-clicking now works again when navigating through classes/variables.
  • FIXED: Pasting chunks of code that require scrolling now force a refresh instead of showing gibberish.
  • FIXED: The portable shortcut now tries to run .\devcpp.exe instead of one in Program Files.
  • FIXED: Added a D3D9 example template.
  • FIXED: The portable shorcut is now a proper relative (AutoIt) one.