New Release D3D9Client Development

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
For what it's worth, I implemented the *_refl.dds functionality. The new functionalities by jarmonik should still be intact, except for the way the textures affect the specular highlights and environment reflection. So now it is (I think) in compliance with the Option #3 discussed earlier.

With that shader DeltaGlider isn't reflecting anything anymore. Is this a better option that reflections can be only defined with reflection map and not by material configuration ? Do we keep the custom material configuration option available ?

What good does it do to have an ability to define separate color for specular reflection and environment map reflection. Is it worth the costs ?
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
Here are modified shaders with reflection map and material support.
 

Attachments

  • Shaders.zip
    7 KB · Views: 37

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
There is one fundamental problem that would need to be solved. Now that the shader size has increased to 71 instructions it cannot be run with a shader model 2.0 which has a maximum of 64 instruction.

Shading costs in instructions:
Dissolve technique 4 - instructions
Glass shading 8 - instructions
Reflection Map 7 - instructions

The easiest way to fix the problem would be splitting the shader to textured and non-textures shaders but there is a setback. I recall I tried it a long ago but it produces some side effects when a semi-transparent (i.e. billboard texture) is rendered on a non-textured object. They would be rendered in an incorrect order and the texture transparency won't work. This problem is also effecting in mesh optimization issues.

We could have a mesh group flag that would place the group in a post rendering stage. So, some meshes would need to be edited to properly work with a client.

One possibility that might work is a four pass technique:

Pass 1 - Normal mapped groups
Pass 2 - Opaque non-textured groups
Pass 3 - Non-normal mapped textured groups
Pass 4 - Semi-transparent non-textured groups (i.e. windows)

If someone has a billboard texture in a window then it would fail to render.

Dissolve technique could be easily removed from model 2.0 shaders but it alone is not enough. I suppose a glass shading could be simplified to reduce instructions.

---------- Post added at 17:28 ---------- Previous post was at 14:36 ----------

Any ideas how do we define environmental camera locations and more importantly how do we define what is drawn and what is clipped from a camera views ?

Currently, focus visual and all attachments are clipped. This is because cargo containers were blocking the camera view in XR2.
 
Last edited:

Felix24

Active member
Joined
May 13, 2010
Messages
245
Reaction score
95
Points
43
Multiplying the environment texture by cRefl.rgb and then by iRefl is kind of repeating the operation. I left out the iRefl multiplication because the reflective intensity within cRefl.rgb is all that is needed when multiplied with the environment texture. We still need iRefl for the next line, though, when we darken down the diffuse texture according to iRefl.

PHP:
    if (gEnvMapEnable) {
        float3 v = reflect(-CamW, nrmW);
//        float3 reflections = (cRefl.rgb * texCUBE(EnvMapS, v).rgb) * iRefl;
        float3 reflections = cRefl.rgb * texCUBE(EnvMapS, v).rgb;
        cTex.rgb  *= (1.0-iRefl); 
        cSpec.rgb += reflections;                        
    }
Thank you for cleaning up and fixing my code. I'm completely new at this kind of coding, and I mostly have no idea what I am doing and I'm learning as I go along. Thank goodness for your code and the msdn library!
 

Frankynov

Member
Joined
Oct 2, 2008
Messages
39
Reaction score
0
Points
6
Hey Jarmonik !
Those reflections are looking awesome ! :)
I've just met a bug, with AMSO. If I apply reflections on the CSM with the LEM docked and then undock the LEM, the reflections are gone and I have to reapply them manually.
It's the same for any separation.
Is there anything I can do for this ?
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
Multiplying the environment texture by cRefl.rgb and then by iRefl is kind of repeating the operation.

Yes, you are right. We could write the section like this. The code compiles to 68 instructions.

PHP:
 if (gEnvMapEnable) {
    
        if (gUseRefl) {
            cRefl = tex2D(ReflS, frg.tex0);    // Color
            iRefl = max(max(cRefl.r,cRefl.g), cRefl.b); // Intensity
        }                     
        else {
            iRefl = gReflCtrl[0];
            cRefl = gMat.specular.rgb * iRefl;
        }    
        
        float3 v = reflect(-CamW, nrmW);
        if (gUseDisl) v += (tex2D(DislMapS, frg.tex0*gReflCtrl[1])-0.5f) * gReflCtrl[2]; // 4-instruction        
        cTex.rgb *= (1.0-iRefl); 
        cSpec.rgb += cRefl.rgb * texCUBE(EnvMapS, v).rgb;                        
    }


---------- Post added at 21:48 ---------- Previous post was at 21:47 ----------

I've just met a bug, with AMSO. If I apply reflections on the CSM with the LEM docked and then undock the LEM, the reflections are gone and I have to reapply them manually.

I think I know what's going on. Taking a look...
 

Felix24

Active member
Joined
May 13, 2010
Messages
245
Reaction score
95
Points
43
Why do we want to stay within shader model 2.0? Is it so that it will run on older hardware?

Are there any previous versions of the D3D9 client that are shader model 2.0 compliant?

---------- Post added at 04:35 AM ---------- Previous post was at 04:21 AM ----------

Any ideas how do we define environmental camera locations and more importantly how do we define what is drawn and what is clipped from a camera views ?

Is it possible to define the camera locations separately for different vessels? If so, then could we declare that attachments only on certain docking ports or attach points be clipped?
 

Quick_Nick

Passed the Turing Test
Donator
Joined
Oct 20, 2007
Messages
4,088
Reaction score
204
Points
103
Location
Tucson, AZ
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Why do we want to stay within shader model 2.0?
First versions were only SM 3.0. Then, I believe, SM 2.0 has been added for people complaining that D3D9Client isn't working for them.

Shader Model 3 and 4 obviously would allow a lot more freedom to deliver the best graphics to those who can run it.
And you can test SM 4 in D3D11Client.
 

Interceptor

Well-known member
Joined
Mar 28, 2008
Messages
2,718
Reaction score
76
Points
63
Location
Michigan,Florida
Hey Jarmonik,I found a bug in D3d9R9,the orbiter menu only partially shows,until you push all the tabs,and sometimes you have to move the mouse arrow around in the left corner where the menu always appears at to get it to show.BTW the reflections look terrific.Thanks for your hard work.
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
Why do we want to stay within shader model 2.0? Is it so that it will run on older hardware?

Orbiter is being used with a pretty old hardware. I would estimate that 25% are running with model 2.0 or less. Also, an other reason to keep the instruction count low is that Orbiter is also used with laptops those may have a higher shader model but not enough kick to run a complex shaders. An other issues that should be kept in mind are a memory and the memory bandwidth. Sampling multible textures consumes memory bandwidth.

We can have a different shaders for 2.0 and 3.0 but a meshes must render properly with both. The question is what is worth of those 64 instructions ?

We could try to design the shaders so that meshes could be rendered with a proper reflections with just one additional control texture. The shader model 3.0 could provide a support for a second control texture. Two "must have" control textures are too much. If the reflections would be controlled with one channel then we wouldn't need intensity computations from rgb.

What sort of situation would need a different color for specular reflection and reflected image ?

Is it possible to define the camera locations separately for different vessels?
Yes, either in vessel local coordinates or centered in a specific mesh groups in which case they could move with animations.

If so, then could we declare that attachments only on certain docking ports or attach points be clipped?
If a vessels have a fixed number of attachment and docking "slots" then we could have a list of the "slots" those need to be omitted. Also a camera could have a configurable near clip-plane distance. Starting to disable meshes or specific mesh groups would probably get too complicated.

---------- Post added at 23:33 ---------- Previous post was at 23:30 ----------

Hey Jarmonik,I found a bug in D3d9R9,the orbiter menu only partially shows,until you push all the tabs,and sometimes you have to move the mouse arrow around in the left corner where the menu always appears at to get it to show.BTW the reflections look terrific.Thanks for your hard work.

