TexturesUnlimited icon indicating copy to clipboard operation
TexturesUnlimited copied to clipboard

Shader not applied under certain conditions (PartVariants)

Open Electrocutor opened this issue 6 years ago • 7 comments

Consider the following example: KSP_MODEL_SHADER { model = SquadExpansion/MakingHistory/Parts/Engine/Assets/KE-1 model = SquadExpansion/MakingHistory/Parts/SharedAssets/Shroud2x2 model = SquadExpansion/MakingHistory/Parts/SharedAssets/Shroud2x3 //model = SquadExpansion/MakingHistory/Parts/SharedAssets/Shroud2x4 MATERIAL { shader = SSTU/PBR/Metallic } }

If you go in game, the KE-1 and all of its variants will have the shader applied, but none of the shrouds will. Then, uncomment the last shroud, now all of them properly get applied.

I suspect this may be similar to how the fairings work? The shrouds are by default not shown and only become shown after you attach another part at a specific position.

I am thinking that perhaps these models are not found in the direct transform chain and must be found via some other property that simply holds onto a reference and then adds or removes it from the transform chain as needed. (just a suspicion though)

Electrocutor avatar Apr 10 '18 19:04 Electrocutor

Interesting....

I'll have to see exactly how/where those models are stored and loaded. I believe that the shrouds are added to the parts through MODEL nodes, but I'll have to take a look at the part configs to know.

Strange that they would all suddenly work/not-work depending on the patched status of the last model from the list.

shadowmage45 avatar Apr 10 '18 19:04 shadowmage45

Can confirm the issue as described. Will see if it can be duplicated on any other parts.

Initial guesses is that there is something in the part-variant system that is maintaining a 'shared material' reference, and re-applying it to the all of the models. Somehow if TU updates all of the models using that material, the shared reference is also updated.

Sadly, I don't have access to the KSP code to really see what is going on with it or why this might happen. Will still try and do some debugging on it though, and if nothing else, find a way to patch/hack around the problem.

shadowmage45 avatar Apr 11 '18 00:04 shadowmage45

In: getModelTransforms()

I think transform.find() Does not see inactive GameObjects. try the following: rootGameObject.GetComponentsInchildren<Transform>(true) or rootGameObject.GetComponentsInchildren<Renderer>(true) the "true" in the braces forces that also the components of inactive GameObjects are returned.

If its not working: reapply the material on this GameEvent:

GameEvents.onEditorVariantApplied.Add(ReapplyTexture);

GER-Space avatar Nov 21 '18 07:11 GER-Space

This issue is a bit out-of date;

There is now a custom TUPartVariant module that integrates with the stock variant system as best it can.

However, now the issue that I'm running into is that there is at least one instance where stock code is manipulating the PartVariant materials without calling the relevant events (thus I have no opportunity to 'correct' whatever dumb crap the stock module did).

shadowmage45 avatar Nov 21 '18 19:11 shadowmage45

@shadowmage45 I do wonder if this is also an issue with Restock. E.g. Stayputnik does not show its reflective features when TU is installed. I do force dx11 and only used TU and the restocked mods. ksp_TU_restock

https://gist.github.com/maushacks/a5c5bc5b80ea5aaa162fd1ffdb319b4a is the output.log

maushacks avatar Aug 13 '19 20:08 maushacks

Restock doesn't work because they change models and textures (and often shaders), and whatever patch set you are using does not target those models (and/or the replaced models do not use the cubemapped shader).

I.E. Not related to the originally posted issue, but something specific to Restock and the models/shaders they use. (Note how the hex probe core still has reflections, so likely they just used a diffuse/flat shader for the stayputnik).

shadowmage45 avatar Aug 13 '19 21:08 shadowmage45

@shadowmage45 Ah, sorry, I did post this twice. My bad. I lost track of the threads. Thanks for the prompt reply.

maushacks avatar Aug 13 '19 21:08 maushacks