FOnline Development > 3D Development

Shaders and effects

(1/16) > >>

Johnnybravo:
Well summer is not really friendly to development or work in general, but I realised some people would probably like to already try doing some stuff so I won't delay it any further due to less relevant technical details.

First off you will need to grab the effect (http://pastebin.ca/2077908), save this as arbitary plain text file in your client/effects directory ( I use 3D_SPecularMapping.fx )
You will also need to add following structure to your IOStructures.inc (this is text file as well)

--- Code: ---struct VsToPs_3DNormal
{
float4 Position     : POSITION;
float2 TexCoord     : TEXCOORD0;
float3 Normal       : TEXCOORD1;
};

--- End code ---
Note - by chance this is exactly the same as 3DTangent and I'll reuse it correctly when I'm done with that, so this is just the part of WIP version and might be changed eventually, but I'm aware this is duplicate in this form :d.

When you are done with this, you shouldn't need to worry about effects themself, but if you want to edit them, turn of your client, delete effects cache (D3D allows saving shaders as binary data, saving some time, however nobody checks for anything, so you have to empty it to have them recompiled). If you cannot notice the effect, or have no shadows, check out fonline log file to see the error during compilation.

Now you need to use this effect. I expect some external definitions from fo3d file in my WIP version, so you should add it to your file
Here's example how to use effect, as well as to pass required value to your file

--- Code: ---Effect 3D_SpecularMapping.fx
EffDef Floats Specular_Power 16.0

Model Armor_APA.x
--- End code ---

And now one last thing - you need to specify specular texture to actually see anything, since texture 0 is already used by default shaders for diffuse part, and texture 1 for normal map, this shader uses texture 2 for specular maps.
So just append
--- Code: ---texture 2 <path>
--- End code ---
after texture 0 definitions and it'll correctly load.

Little tip to creating such texture: Transparency is calculated using normals on model, so you'r texture is supposed to cover whole model, and not just be diffuse texture with highlights painted on it. It's added on already calculated colors, so black parts will not actually darken anything, but just have no reflection appearing on it.
For metalic surface playing with levels should be enough, but for the best result you might want to actually paint the metal as if it was lit from every side.

Have fun with it, and post if you got any problem or questions, I'll add some effects and their variation later, and I'll answer questions about any effects, not just specular reflection, so if you got any idea feel free to ask.

Luther Blissett:
Awesome! I'm excited like a child at Christmas :)

Going to try and test this tonight. If it works, expect a few screenshots later.

[edit] Totally works :)

Example text files stuff :

In "_FOHuman.fo3d" :

The old one I had attached was written like so :

--- Code: ---# Body
Layer 3
[...]
Value 27 Root Attach Armor_%anim%_ncr_patrol.x Texture 0 Armor_male_ncr_patrol.png

--- End code ---

That is roughly "make ~param 0 153 27 give me that model with that texture".

The shiny one is written like so :

--- Code: ---# Body
Layer 3
[...]
Value 29 Root Attach Armor_male_ncr_patrol.fo3d
--- End code ---

That is roughly "make ~param 0 153 29 give me whatever that fo3d file is".

Then the Armor_male_ncr_patrol.fo3d file contains :


--- Code: ---Effect 3D_SpecularMapping.fx
EffDef Floats Specular_Power 16.0

Model Armor_male_ncr_patrol.x

Texture 0 Armor_male_ncr_patrol.png
Texture 2 Armor_male_ncr_patrol_spec.png
--- End code ---

Texture 0 being the same as previous, texture 2 being the specular map. My example one is rubbish, so I won't post a screenshot, but trust me when I say it works.

If you comment out the "texture 2" line (or if the line just didn't exist) then there is no specular map, so it assumes "all non-shiny". The improved light and shadow still works in this case.

[edit 2] If you put the Effect and Effectdef lines at the top of the base human fo3d file, it applies the lighting setup to the base model. This is currently with no specular texture included but as mentioned, the light / shadow is there.

In my opinion it's beginning to look awesome already.

Karpov:
Johnny Bravissimo!
It is amazing.

Also, great job Luther, keep up your experiments  ;).

ok ok, I have to test this, bye.

Johnnybravo:

--- Quote ---[edit 2] If you put the Effect and Effectdef lines at the top of the base human fo3d file, it applies the lighting setup to the base model. This is currently with no specular texture included but as mentioned, the light / shadow is there.
--- End quote ---
It's because I've changed some parameters to make it feel more like on sprites, and when there's no specular power defined, specular will be skipped at minimal loss.
Though it'll make better sense to just add extra effect for those who want to use it that way.

Oh and feel free to mod "eye" vector ( should be relative position of camera, normalized )
and "LightDir" vector (obvious from name), changing "eye" will result on different specular highlights, changing lightdir will change everything.
You might also want to try higher ambience as I might have lowered it way too much.
That is if you want to play around with simple things ( don't forget to clear your chache each time you change it, server don't need restart ).

By the way, thanks for bluesuit comparsion, seems like this will need better filtering and perhaps bigger resolution of textures.
Not sure how'd normal map improve it (it definetly would though, but would probably require quite high resolution to do more than just to form the chest/pelvis details), but the main problem now is that it looks blurry.

As for normal maps, not sure if it works because did not see it working, but no reason for it to not work. There's some statement for calculating tangent space and shader is already included in base repositary. It would be quite easier to work it out if there was enough [english] documentation. But considering the difficulty of creating this layer it shouldn't be priority at the moment.

BTW: check out VB female, it has quite awesome model job, and especialy smoothing is well done, when shaded per pixel it's pretty smooth even without any normal map.

Luther Blissett:

--- Quote from: Johnnybravo on August 24, 2011, 03:50:02 am ---It's because I've changed some parameters to make it feel more like on sprites, and when there's no specular power defined, specular will be skipped at minimal loss.
Though it'll make better sense to just add extra effect for those who want to use it that way.

--- End quote ---

Well ultimately, the base models need better light/shadow than their default - I believe the original settings will have been for the Van Buren models, and your settings seem to work much better on the base models, even without the shiny stuff. In bluesuit screenshot above, it's already much closer to the original sprites (I've tested a lot of the other base skins too, and though not yet perfect, it's starting to look great).

It may be possible to add a "universal normal map" to all of the base model textures, as they are all based off the same model - so if the effect was added with normal map into VbMaleStrong.fo3d, then all base models should use it - with the 0 layer diffuse map being selectable as it currently is... I think.

In this case though, there are only a couple of clothing layers which would use specular - the NCR longcoat trooper has metal chest plates for example. I'm not sure if there are any others. If there's only this one, then I may as well remake the NCR longcoat model, and make the metallic chest plate part of the armour model instead of a clothing texture, therefore leaving all clothing textures as non-metallic.

You mention "Though it'll make better sense to just add extra effect for those who want to use it that way." - does it use up processing power to calculate the specular stuff without a texture 2 layer? i.e. if we use this full effect on non-shiny materials, are we wasting processing? If so, would it be possible to adapt this to just use diffuse and normal maps, with the improved lighting and shadow you've set up?

Quite difficult to explain, but I mean "should we have two different 3D effects", like :

1) Default effect for all 3D models. Uses diffuse map (layer 0) and normal map (layer 1). Uses the improved lighting and shadow settings you've developed.

2) Everything as above, with the addition of specular map (layer 2) to be used on metallic armours.

If the unused specular layer doesn't use up extra processing, is there any reason you can think of to not just use Effect #2 on all the models?

Navigation

[0] Message Index

[#] Next page

Go to full version