Quantcast

Jump to content

» «
Photo

[SA] Transparency without changing all Instances.

19 replies to this topic
pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#1

Posted 17 February 2018 - 03:19 AM Edited by pep legal, 17 February 2018 - 03:53 AM.

.

As well known, tweaking model's alpha affects all instances of that model (working on cars mostly).

 

Have tried individual transparency by cloning some frame/atomics (in cleo scripts) of some parts, but no success. :/

 

Not sure if it is necessary to clone rpGeometry as well.

 

Also have tried to migrate an atomic (chassis) from a car to an object ==> crash !

 

Studying the possibility of a total duplication of a specific car model (in memory)...and create a car using that model clone. Need more info about model loading though.

 

Not really necessary that the "transparent instance" must be fully functional. Just a "dummy" object with chassis, doors and wheels would be excelent.

 

 

Some tips from PROs would be very welcome ! :cool:

 

 

.


Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#2

Posted 17 February 2018 - 06:20 AM

What you're asking is something similar to the one I asked in the old days (and I have not been able to do it until now, but I have not tried it again in a long time).

Basically, you want the changes of a rpatomic's material to be individual for each entity, right? The maximum I got caused the rpatomic to be totally black or random colors at each vertex.


DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#3

Posted 17 February 2018 - 08:21 AM Edited by DK22Pac, 17 February 2018 - 08:21 AM.

It's not really necessary to create unique materials for each clump/atomic.
R* solved this 'problem' in this way: they saved material data before atomic/clump rendering, changed material properties, and then restored saved data after atomic/clump was rendered.
// save materials parameters
// edit materials parameters
Clump/Atomic rendering
// restore materials parameters
Also, cloning geometries (thus, making them 'unique') could be an idea. Could you share your code?

pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#4

Posted 24 February 2018 - 06:31 PM Edited by pep legal, 24 February 2018 - 07:33 PM.

.

After digging for info, I got some light from old topics in this forum... here goes some feedback :

 

- Gave up of tweaking vertex alpha (it affects all instances)....Material alpha seems to be easier.

 

- I succeed in cloning Geometry, Material List and all its Materials from a car chassis...but for some obscure reason, changing rwRGBA value (offset 0x04) of the cloned Mat does NOTHING at all. But...If I change rwRGBA of original Mat, just before "_rpMaterialClone", then the copy (and the original of course) has its color changed.

 

Spoiler

 

- Another question : Provided that I have a cloned rpAtomic, is it possible to create an object (no hierarchy) using that Atomic ? - All my attempts to overwrite  CEntity:rwObject (offset 0x18) with that cloned Atomic result in CRASH.

 

 

Looking forward to any help. :santa:

 

 

.


pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#5

Posted 11 March 2018 - 04:36 AM Edited by pep legal, 11 March 2018 - 04:59 AM.

Harder than I thought...but it's done.

( Tires still not so good )


Next step, remove out all the "core" atomics (seats, steer wheel, extras), keeping only the visible "shell" (chassis, doors, wheels).


Need a way to know if an Atomic is tottaly occluded (behind another atomic).


Thanks for the attention !




d1fNnER.jpg
  • -Anti- and Junior_Djjr like this

Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#6

Posted 12 March 2018 - 04:55 PM Edited by Junior_Djjr, 12 March 2018 - 04:58 PM.

Do you fixed this issue?

- I succeed in cloning Geometry, Material List and all its Materials from a car chassis...but for some obscure reason, changing rwRGBA value (offset 0x04) of the cloned Mat does NOTHING at all. But...If I change rwRGBA of original Mat, just before "_rpMaterialClone", then the copy (and the original of course) has its color changed.

This will be very useful for me (it's the main problem of Tuning Mod).

- Another question : Provided that I have a cloned rpAtomic, is it possible to create an object (no hierarchy) using that Atomic ? - All my attempts to overwrite  CEntity:rwObject (offset 0x18) with that cloned Atomic result in CRASH.

Do you tried the Tuning Mod's clone function? (Extra - Add.txt)

pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#7

Posted 13 March 2018 - 01:37 AM Edited by pep legal, 4 weeks ago.

.
I've solved both problems above mentioned (completely the first one...partially the second)
 
I didn't know you have published a separated source code for Tunning Mod.
 
Now looking at your "Clone function", I see it is not complete...still persists some kind of dependency among instances. Not a problem if you don't need to make deep changes (alpha, for example) in one instance, without changing others.
 
 

  • Junior_Djjr likes this

pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#8

Posted 14 March 2018 - 07:36 AM Edited by pep legal, 15 March 2018 - 08:33 AM.

.
EDIT : For the sake of correctness, the previous script was fixed.

No more doubts. Thread can be closed.
.

Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#9

Posted 15 March 2018 - 06:26 PM

Nice :)

Check my "Search Parts - Funcs.txt", there's a much better way to make your "Walk through Linked List of RwFrames".


Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#10

Posted 15 March 2018 - 07:26 PM Edited by Junior_Djjr, 15 March 2018 - 08:53 PM.

After a lot of message edits, rewriting this:
 
I noticed this:
0AA5: call_function _memcpy num_params 3 pop 3 params Size 60 block [email protected] CopyTo [email protected] //copy part of original RpGeometry to the new one
"Size 60"
In fact, is 0x60.

But, well, all vehicles occasionally bugs after cloning, like this.
If not bugs, it crashes at d3d9.dll.
Tested cloning just one RpAtomic (bonnet, chassis, door...)

Only here?

pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#11

Posted 16 March 2018 - 01:57 AM Edited by pep legal, 16 March 2018 - 02:36 AM.

After a lot of message edits, rewriting this:


:blink:  - I didn't know message edits send messages...I usually put a lot of care on writings.



"Size 60"
In fact, is 0x60.


Nope...Its 60 (decimal). It's a partial copy...not full (he..he...pegadinha do malandro !)
 
 

But, well, all vehicles occasionally bugs after cloning,


Works great here ! Actually I took a 30 minute ride on a transparent cloned car. No problem at all.

But I'm sure that a cloned car cannot be re-cloned. Still missing some refs. Additionally, I'm not sure the game releases those allocated objects created by the Clone function.

I'm still doing tests on traffic cars....so far, so good.


 

Check my "Search Parts - Funcs.txt", there's a much better way to make your "Walk through Linked List of RwFrames".


I see...recursion is a classical solution for Linked List, but SCM functions put a fuc* overhead on calls, and T&T is already a 20 thounsand lines piece of software. I need to be cautious about performance.

The "fixed" version I wrote above works good enough (not great), and it can be easily extended to increase deeper searches.

Anyway, I'm thinking about using pointers to data arrays to "simulate" recursion, instead of fixed variables. Then I would have the same performance I already have, plus variable deep searches (I don't have).


.

DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#12

Posted 16 March 2018 - 02:11 AM Edited by DK22Pac, 16 March 2018 - 02:13 AM.

Nice, but do you think writing an assembly byte-code is a proper way of 'coding'!?

Anyway, I thought about some another solution (not the 'classical R* way') and I made this.
https://drive.google...q3tMl8COP92iQzD

* [ ] keys are used to change transparency; it works for current player car only.


pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#13

Posted 16 March 2018 - 04:49 AM Edited by pep legal, 16 March 2018 - 05:19 AM.

.
Oh gosh...finally we've got some divine intervention ! :santa:


 

Nice, but do you think writing an assembly byte-code is a proper way of 'coding'!?


Still learning....I will try doing better next time !  :sigh:
 
 

Anyway, I thought about some another solution


Apart trying to find out the keys to proper control it (probably due to different keyboard layout)...I loved the way CJ becomes a Ghost !

It would be great if you have done that for Cars...and not the Player !

--------------------------------------------------------------------------

EDIT :

Fuc* !!! Your transparency is far better than mine.

Tweaking material alpha of every cloned atomic (like I did) gives an UGLY view of the car skeleton.

Your solution keeps the original way of looking...just merging softly with the ambient.

Perfect !

What about giving us an API in order to use your ASI from a Cleo Script ? (All credits given, of course).


PS.: It's not compatible with SkyGfx (from TheHero/aap) - it changes only CJ transparency.

Thanks.









.

DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#14

Posted 16 March 2018 - 06:38 AM Edited by DK22Pac, 16 March 2018 - 06:57 AM.

Yes, it may not work with custom rendering pipelines (or shaders).
 
So what I made here:
there are 2 hooks, one is for storing currently rendered entity (but only if it's a vehicle), and another for changing D3D material properties, right before mesh is rendered.
In the second hook, we check if a mesh is a part of a vehicle and, if so, apply new material properties.

Entity renderer > Our hook : save vehicle ptr to a variable (if that's not a vehicle, a variable will stay unchanged (it will be a null-pointer))
{
    // ...
    Mesh rendering > Our hook : check if we render a vehicle (i.e., if variable is not a null-pointer) and apply new material properties
    {
    }    
    // ...
}
> Our hook : clear entity ptr (set variable to null-pointer)
#include "plugin.h"
#include "CHud.h"
#include <d3d9.h>
 
using namespace plugin;
 
class VehicleTransparency {
    struct Transparency {
        float mValue = 1.0f; // default vehicle transparency
        Transparency(CVehicle *) {} // dummy constructor
    };
 
    inline static VehicleExtendedData<Transparency> TransparencyInfo; // extender instance
    inline static CVehicle *CurrentVehicle = nullptr; // we store current renderer vehicle here
    inline static D3DMATERIAL9 CurrMaterial; // storage for material
public:
    // get/set transparency for vehicle
    static void Set(CVehicle *vehicle, float value) { TransparencyInfo.Get(vehicle).mValue = value; }
    static float Get(CVehicle *vehicle) { return TransparencyInfo.Get(vehicle).mValue; }
 
    VehicleTransparency() {
        static CdeclEvent<AddressList<0x757018, H_CALL, 0x757043, H_CALL, 0x7572F2, H_CALL, 0x75731D, H_CALL, 0x7FA320,
            H_CALL, 0x7FA360, H_CALL>, PRIORITY_AFTER, ArgPickNone, void()> myOnFlushRenderStates; // before primitive render
        static CdeclEvent<AddressList<0x553C52, H_CALL, 0x553CB8, H_CALL, 0x553D8F, H_CALL, 0x732C48, H_CALL>,
            PRIORITY_AFTER, ArgPickN<CVehicle *, 0>, void(CVehicle *)> myOnEntityRenderer; // entity renderer
 
        myOnEntityRenderer.before += [](CVehicle *entity) { // store entity if it's a vehicle
            CurrentVehicle = (entity->m_nType == ENTITY_TYPE_VEHICLE) ? entity : nullptr;
        };
 
        myOnEntityRenderer.after += [](CVehicle *entity) { // clear in any case
            CurrentVehicle = nullptr;
        };
 
        myOnFlushRenderStates += [] {
            if (CurrentVehicle && VehicleTransparency::Get(CurrentVehicle) != 1.0f) { // if transparent vehicle
                CurrMaterial = *reinterpret_cast<D3DMATERIAL9 *>(0xC98AF8); // get last material parameters
                CurrMaterial.Diffuse.a *= VehicleTransparency::Get(CurrentVehicle); // change material alpha
                RwD3D9SetMaterial(&CurrMaterial); // apply new material parameters
                SetRenderState(rwRENDERSTATEVERTEXALPHAENABLE, true); // enable transparency
                SetRenderState(rwRENDERSTATECULLMODE, rwCULLMODECULLBACK); // enable culling
                SetRenderState(rwRENDERSTATEALPHATESTFUNCTION, rwALPHATESTFUNCTIONGREATER); // change alpha-test
                SetRenderState(rwRENDERSTATEALPHATESTFUNCTIONREF, 0); // reference value
                _rwD3D9RenderStateFlushCache(); // apply rendering parameters
            }
        };
    }
} vehicleTransparency;
 
class Test {
public:
    Test() {
        Events::gameProcessEvent += [] {
            static bool messageDisplayed = false;
            CVehicle *playaCar = FindPlayerVehicle(0, false);
            if (playaCar) {
                float alpha = VehicleTransparency::Get(playaCar);
                if (KeyPressed(VK_OEM_4)) // [
                    alpha -= 0.01f;
                else if (KeyPressed(VK_OEM_6)) // ]
                    alpha += 0.01f;
                alpha = std::clamp(alpha, 0.0f, 1.0f);
                VehicleTransparency::Set(playaCar, alpha); // set transparency for player's current car
                if (!messageDisplayed) {
                    CHud::SetHelpMessage("Use [ ] keys to control vehicle transparency", false, false, false);
                    messageDisplayed = true;
                }
            }
        };
    }
} test;
As you already found, it doesn't work SkyGfx - because it introduces a new rendering pipeline for vehicles (so it ignores myOnFlushRenderStates hook).
For a better compatibility, I'd go with that 'classical R*'s solution'.
  • pep legal, Junior_Djjr and Veryzon like this

Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#15

Posted 4 weeks ago Edited by Junior_Djjr, 4 weeks ago.

Nope...Its 60 (decimal). It's a partial copy...not full (he..he...pegadinha do malandro !)

It's a f*cking coincidence  :monocle: 

I would love a good solution in .asi that makes all materials independent, being able to change the RGBA of them.

I think some API would be nice, where you send a vehicle and it does all the service. Doing such a thing with cleo isn't really cool...


SHIFAAH9
  • SHIFAAH9

    Hustler

  • Members
  • Joined: 23 Aug 2017
  • Maldives

#16

Posted 4 weeks ago

how about in LUA..?


pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#17

Posted 4 weeks ago Edited by pep legal, 4 weeks ago.

Previous code rewriten ! :whistle:
 
- Stability and Performance improvements
 
- Recursion used to walk through frame hierarchy (but not using SCM funtions)
 
- Cosmetic tweaks.
  • Junior_Djjr likes this

Junior_Djjr
  • Junior_Djjr

    Modding Lover

  • Members
  • Joined: 16 Dec 2011
  • Brazil
  • Best Map 2016 [San Andreas INSANITY] [Contribution]

#18

Posted 4 weeks ago Edited by Junior_Djjr, 4 weeks ago.

Why don't use atomicList? (like I used on Search Parts - Funcs.txt). Why do you need these _GetOkAtomics etc?
 
const
AtomicList = 0x8
RpAtomicOnList = 0x40
RwObjectParent = 0x4
end

:ListWalk {RpClump [email protected]}   
[email protected] += AtomicList
0A8D: [email protected] = read_memory [email protected] size 4 vp false
if [email protected] > 0 // first
then
    0085: [email protected] = [email protected] // store first
    repeat
    
        // Get RpAtomic
        0A8F: [email protected] = [email protected] - RpAtomicOnList
        
        // Get RwFrame
        0A8E: [email protected] = [email protected] + RwObjectParent
        0A8D: [email protected] = read_memory [email protected] size 4 vp false
        
        // Do anything...
         
        // Next                                  
        0A8D: [email protected] = read_memory [email protected] size 4 vp false
        
    until 003B:   [email protected] == [email protected] // check if current is first (end of list)
end
0AB2: ret 0

pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#19

Posted 4 weeks ago Edited by pep legal, 4 weeks ago.

Why don't use atomicList? (like I used on Search Parts - Funcs.txt).



No strong reasons. Excess of cautiousness maybe.

I though would be safer to replace atomics following clump hierarchy. I mean, first cut the leaves, then the branches, and last the trunk.

I'm not applying transparency under laboratory conditions...instead I'm doing it on traffic cars, in large scale.

But I will give a try to your way.

 

 

Why do you need these _GetOkAtomics etc?


 

Previously I was being very selective about which atomic would be transparent, or which one would be deleted.

_GetOkAtomics acts as a filter.

 

But I think your question is : Why to use callbacks ?        ==>  Performance !

.
.
 


pep legal
  • pep legal

    Old but Gold

  • Members
  • Joined: 17 May 2008
  • Brazil

#20

Posted 4 weeks ago Edited by pep legal, 4 weeks ago.

Small fixes on previous code. Just to keep it updated with the last founds.

 

 

Question.:  Does anyone know if the game "re-instance" a set of RxD3D9InstanceData ?

 

...and how to avoid that for a specific geometry ?

 

 

Spoiler




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users