Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks #1

Open
31 of 46 tasks
kianzarrin opened this issue Dec 17, 2019 · 24 comments
Open
31 of 46 tasks

tasks #1

kianzarrin opened this issue Dec 17, 2019 · 24 comments

Comments

@kianzarrin
Copy link
Collaborator

kianzarrin commented Dec 17, 2019

Moving boformer/NetworkSkins#42 to here because it does not sound like I am merging this with NS2 in the next version. and even if I do it may be a submodule.

In this task I hide tmpe cross walks
here I continue to version 2 of the operation to make further improvements.

Version 2.0 released:

  • use harmony
  • merge with ns2 Check compatibility with NS2
  • investigate cropped textures.
  • have road specific modification of crosswalks (eg small roads, highways, etc)
  • test custom on segments mentioned by users.
  • Hide crosswalks on level crossings.

Version 2.5 released:

  • when loading the game cache clear textures for all junctions with crossing ban. Currently when the
    game is loaded the user will have a hard time to move the camera around until the textures are cached.
  • mix segment ARPMap texture with node texture for smooth transition.
  • increase the performance of texture processing.
  • Cache used textures upfront
  • fix Real time compatibility
  • E/B/T support.
  • investigate caching of textures.
  • create texture dumps in debug mode.
  • benchmark/fix cache (array VS hashtable) EDIT: this won't apply to version 3
  • support asym road.
  • fix scale mismatch for 6L road. Fix road/node texture mismatch on "plain" roads #2
  • more fine tuning for smoother textures. (some of the Next2 roads)

Version 3.0:

  • Polish code
  • fix hot reload
  • Ensure texture cache hit
  • use CSUtilsCommons for logging.
  • wrap NetInfo
  • Option to exclude prefabs.
  • hard coded exclusion list.
  • Fix outstanding issues some roads have bad textures #6 Texture replacement bug #8
  • publish as experimental
  • publish as stable one week later
  • TMPE to require this mod.

Version 3.*

  • allow builtin prepared textures.
  • allow asset creators to add their textures.
  • allow users to add their own textures to my mod.
  • allow parallel processing of colors.
  • update should hide markings when segment/node flags are updated.

Version 4:

  • read about LODs: https://steamcommunity.com/workshop/filedetails/discussion/667342976/1636416951459546732/
  • hide crosswalks when camera is very far away. (LODs)
  • Update textures periodically
  • Patch TMPE to post update textures (harmony)
  • better scale detection algorithm.
  • better asym invert detection algorithm
  • provide options for list of roads to never/always hide crossings. (requires optimizations)
  • reset cache when game resolution changes.
  • perform real-time texture processing in a separate thread.
  • investigate texture replacements with median color.

Debug tools:

  • process texture outside of CS and then use Texture swap mod. This is to quickly review the results of texture swapping.
  • use in game debug UI to fine tune textures.

related:
CitiesSkylinesMods/TMPE#27
CitiesSkylinesMods/TMPE#27 (comment)
CitiesSkylinesMods/TMPE#40

@kianzarrin
Copy link
Collaborator Author

Currently the node textures with cross walks removed have sharp transitions:
Screenshot (223)

I am trying to SMOOTH out the node textures. I do not want to create PNG files manually because that approach is not practical for custom roads. This also reduces precious production time.

  • One way is to use the ARPMap of the segment textures and make it gradually fade out.

  • I am also thinking I don't need to crop out the node textures I can simply use a 1x1 texture with the median color of the Main texture. ( 1x1 textures are rendered properly :) )

Future idea:

  • additionally I am thinking of replacing the crosswalks with a stop line. This is going to further distract the user from sharp node textures. But I think I should only do so when there is a yield or stop sign. Another exciting improvement of TMPE :) though I think this should probably should be a prop not texture.

  • some node textures have built in stop line and crosswalks. In the image bellow the stop line for parking is part of the node texture but the stop line for cars is part of the road texture.
    download
    What to do ... what to do? adding a stop line prop here could be bad! maybe we can Ask people to be NS2 friendly and create extra node textures if they really want their junctions to be pretty. We can have options weather or not to add stop line when there is a Yeild/stop sign (only when stop line texture is not found).

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Dec 18, 2019

Ground_Node__AlphaMap
The picture above shows NEXT2 asym-6L ARPMap with road texture under the node texture. According to this picture I don't see how melding road ARP into node ARP is possible.

EDIT: Perhaps I can check for values that are too high and replace them with low values. I need to check a bunch of other ARP maps to be sure.

@kianzarrin
Copy link
Collaborator Author

I can't use mod tools to take a full dump
Screenshot (225)
I have to DIY

@kianzarrin
Copy link
Collaborator Author

when caching textures its important that my OnLevelLoaded is called after TMPE.
In order to determine mod orders I traced the code to LoadAssembliesRO

string[] files = Directory.GetFiles(modPath, "*.dll", SearchOption.AllDirectories);```

So it is kind of random. `m_LevelLoaded` event is called before `OnLevelLoaded()`.

It seems I have no choice but to Patch the loading functionality.

@chameleon-tbn
Copy link

Hi @kianzarrin - As you asked me on Steam for some information what are E/B Model of roads.... (E)levated/(B)ridge ;) I think that makes it clear

image

So if you have a road transition ground to elevated, ground to bridge, bridge to bridge or elevated to bridge the crossings are not removed at all on all the roads i mentioned in my comment on Steam.

image

the bugfix aka Chamëleon

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Dec 19, 2019

@thebugfixnet thanks . I haven't got around supporting bridge and tunnel transactions yet. I'll update the mod info.

@kianzarrin
Copy link
Collaborator Author

@thebugfixnet Fixed the E/B/T problem It was a one word fix!
Screenshot (231)

I kind of wished I had done this sooner and have saved you the effort of reporting all this.

@chameleon-tbn
Copy link

No problem - it is fixed that's all that is important 🥇 I'll test again :)

@chameleon-tbn
Copy link

Could this be cause by your update? I have nothing new -only your mod is updated...

Seems to collide with Garbage Bin Controller https://steamcommunity.com/sharedfiles/filedetails/?id=1386697922 ???

A Mod caused an error [System.Exception] Details: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: No target method specified for class VanillaGarbageBinBlocker.PropManagerDataPatch (declaringType=, methodName =AfterDeserialize, methodType=, argumentTypes=NULL) at Harmony.PatchProcessor.PrepareType () [0x00000] in :0 at Harmony.PatchProcessor..ctor (Harmony.HarmonyInstance instance, System.Type type, Harmony.HarmonyMethod attributes) [0x00000] in :0 at Harmony.HarmonyInstance.b__6_0 (System.Type type) [0x00000] in :0 at Harmony.CollectionExtensions.Do[Type] (IEnumerable1 sequence, System.Action1 action) [0x00000] in :0 at Harmony.HarmonyInstance.PatchAll (System.Reflection.Assembly assembly) [0x00000] in :0 at VanillaGarbageBinBlocker.UserMod.OnEnabled () [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception

@kianzarrin
Copy link
Collaborator Author

@thebugfixnet I disabled Harmony self patching as NS2 does to make it compatible with Real time mod. I will have a look into this.

@kianzarrin
Copy link
Collaborator Author

@thebugfixnet I cannot reproduce the problem. Can you please tell me the minimum number of mods to reproduce the problem and does removing my mod solves it?

I did got this though:
Screenshot (232)

My mods were:
Garbabe bin controler
Hide TMPE crosswalks V2.2 ALPHA
TMPE labs
NS2
Unlock all roads.

I will try to get to the bottom of it.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Dec 19, 2019

I closed the game and opened it again. I can't reproduce this any more.
Screenshot (234)

@thebugfixnet enabling and disabling mods does not always work due to an internal bug in the game resulting in "zombie" mods. You need to restart CS particularly if you migrate between different mod versions.

@chameleon-tbn
Copy link

@kianzarrin - the pipette Tool of NS2 still not work for me. If i click
image
just nothing happens.

@kianzarrin
Copy link
Collaborator Author

I failed to provide always/never options. The speed is just not fast enough. It requires optimization. I will postponed this feature.

@kianzarrin
Copy link
Collaborator Author

This is my current progress on smoothing node textures. I am blending in the segment textures into node textures after cropping out the crosswalks.
Screenshot (241)
The 4L road has problem with median. Clamping the APR values should solve this problem.
The 6L road has a another problem. Mismatch between node texture and segment texture. so the blending has created a sharp edge. I don't know why 4L road does not have this problem.
I am of-course stretching the textures before blending them.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Dec 23, 2019

I managed to smoothen out the barrier APR of the 4L road.:
Screenshot (1)

The 6L road is still creating a sharp junction texture. the APR maps of the node and segments are the same size. here I have put segment texture under the node texture:
Screenshot (243) - Copy
Edit: same image with increased contrast:
piant edited

EDIT:

  • Roads affected by this (APR mismatch): all Meduim/Large Vanilla/NExt2 roads which do not have decoration or central barriers. ( haven't tested it on small roads due to complications)
  • Roads not effected by this: all roads that have decorations (Grass/trees) or central barriers.
  • conclusion: So it seems that roads without decorations/barriers, scale the node texture differently.
  • problem: I do not know what exactly to look for (is there a field or a flag I need to check) to distinguish such roads from others and I do not know how much is the scaling factor. I have some ways of dealing with this problem in mind (check for a central lane without cars, check if road has decorations) but I am worried they may be hackish and complex and not future proof. I need to know what is the best solution to this problem rather than shooting in the dark.

It is not very obvious why It creates a sharp transition like shown in the first screenshot
EDIT: in the first screenshot for the 6L road, the segment to junction transition looks good in the middle of the texture. But it is being displaced outward as we go further away from the center. To understand why this happens for the 6L road and not the 4L road I am including the 4L APR too:
Screenshot (246) - Copy

All these textures are 1024x1024

I Do not understand why there is no texture displacement for the 4L but there is for 6L road. They both use the same piece of code.

//simplified code: all textures are 1024x1024
            Color[] colors2 = tex2.GetPixels(0, yM2, tex2.width, 1);
            for (int j = 0; j < yM; j++) {
                Color []colors  = tex .GetPixels(0, j, tex.width, 1);
                float w= (float)j / (float)yM; //weight
                for (int i = 0; i < colors.Length; ++i) {
                    Color c = colors[i];
                    Color c2 = colors2[i];
                    colors[i] = c * w+ c2 * (1 - w);
                }
                ret.SetPixels(0, j, tex.width, 1, colors);
            }
            ret.SetPixels(0, yM, tex.width, tex.height - yM, tex.GetPixels(0, yM, tex.width, tex.height - yM));

EDIT: bellow is the segment APRMap under the result of the code above:
node melt_APRMap

@Cgameworld
Copy link

Cgameworld commented Dec 29, 2019

Roads affected by this (APR mismatch): all Meduim/Large Vanilla/NExt2 roads which do not have decoration or central barriers. ( haven't tested it on small roads due to complications)

  • Roads not effected by this: all roads that have decorations (Grass/trees) or central barriers.
  • conclusion: So it seems that roads without decorations/barriers, scale the node texture differently.
  • problem: I do not know what exactly to look for (is there a field or a flag I need to check) to distinguish such roads from others and I do not know how much is the scaling factor. I have some ways of dealing with this problem in mind (check for a central lane without cars, check if road has decorations) but I am worried they may be hackish and complex and not future proof. I need to know what is the best solution to this problem rather than shooting in the dark.

Awesome to see the progress of this project

The scaling mismatch of the node textures could be due to the uv map on the node meshes being different, depending on the road. Try copying the uv map from another road’s node

You can also try grabbing the uv coordinates of the mesh with this

PrefabCollection<NetInfo>.FindLoaded(road).m_nodes[0].m_mesh.uv

The mesh uv coordinates could be grabbed from each side of the road at the curb and a scale factor calculated based on that?

@kianzarrin
Copy link
Collaborator Author

I fixed #2 using hackish code. I also mostly solved the asym roads. But the 2+3 NExt2 road has some problems.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Jan 13, 2020

Comparing the two images bellow (this is the vanilla 4 lane avenue), the zebra crossings of the lod texture starts after and offset:
RoadMediumnode_d
RoadMediumNode_LOD-No Name-rgb

I had to hard code 16 pixels offset into my code.

This is the preview of the mesh and the UV in blender:
Screenshot (292)

Why is there an offset for the lod textures. is it the same for all the [custom] roads?

@kianzarrin
Copy link
Collaborator Author

I made some progress with the lods. I replaced the original lod textures with new ones for testing just to prove my lods are good.
Screenshot (294)

I am having trouble to switch between normal textures and lod textures when TMPE activates and deactivates crosswalks. I think the problem is that segment textures are not updated when TMPE pans crossing.

I probably will end up patching TMPE using harmony.

@kianzarrin
Copy link
Collaborator Author

I patched TMPE to updatesegment() Everything works :)
Screenshot (296)

@originalfoo
Copy link
Member

Did it have any performance impact?

IMO, assuming we will be deprecating the old v10.20 STABLE branch it might be worth updating TMPE if there's no performance hit. We could test it on v11 ALPHA (which will become v11 LABS soon) once v11 STABLE is live.

@kianzarrin
Copy link
Collaborator Author

@aubergine10 Did it have any performance impact?

IMO, assuming we will be deprecating the old v10.20 STABLE branch it might be worth updating TMPE if there's no performance hit. We could test it on v11 ALPHA (which will become v11 LABS soon) once v11 STABLE is live.

It takes a few seconds to patch so that adds to startup time. No big deal for now but I work arounds tend to pile up if not dealt with.
I am not planning to support depricated TMPE.
It works with all TMPE versions.

@kianzarrin
Copy link
Collaborator Author

Benchmarking:

Info 417.5347036: BENCHMARK> totalCollisions=0 averageCollisions=0
Info 417.5356472: BENCHMARK> peforming cache speed benchmark:
Info 417.6368915: BENCHMARK> Done peforming cache speed benchmark 469*1000 times 
Info 417.6382061: Benchmarking Done!

so 469 materials cause no cache collision and take 0.1 sec load from material cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants