Reflector sights - implementation discussion
Results 1 to 19 of 19

Thread: Reflector sights - implementation discussion

  1. #1

    Reflector sights - implementation discussion

    Hi!
    As you might know, I'm the author of DX9 shaders for CFS3 (and more specifically WOFF). Sorry if my English slips sometimes, but I hope it is still understandable


    In another thread I mentioned that I want to add support for reflector sights into the next version of my DirectX 9 shaders. This work won't be immediately useful for WOFF because WWI Aldis sight requires a different approach, and that's why I want to talk about it here and not on WOFF forums.
    If you don't know what I'm taking about - here is a demo video I recorded months ago:
    http://www.youtube.com/watch?v=p4-shLNwLyA

    We had previously discussed the matter with gecko and he had a great idea of using sprite effects in *.xdp file to add a new reticle.
    With this approach one can hex-edit m3d file to make existing reticle object fully transparent and then add a sprite in place of it. My shaders will detect this sprite by its texture name (for example any name starting with "Reticle") and apply some "magic" to move the sight as needed.


    However, xdp sprite approach also has a few issues which I want to discuss.


    1. The sprite is always square.
    And the "glass" on which the reticle is projected is not (at least as it is seen from the pilot's point of view).
    As gecko proposed this is solvable by making the sprite larger that the glass, but adding a "mask" texture which will define the area where the reticle can appear on the sprie. The mask may also allow to make the reticle gradually become fainter near the edge if needed.
    One note though is that the mask has to be put into the same texture as the reticle, which is slightly tricky, but shouldn't be a big problem.


    2. Aircrafts like Boulton Paul Defiant have a reflector sight in gunners cockpit which moves with the gun.
    The sprite has fixed location and I think it is not directly solvable.
    The solution for such models is to keep the existing reticle instead of using a sprite. However it is not as simple. In real reflector sights the glass is tilted so it will reflect the reticle towards the pilot. This is also true for Defiant and many other in game models. And it poses a challenge for my shaders because there is no way to tell where the guns are pointing based on gunsight model alone.


    My current idea is to hex-edit the m3d file and change material properties for gunsight glass object in a way that encodes the tilt into them. For example, the gunsight object for Defiant has specular set to "00 00 00 40" and tilted at about 36 degrees. 36 is 24 in hex, so the specular has to be set to "24 00 00 40". This will have almost no effect on the look without my shaders, but if shaders are enabled they will read these bytes and will know where to put the reticle.
    This is just an example, I haven't yet decided what the encoding scheme will be.

    So... If anyone has any ideas or questions - let's discuss them.
    Since I'm doing it for CFS3 modders I need your opinions on this feature

  2. #2
    You found a way to do the gunner station sights! Cool! I think we would still need permission from the original modelers to upload the changes to their models, but hopefully they will all be on board with this. We should also compile a list of aircraft that have gunner positions equipped with reflector sights so we can go about contacting the authors. Here's a start:
    Beaufort
    Blenheim IV (only certain versions)
    Defiant
    Hudson
    Sunderland
    Wellington
    A-26
    B-17
    B-24
    Br.693

    I know that's not complete, so there are others.

    For the regular gunsights, do I understand correctly that all that is needed is to add the sprite effect to the desired location on the aircraft and the moving reticle will work and is completely independent of how the model is set up. I ask as there are a few models that never had a gunsight glass modeled, or the gunsight is in a non-standard locacation - many of the German cockpits have the gunsight offset to one side, and others have two gunsights, one of which is mounted on the roof facing up. Will this support having two gunsights in one cockpit?

    Is the sprite effect texture the one that determines the design of the reticle and its color?

    Is there a limit to the size a reticle can be?

    Is there anything stopping us from adding sprites to models now, in preparation for the release of this project?

    Thanks again so much for doing this!

  3. #3
    Quote Originally Posted by gecko View Post
    For the regular gunsights, do I understand correctly that all that is needed is to add the sprite effect to the desired location on the aircraft and the moving reticle will work and is completely independent of how the model is set up. I ask as there are a few models that never had a gunsight glass modeled, or the gunsight is in a non-standard locacation - many of the German cockpits have the gunsight offset to one side, and others have two gunsights, one of which is mounted on the roof facing up. Will this support having two gunsights in one cockpit?
    You also need to hide the original gunsight. However, if distributing edited models is a problem I can probably invent something and make my code automatically hide the original gunsight if a sprite one is detected.
    One big issue though (and it applies to other stuff as well) is keeping compatibility with the stock renderer. I can control what is visible and what is not with my dll, but if my dll isn't used then the sprite will still appear and the original gunsight will also stay there.

    The location of the original gunsight doesn't matter. The sprite can be placed anywhere as well, what is important is the orientation of the sprite:
    <Effect Type="Track" EffectName="bf_109g_6_gunsight" PosX="-0.0018" PosZ="-0.475" PosY="0.76175" Pitch="90" MinVel="-999999" MaxVel="999999"/>
    This pitch makes the sprite stay vertical instead of being tilted and this is required by my shaders. Otherwise the reticle will be pointing upwards.

    You can add as many gunsight sprites as you need into the cockpit - all of them work independently.


    Is the sprite effect texture the one that determines the design of the reticle and its color?
    Yes, but the texture design might be a bit unusual.
    My idea is that the alpha channel of reticle texture defines the reticle shape (as it does normally), but RGB channels is used both as a mask and to define the reticle color - in the simplest case it is just a solid color over the whole texture. Or with gradual falloff near the edges it will look like the image I've attached below.
    The tricky part is that the color channels are applied to the whole sprite and don't move, but the reticle made up with alpha channel moves over the sprite and "inherits" the color of corresponding area. You can think about it as if color and alpha channels are two independent textures.

    Is there a limit to the size a reticle can be?
    No. And its size is actually independent of the sprite size.
    I think the scale will be a part of the texture name, something like: Reticle.bf109g6.x12.dds
    I will explain it in more details later.

    Is there anything stopping us from adding sprites to models now, in preparation for the release of this project?
    Well, I can't tell you what you need to do because I still don't know how it will work
    I've tested various features but more in proof of concept style, they aren't finalized yet.
    When I get it working in more or less final state I will make a couple of examples to show all features.
    Attached Thumbnails Attached Thumbnails ReticleWithMask.jpg  

  4. #4
    I'm very interested in this AnKor, from the standing of a modeller with a completed model to upload and other work in progress. I take it the square sprite limitation is a DirectX shader thing, because a number of gunsights have rectangular reflectors and some are oval (from the pilot's perspective)?

    It's not at all hard to add more VC models to an aircraft to give different gunsight options - the modelling is identical in each but the reticule changes - although whichever option is used with TrackIR must be VC0 or you're stuck. My Tempest uses two VC models, one with a simulated gyro-controlled reticule and the second with a fixed sight.
    Tom
    __________________________________________________ ___________________________________________
    Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding. Proverbs 4:7



  5. #5
    Some good news

    Sprite based gunsights are coming along nicely and I've figured out a very simple way to avoid showing the sprite in stock mode: we just need to make it very small - 1000 smaller than needed and the stock cfs3 renderer will draw it as a tiny dot, but my shaders will scale it back to proper size.

    And to make things even better while researching the sprite rendering I've noticed they are never culled even if out of sight. This makes it possible to use them as... a light source - my shaders will treat a sprite with specifically named texture (which can be of 1x1 size) as the cockpit light. WOFF 2.0 uses similar approach but there a light source is a part of m3d and thus has greater flexibility, however for adding simple point lights to 3rd party models a sprite will do - anything is better that the stock red light.

    There are two differences between these new DX9 lights and the ones you can already add via light effect: 1) these can be switched on/off by the player in game just like the stock cockpit light, 2) they don't count toward the 6 lights per scene limit and won't flicker (although there can't be more than 2 such lights in a cockpit).
    Attached Thumbnails Attached Thumbnails bf109g6.jpg  

  6. #6


    I thought that sprites weren't culled! I'm glad it will work, it's going to be a major improvement! Out of curiosity, what are the advantages of making the light source part of the m3d?

    Looking forward to getting this implemented!

  7. #7
    Quote Originally Posted by gecko View Post
    Out of curiosity, what are the advantages of making the light source part of the m3d?
    Spot lights - i.e. lights with a cone of specific width pointing in specific direction. Check Gotha or Home Defense fighters in WOFF -- lit spots have well defined edge which looks nice.
    Since sprites can't face an arbitrary direction (only pitch is customizable) they will only support point lights shining in all directions without a cone.

    The advantage of sprites is the lack of culling, to make m3d lights work we have to place several dummy objects around the cockpit to make sure the bounding box is large enough and the light is not culled. Although this will also require additional coding on my side to avoid picking up lights from nearby aircrafts instead of player's cockpit

  8. #8
    We can orient the sprite in any direction we like. In addition to the "Pitch" modifier, "Bank" and "Heading" are also recognized in the xdp. I don't know if that helps define a cone of light or not, but it is available if you find it helpful. The original sprite effect I sent you only required pitch, so I left the others off, but they do work.

  9. #9
    SOH-CM-2024 Pat Pattle's Avatar
    Join Date
    Jun 2005
    Location
    Newton Abbot, Devon. Dear old Blighty
    Age
    60
    Posts
    2,907
    Blog Entries
    1
    Fascinating stuff! But....could someone explain to me what exactly a 'sprite' is please and what it does and how it works in cfs3?

    And when it is said that they are not culled does that mean that it's always on even when not looking at it? i.e. the opposite to some effects that disappear when out of view to be re-created once back in view (smoke for example).

    I have in the back of my mind that this could be used for cockpit damage one day, perhaps?

    Thanks,

    Clive
    CFS3 Battle of Britain Website: https://cfs3bob.wixsite.com/cfs3-bob
    CFS3 ACC Member & ETO Expansion Group

  10. #10
    SOH-CM-2021
    Join Date
    Sep 2005
    Location
    Dayton,ohio
    Age
    68
    Posts
    5,749
    Blog Entries
    1
    WOW!!
    More rejoicing!
    Thanks very much for this work.

  11. #11
    Actually Clive, this is exactly the technique you've used in the past for the bullet holes in the canopy, just under a different name. The sprite is just the texture as it is placed in the model.

  12. #12
    We can orient the sprite in any direction we like. In addition to the "Pitch" modifier, "Bank" and "Heading" are also recognized in the xdp. I don't know if that helps define a cone of light or not, but it is available if you find it helpful. The original sprite effect I sent you only required pitch, so I left the others off, but they do work.
    Excellent!
    Then there is nothing preventing me from adding spot lights as well. Again the limit is 2 such lights in cockpit (so the total is 4 = 2 point + 2 spot), but that should be enough.

    Quote Originally Posted by Pat Pattle View Post
    And when it is said that they are not culled does that mean that it's always on even when not looking at it? i.e. the opposite to some effects that disappear when out of view to be re-created once back in view (smoke for example).
    Well, yes, though I don't know if there is any use for this feature outside of my shaders.
    For me the lack of culling is important because the light source should work even if it is out of view.

  13. #13
    Great! Four lights I suspect is plenty. Will there be a way to define color and intensity of the lights? Perhaps based on the name of the sprite effect? There was a pretty great variety, I think the He 219 even used black lights IIRC.

    We have used the same kind of sprite effect to display bullet holes on glass. The only downside is that the model has to have an emitter located at each bullet hole, and if the original modeler didn't add them then bullet holes in glass aren't possible.

  14. #14
    Color and intensity will be configurable.
    My current solution is to introduce a configuration file to go along with my shaders allowing to set special use for known textures.
    Contents of this file will be like this:
    Code:
    [PropDisk]
    prop_german.dds
    prop_us_brit.dds
    prop_dr1.dds
    prop_hp0400.dds
    prop_pfalz.dds
    prop_us_han.dds
    prop_us_hann.dds
    propspad.dds
    
    [Ground]
    dover1_t.dds
    
    [Searchlight]
    search_light.dds
    
    [ReticleStatic]
    reticle_br.dds
    reticle_gr.dds
    reticle_us.dds
    
    [ReticleDynamic] ; scale
    reticle_bf109g6.dds=1.0
    
    [CockpitLight] ; P or S|hex RGB|Range(m)|Attenuation(more - quicker fade out)|Cone (degrees, for Spot)
    light_yellow.dds=S|FFC020|2.0|30|45

  15. #15
    Great! That's a really good idea, then we can just add new textures to it as we come up with more things! It's got me wondering, since we can add any texture to a list to make it behave a certain way, what else is possible? Could a texture be made so it only displays above a certain altitude (thinking contrail effects)? Could textures used in special effects be lit the same as all the other textures so they don't glow at night? (There would need to be a list of exceptions to this so fires and lights are still bright). Just ideas.

  16. #16
    Yes, altitude above sea level is available to my shaders - I can make texture transparency depend on it and yes, I already thought about proper lighting for special effect sprites
    I just need to finish the work on current list of features - there is already quite a few of them.

  17. #17
    Very cool! We've been trying to find a way to get altitude controlled contrails since day 1. And the effect lighting has been my personal headache ever since I started working on effects for the Bomber Command expansion.

    Can't wait to find out all the features, sounds like you've been busy!

  18. #18
    SOH-CM-2024 Pat Pattle's Avatar
    Join Date
    Jun 2005
    Location
    Newton Abbot, Devon. Dear old Blighty
    Age
    60
    Posts
    2,907
    Blog Entries
    1
    Actually Clive, this is exactly the technique you've used in the past for the bullet holes in the canopy, just under a different name. The sprite is just the texture as it is placed in the model.
    Ah! thanks Daniel

    Yes, altitude above sea level is available to my shaders - I can make texture transparency depend on it
    Now that would be a major step forward, contrails are a pain and one of the least realistic areas of cfs3. Although there are some very good work arounds, being able to link them to altitude would be excellent!
    CFS3 Battle of Britain Website: https://cfs3bob.wixsite.com/cfs3-bob
    CFS3 ACC Member & ETO Expansion Group

  19. #19
    SOH-CM-2023 mongoose's Avatar
    Join Date
    Jun 2005
    Location
    Navigator, where are we?
    Age
    79
    Posts
    3,554
    Quote Originally Posted by Pat Pattle View Post
    Ah! thanks Daniel



    Now that would be a major step forward, contrails are a pain and one of the least realistic areas of cfs3. Although there are some very good work arounds, being able to link them to altitude would be excellent!
    I totally agree!

    Cato said "Carthaginem esse delendam"
    I say "Carthago iam diu deleta,sed enim Bellum Alium adhuc aedificandum est"

Members who have read this thread: 0

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •