Tuesday, April 16, 2013

[Download] Texture Atlas Material Function

A little addendum to my last post: [How-To] create UE3/UDK Texture Atlases (tileable) 

Here's  a material function which will work with varying setups, no matter what atlas size, border width or amount of sub-textures. The only restriction is a square atlas (e.g. 1024x1024, 2048x2048, 4096x4096).

Download:http://www.mediafire.com/?iax7tyrid5464op

Should show up in the material function library once the package is loaded. I just copied mine over to one of the Engine Material Function packages for easy accessibility.


Monday, April 8, 2013

[How-To] create UE3/UDK Texture Atlases (tileable)

The basic material setup is described at the UDN page: http://udn.epicgames.com/Three/TerrainAdvancedTextures.html#Texture%20Packing:%20Implementing%20large%20texture%20tile%20sets
As stated there will occure noticable seams when using this setup for tileable textures like on a terrain.
Usually you will end up with something like this:



 In fact there are two separate kind of issues which need to be fixed both.
- some kind of pixel artifacts caused by the 'frac' function
- texture seams caused by mipmapping


1.) To fix the pixel artifacts it is nesseccary to use a custom node with some HLSL code. Since we use a frac function there is a huge difference in texture coordinates across a seam, something like 0.49 to 0.01 (assuming an atlas with 4 textures). Such gaps usually occure only when a surface is far away from the camera, which makes the GPU to chose the smallest mipmap for these pixels. So what you can see here is not just a random artifact but the same texture at a very low resolution:




For the hlsl part we make use of the tex2dgrad function. This one allows us to use different texcoords for the actual texturing and the mipmap selection. To get rid of the artifacts it is as easy as using simple texture coordinates (without frac) for mipmapping, whilst 'frac coords' determine the texture mapping.



Keep in mind that custom nodes require custom textures or texture objects as an input to sample a textur.
If sampling a normal map in a custom node it is necessary to manually bring it from [0,1] to the [-1,1] range. Therefore multiply your final normal input by 2 and subtract 1:





2.) The second issue is indeed a 'real' seam, caused by mipmapping and linear filtering.



The basic idea for fixing those seams is to slightly shrink the sub textures and add a border afterwards. As a result mipmaps won't contain pixels of adjacent tiles, therefore the effective size of your texture will decrease. The wider the border, the more mipmaps won't contain seams.
You can find a detailed description of a corresponding workflow here: http://mtnphil.wordpress.com/2011/09/26/terrain-texture-atlas-construction/

The proper border width can vary depending on your gameplay, level design or atlas composition (speaking about textures with similar brightness and color).
Where n is the mipmap up to which you'd like to get rid of seams, the border x should be x^n pixels wide.

Back in the material editor the texture needs to be scaled and offset. The exact values depend on atlas/tile size and border pixel width. The scale is defined as effective tile size / real tile size.
The offset is done in increments of border pixels / atlas size.
Starting from the left, upper corner the first texture needs to be offset by one increment on both, the x- and y-axis. Each following textures requires 2 additional offset increments.

A screenshot is worth a thousand words, this is my material setup for a 2048²px atlas with 4 sub textures. Each texture has a 8px border which makes the effective size being 1008²px (instead of 1024²px):




Final result:



Wednesday, January 16, 2013

UDK Benchmark WiP #4


After creating the cave scene for testing multiple dynamic lights I am now working on the outdoor area whose key features will be a dynamic sunlight and lots of foliage (=alpha testing).



Wooden Props















The workflow for all objects with a unique texture (e.g. table, cart, bench, barrel...) is almost identical to each other. Game and LoD mesh is modeled from scratch with as much matching UV coordinates as possible. Based on the game mesh I did create a high poly sculpt to bake a normal map for correct shading and large scale details. This normal map is being combined with a small detail normal map which has been generated out of the diffuse map.
For objects with multiple materials (usually bigger ones with tileable textures) I'm using a low res texture atlas for the LoD model to cut down the amount of materials to 1.

Here's an example of the wooden planks which are part of the bridge model:





Foliage

For performance reasons I'm using static meshes for most trees of small and mid scale. Only a few big / special trees are created with speedtree to save me some time.

The triangle count of these 3 trees is ~1300/1800/900:


Turntable .gif (4.8MB): http://www.abload.de/img/foliage_trees_rendert2eqos.gif




Instead of fiddling around with photo resources I just modeled some grass by hand. These grass blade meshes are easily editable and can be rendered from an orthographic side view to quickly get a diffuse and alpha opacity map.






Landscape Meshes


To create an interesting landscape I decided to combine custom rock meshes with UE3' landscape tool.

Modeling is done in at least 2 iterations with increasing subdivisions and details. This makes it easily possible to use work-in-progress meshes as LoD models:



For both, the grass parts of those rock meshes and the UE3 landscape I'm using a material with triplanar textur projection for seamless blending between both. As a side effect the custom meshes can be textured without any seams or heavy texture stretching.


Thursday, November 29, 2012

Risen 2 Mods

After several months of not playing Risen 2, I just got back to modding again.


[Risen 2] Food/Plant Inventory Mod

All food and plant items have individual stats now. None of them will be subsumed under provisions anymore. It is also possible to roast meat and fishes at campfires (requires toughness level 2). Besides I've created new Icons for all additional food items.



Download: upload.worldofplayers.de/files8/Food_Inventory_Mod_v1.1.zip

Extract the .zip file and copy Food_Inventory_Mod_v1.1 to the following directory:
%localappdata%\Risen2\Config\ , f.e. C:\User\MyName\AppData\Local\Risen2\Config\




[Risen 2] Player Interact Mod

The Hero can now use additional interacts which had been reserved for NPCs only before.

New interacts:
- bongo
- cooker
- grindstone
- nailing crates
- water barrel


Download: http://upload.worldofplayers.de/file...nteractMod.zip

Extract .zip file and copy PlayerInteractMod to the following directory:
%localappdata%\Risen2\Config\ , f.e. C:\User\MyName\AppData\Local\Risen2\Config\


_________________________________________




Here's a list of my previous R2 mods:

LoD Distance Mod http://oliverm-h.blogspot.de/2012/05/risen-2-lod-distance-mod.html

Dynamic Torch Light Shadows http://oliverm-h.blogspot.de/2012/05/risen-2-dynamic-torch-light-shadows.html

Crosshair Mod http://forum.worldofplayers.de/forum/threads/1147095-Risen-2-Post-Process-Shader-Mods?p=18954667&viewfull=1#post18954667

Small Fonts http://forum.worldofplayers.de/forum/threads/1141220-Modding-in-Risen-2/page12?p=18998808&viewfull=1#post18998808

No POM Mod http://oliverm-h.blogspot.de/2012/05/risen-2-no-pom-mod-update.html

Specular Lookup Texture http://forum.worldofplayers.de/forum/threads/1149575-Risen-2-FPS-Mods?p=18999610&viewfull=1#post18999610

No Dynamic Point Lights Mod http://forum.worldofplayers.de/forum/threads/1149575-Risen-2-FPS-Mods?p=19063721&viewfull=1#post19063721

(Risen 2 Tuning (german))