There are no changes made to anything that could cause it. Could it be a temporary driver issue of some kind. Can anyone else reproduce ?

---------- Post added at 23:42 ---------- Previous post was at 23:33 ----------

I've just met a bug, with AMSO. If I apply reflections on the CSM with the LEM docked and then undock the LEM, the reflections are gone and I have to reapply them manually.

Will be fixed in next release.

---------- Post added at 23:44 ---------- Previous post was at 23:42 ----------

I had to disable a skin specific configuration because there are no reliable data about the skin and textures are dynamically changed during runtime.

We could try create a skin specific configuration by using a skin specific file name like:

classname_skinname.cfg

But how do we find out the name of the skin ?
 

Felix24

Active member
Joined
May 13, 2010
Messages
245
Reaction score
95
Points
43
There is at least one situation when the specular reflection and reflected image would need to be different. If someone wanted to paint an area with colored metallic paint with a glossy clear coat on top, then the specular reflection would take on the color of the metallic paint, and the reflected image color would remain unchanged. Here are some real-life pictures to illustrate the effect:

http://images10.newegg.com/NeweggImage/ProductImageCompressAll300/A1NW_1_20121001_62684295.jpg
http://www.zero-paints.com/photo-ga...s-using-Zero-Paints/DSC01262.jpg?m=1305751839
http://www.zero-paints.com/photo-ga...s-using-Zero-Paints/DSC01270.jpg?m=1305737175
This one is raytraced, but still it shows up very well: http://www.keyshot.com/wp-content/uploads/2012/02/keyshot-metallic-paint.jpg

But I do realize this is Orbiter, not Grand Theft Auto.

I do agree that two "must have" textures are too much. One or two "might have" textures are better. I would rather try and prove it can be done with two and then come up with a compromise, than to not try.

Some thoughts.

Would it be practical to have different shaders for 2.0 and 3.0 if we kept the differences to a minimum?

I'm reading there are differences between shader models 2.0 and 2.0a. It seems that for 2.0a, the limit is 512 instead of 64. Is 2.0a-compliant hardware more or less in use with Orbiter than 2.0?

How fast are users able to run shader model 2.0 effects on hardware that supports only 2.0? I dug around and installed both D3D9 R5b and the latest alpha version on an old machine (P4 2.8Ghz, Windows XP, 2GB ram, GeForce FX5200, DirectX 9.0). The latest alpha version cannot run because there are 70 instructions, too many for shader model 2.0. R5b is able to run, but only very slowly (about 3-7 fps at 1024x768 fullscreen). The same machine using the inline client at the same resolution runs smoothly between 20 and 30 fps. This is only one test case, but I'm curious if other people have similar experiences. Would it be worth staying with 2.0 if hardware capable only of 2.0 can run only very slowly?

Can using a skin-specific configuration file to control the specular reflection bring the number of instructions down to 64?
 
Last edited:

Kendo

New member
Joined
Oct 16, 2007
Messages
589
Reaction score
1
Points
0
Yes, the latest Alpha version does use a lot more CPU, my fan is always ON. I guess that,s to do with the new shaders for the reflectivity. Where as my fan is OFF 95% of the time with D3d9 version 8.
Frame rates are just under the client 8 version though.

Also, I eat my words regarding my comment on the " black areas should be sunlit....." in an earlier post.
 

Interceptor

Well-known member
Joined
Mar 28, 2008
Messages
2,718
Reaction score
76
Points
63
Location
Michigan,Florida
Thanks,Jarmonik,I will see if maybe some recently installed drivers'and,or software is causing the menu problem.Thanks
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
I'm reading there are differences between shader models 2.0 and 2.0a. It seems that for 2.0a, the limit is 512 instead of 64. Is 2.0a-compliant hardware more or less in use with Orbiter than 2.0?

I have never encountered such hardware. There are very few DirectX 9.0a or 9.0b cards out there.

