Notifications
Clear all

inside FFED3D (the FFED3D tech thread)


Gernot66
(@gernot66)
Lieutenant Registered
Joined: 7 years ago
Posts: 522
Topic starter  

a short introduction

this thread is ment for precise technical questions about FFED3D

it's not ment for "why crashes it on my system" or "mouse problems" or whatever of this sort of problems one can have

it's rather ment for things like "i altered the shader scripts, do you think it's a good solution?"
or "how can i alter the shader scripts"
or "how do the ship specifications work?"
or "how can i put this specific model into FFED3D?"
or "what tools do i need to create a model for FFED3D?"
or "what do i have to respect if i like to compile my own build?"
or "is it possible to compile ffed3d for a different platform?"

some of them would be real questions i have

have phun
gernot66


Quote
Gernot66
(@gernot66)
Lieutenant Registered
Joined: 7 years ago
Posts: 522
Topic starter  

here we go
this is my first Q:
"i altered the shader scripts... bla bla"

i wrote this already in my models thread that i "abused" the texture to reach a sort of control over the specularity.
it's not a really good solution quick and dirty as usual if it's made by me.

i simply did this (in general):
and altered following entry in the shader script for the ships (i.e. it's also suitable for all models)
float3 specular = (lightcol * VdotR);
to
float3 specular = (lightcol * VdotR * tx_base);

that works, but i have no idea how "elegant" this solution is

by multiplying the specularity with the texture you simply reduce specularity on the darker textured areas while the bright ones will have a glossy specularity.
for metallic surfaces this looks quite ok.

the common "plastic surface" look in ffed3d:
![]( "")

the same surface in a similar angle to lightsource with reduced specularity
![]( "")

again, but now the belly of the eagle to really show what's the effect to the black lines compared to the bright metal
![]( "")

but this cheap solution isn't really satisfying
i can't tell a black window like surface shall be glossy
neither i can tell a bright concrete wall shall be matt.

of course for this i need a specularity map
no problem - i thought
but not for long
it's a problem
i really couldn't figure this out

i opened and registered a new texture sampler e.g. s_spec with the texture "spec" (spec.png)
and tried to use the greyscale in a similar way as the diffuse color texture
but if i use the output to multiply it with the specularity the result is a totally flat shaded model
and nothing of what is to expect is to see.

i'm pretty sure i'm only to unexperienced and made probably many mistakes.

it would be fine if someone would pick up this idea
because with a clever used specularity map you can even control depth for a surfaces structure
and this makes bump-mapping obsolate imho.
of course i can't trick a stud of a lego brick where is no stud likewise with a bump-map.
but i can make a surface which has depth and that's enough to reach.

and if we have a spec-map
of course we need a
glow-map
this would round off the things, it will be "das tüpfelchen auf dem i".
space stations with lit windows even or especially on the dark side.

---

there is a chance that this Q. is already obsolate
because i missed to download the latest build last time


ReplyQuote
AndyJ
(@andyj)
Senior Chief Registered
Joined: 7 years ago
Posts: 91
 

OK so I propose that we keep this thread to the ship skins for the time being.

In the main "announcement" thread, Gernot posted the following. (I've formatted a little and hidden the shader in a spoiler)

- - -

comparison

**without secularity map**
![]( "")

**with simple reuse of the diffuse texture as specularity map**
![]( "")

i know the latter has a slightly different angle but i did best to show at least a little specularity because it really lowers it much

(Formatted HLSL Shader code)
>!
>! float4x4 viewprojmat; // view*proj
>! float4x4 worldmat; // world
>! float4 light; // light source
>! float4 lightcol; // light color
>! float4 ambient; // ambient color
>!
>! int skinnum; // the skin number for this model instance
>!
>! texture skin; // skin.png
>! texture spec; // spec.png
>!
>! sampler s_tex = sampler_state
>! {
>! texture = ;
>! AddressU = WRAP;
>! AddressV = WRAP;
>! MIPFILTER = LINEAR;
>! MINFILTER = LINEAR;
>! MAGFILTER = LINEAR;
>! };
>!
>! struct VS_OUTPUT
>! {
>! float4 position : POSITION;
>! float3 normal : TEXCOORD1;
>! float2 tex_vu : TEXCOORD0;
>! float3 lightDir : TEXCOORD2;
>! float3 eye : TEXCOORD3;
>! };
>!
>! VS_OUTPUT Vexel_Sh (
>! float4 pos : POSITION,
>! float3 nor : NORMAL,
>! float3 tangent : TANGENT,
>! float2 tex_vu : TEXCOORD0
>! )
>! {
>! VS_OUTPUT Out = (VS_OUTPUT)0;
>!
>! float4 vertex = mul(pos, worldmat);
>!
>! Out.position = mul(vertex, viewprojmat);
>! Out.normal = normalize(mul(nor, (float3x3)worldmat));
>! Out.tex_vu = tex_vu;
>!
>! Out.lightDir = normalize(light);
>! Out.eye = -normalize(vertex.xyz);
>!
>! return Out;
>! }
>!
>! float4 Pixel_Sh(
>! float2 tex_vu : TEXCOORD0,
>! float3 normal : TEXCOORD1,
>! float3 lightDir : TEXCOORD2,
>! float3 eye : TEXCOORD3
>! ) : COLOR0
>! {
>! float4 ut;
>! float4 tx_base = tex2D(s_tex, tex_vu);
>! float3 diffuse = tx_base * lightcol;
>!
>! ut.rgb = saturate(max(0.05,dot(lightDir, normal)) * diffuse * 2.0 );
>!
>! float3 R = normalize(reflect(-lightDir, normal));
>! float VdotR = saturate(dot(R, normalize(eye)));
>! VdotR /= 128.0 - VdotR * 128.0 + VdotR;
>! float3 specular = lightcol * VdotR * tx_base;
>!
>! ut.rgb += specular;
>! ut.a = tx_base.a; //Take alpha from skin to allow transparent glass etc
>!
>! return ut;
>! }
>!
>! technique PixelLight
>! {
>! pass P0
>! {
>! VertexShader = compile vs_3_0 Vexel_Sh();
>! PixelShader = compile ps_3_0 Pixel_Sh();
>! }
>! }
>!

as one can see the use of the code format is a little difficult (hrmpf)
but ok that's how i changed it for the models, the declaring on top for a spec texture is still present but not needed for this
the rest of my experiment i removed except for the reuse of the diffuse texture, which is

float3 specular = lightcol * VdotR * tx_base;

instead of

float3 specular = lightcol * VdotR;

probably my experiment still exists but i'm a bit afraid to show it off

in the 2nd picture of the eagle it looks quite matt but when you (could) move the camera it gives you a different impression.
the texture of the eagle is made to be as crispy as possible for such a reuse of a diffuse map, in this simple way for years the pioneer models was shaded,
with the difference that in the script the diffuse texture first has been converted to a greyscale map to lower the specularity.
if i liked to have something glossy i had the possibility to set this in the material i use for a untextured material.

but i'm a absolute beginner when it comes to shader scripts, i did some experiments already many years ago when did my first steps in modelling
i know that i already for the courier changed them back then to have a less synthetic look and i guess i even added the star color to it and removed
the reflection of the thruster flames and such lights loosed therefore the semi transparency.
i used back then the shader output of 3dsmax for it, the output doesn't varies much to what was used for FFED3D.
thus i had at least a idea where to start.


ReplyQuote
AndyJ
(@andyj)
Senior Chief Registered
Joined: 7 years ago
Posts: 91
 

OK so I'm a newbie myself to HLSL shaders, and it's quite hard to find information "out there" on the web. Most information now will be DirectX 10 or later - for FFED3DAJ, the shaders are DirectX9 and also XNA examples are appropriate.

At present, neither my own version FFED3DAJ or the original FFED3D beta supports multi-pass shaders, although that is something I am looking at implementing at the moment.
I have a bump-map shader sort-of working on the Asp, but it may need more than one pass to be really effective, and it also suffers from the terrible too-bright/too-dark lighting that can be seen in the "without specularity" picture.

OK, so I'm assuming this shader is specific to the model, placed within its folder, and named as "effect.fx".
If you wish to use a separate grey-scale image for the specularity map rather than the diffuse map (skin) then there are 5 extra textures that you can specify in the textures.ini flle which you can make use of. They are specified in the same way as the alternate skins, just add: texture1=spec.png etc as required.

In your HLSL shader I noticed that there is still a declaration for the specularity texture.
.
So change

texture spec; // spec.png

to be

texture texture1; //spec.png

.
And after

sampler s_tex = sampler_state
{
...
};

You'll want to add something similar for your specularity map that references "texture1" - e.g..

sampler spec_tex = sampler_state
{
texture = ;
AddressU = WRAP;
AddressV = WRAP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};

.

With that done, you can now reference it in the pixel shader instead of reusing the skin.

float4 Pixel_Sh(
float2 tex_vu : TEXCOORD0,
float3 normal : TEXCOORD1,
float3 lightDir : TEXCOORD2,
float3 eye : TEXCOORD3
) : COLOR0
{
float4 ut;
float4 tx_base = tex2D(s_tex, tex_vu);
float3 diffuse = tx_base * lightcol;

ut.rgb = saturate(max(0.05,dot(lightDir, normal)) * diffuse * 2.0 );

float3 R = normalize(reflect(-lightDir, normal));
float VdotR = saturate(dot(R, normalize(eye)));
VdotR /= 128.0 - VdotR * 128.0 + VdotR;

float4 spec_base = tex2D(spec_tex, tex_vu);
float3 specular = lightcol * VdotR * spec_base;

ut.rgb += specular;
ut.a = tx_base.a; //Take alpha from skin to allow transparent glass etc

return ut;
}

That's totally untested of course 😆 as I've not got your graphics ... but should work ... (he says, nervously!)
.
The reason that your shader didn't work in the past with the extra texture and "sampler" declaration is because the game executable has to actually load the texture into memory and make it available to the shader. You then have to reference it correctly in the shader. I added the extra "texture1" to "texture5" settings in the textures.ini file so that shaders can be enhanced in this way. 🙂

.
... goes off to check own experimental shader ...
.

Hmmm!
Actually I was also creating a specular value in another version of the Asp shader by using the diffuse skin in just the same way, but I hadn't copied that part into the latest shader at all.
And even though I'd specified a separate specular map image in the textures ini, I hadn't actually referenced it in the shader as I've just described above - how odd! I must have forgotten!
It does seems to really calm down the lighting in the bump shader I'm creating anyway - so hopefully the above code is what you are looking for too!


ReplyQuote
AndyJ
(@andyj)
Senior Chief Registered
Joined: 7 years ago
Posts: 91
 

Well I decided to spend a little more time on my bump-map shader for the Asp tonight and have made some useful progress!
First of all, I was thinking that there must be a way to combine the grey-scale height and specularity textures into a single file, because only a single channel is really needed from them, and I've found out how to do that - so saving useful memory.
I was also thinking that perhaps I could use a spare layer as a selection mask for recolouring panels on the ship too. I'd tried to do this before without without a mask and it hadn't worked very well - but I'm really pleased tonight as this way it targets precisely the areas that I want it to 😀

![]( "")
Ooh. Suits you sir!

And yes, you do have to be fairly eagle-eyed to be able to spot the extra bump-map detailing - which is why I'd not released it before with 4 textures!
It's now using 3 textures (skin, normal map and height-map/specularity/colour mask) and by providing the extra colour functionality, well perhaps it does justify using those extra resources!

I think that this progress is also really good news for the Viper Mark II and Skeet ships too - they are currently using multiple skins (from the example_skins pack) to give a variety of colours - which is terribly wasteful of resources. I should be able to rework these now to use a mask and then re-colour them in the shader. I'm thinking that I could possibly just the use alpha channel of the main texture for the mask - because IIRC it has no purpose at present - and that would then be a big saving for anyone using them!

The other opportunity this opens up is ... decals... but I haven't got to looking at this yet!
A single texture could probably contain 4 decal layouts for a ship, using rgba channels. Thinking ahead - perhaps the value of the pixel in a channel could possibly even select a colour if they weren't just assumed to be white/transparent.


ReplyQuote