R5b is able to run, but only very slowly (about 3-7 fps at 1024x768 fullscreen). The same machine using the inline client at the same resolution runs smoothly between 20 and 30 fps.
It could be running in software vertex processing mode. I can detect about 30%-40% frame rate drop if compiling for model 2.0 with model 5.0 hardware.

But it's a good question how fast the R9 client runs on model 2.0 hardware ?

Can using a skin-specific configuration file to control the specular reflection bring the number of instructions down to 64?
Yes, it can.

What do you think about this.

Primary control texture:
r = Specular red
g = Specular green
b = Specular blue
a = Reflection itensity

Secondary control texture:
r = Reflection red
g = Reflection green
b = Reflection blue
a = Specular power

The code would compile to 67 instructions. User could omit the Secondary texture or improved glass shading from model 2.0 hardware. We are only 3 instructions sort.

Of, course reflection color could come from a skin specific material configuration and intensity from a texture.
cRefl.rgb = gMat.reflect.rgb * iRefl;
But how would it be better that using per pixle specular color
cRefl.rgb = cSpec.rgb * iRefl;

Could the diffuse texture color to be any use ?

---------- Post added at 07:40 ---------- Previous post was at 07:37 ----------

Yes, the latest Alpha version does use a lot more CPU, my fan is always ON. I guess that,s to do with the new shaders for the reflectivity. Where as my fan is OFF 95% of the time with D3d9 version 8.
Frame rates are just under the client 8 version though.

If you have selected "Fullscene" from the options then it might double the CPU load. I believe there is a way to reduce the total CPU load down to 1/4 of the current load if we are lucky.
 
Last edited:

Felix24

Active member
Joined
May 13, 2010
Messages
245
Reaction score
95
Points
43
It could be running in software vertex processing mode.
Can I somehow force it to run in hardware mode instead, or is that not possible?

Primary control texture:
r = Specular red
g = Specular green
b = Specular blue
a = Reflection itensity

Secondary control texture:
r = Reflection red
g = Reflection green
b = Reflection blue
a = Specular power
I think this is okay. I don't think it's the best solution, because it will be confusing to have two files with with specular data and reflection data mixed up between them. But with the shader model constraints, it might be the best we can do.

Would it be possible to have the secondary texture present without the the primary texture?

Unused if-then statements in the code still count toward the 64 instructions, don't they?

I think it's best that we stay away from making a "secret recipe" (or an extra confusing one) for using the D3D9 effects, so that other clients like D3D11 will be able to understand and render using the same files, if they choose to implement the same effects. This is already the case with normal maps, which is a huge bonus.

In other DirextX games, like MS Flight Simulator, the diffuse texture often has an alpha channel, which is used to control either transparency or reflection intensity, depending on how the model was coded.
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,668
Reaction score
796
Points
128
Can I somehow force it to run in hardware mode instead, or is that not possible?
No.

I don't think it's the best solution, because it will be confusing to have two files with with specular data and reflection data mixed up between them.

That was my thought as well. The idea is to setup the most essential data in one texture and non essential data in the other texture. The question is what is most essential ?

Would it be possible to have the secondary texture present without the the primary texture?
I suppose yes, but if there is a need to do that then the setup of essential data in the first texture may have failed.

Unused if-then statements in the code still count toward the 64 instructions, don't they?
I have removed all unused if-else statements


In other DirextX games, like MS Flight Simulator, the diffuse texture often has an alpha channel, which is used to control either transparency or reflection intensity, depending on how the model was coded.

That is an interesting idea and fully doable in a new implementation but not in the orbiter because it would break the add-on. They would no-longer work with the inline engine. Also using the unused channel in the normal maps could be confusing.
 

Dmitrtr

New member
Joined
Mar 10, 2011
Messages
38
Reaction score
0
Points
0
D3D9 Client works far better with alpha chanell than default Orbiter, but there is a bug, meshes disapear when you look through several meshes with alpha channel textures.

And how about LOD implementation to bases and vessels?
 
Last edited:
Top