Jump to content

[1.9.x] Textures Unlimited - PBR-Shader, Texture Set, and Model Loading API


Shadowmage

Recommended Posts

21 hours ago, Warsoul said:

 

I want to use my PBR Texture Set from substances Painter 2 into KSP to look like this : https://sketchfab.com/models/89ff537215474f588c3ffa317e92ff93

If i understand well;

1- Export Unity 5 Metal PBR maps from SP2018

2- Import Unity 5 Metal PBR maps into Unity 2017.4

3- Input Maps into Ksp\Emissive\Bumped+Specular

4- Add Textures Unlimited shaders to \gamedata

5- Add Metalic .cfg

6- Add Roughness .cfg

That's it ?

 

Close, but it can be simlified a bit.

1. Export textures from SP using Unity5 Metal PBR preset.

2. Export models from part-tools.  They don't need any textures/materials assigned at all.

3. Copy your texture somewhere in the GameData folder

4. Add TexturesUnlimited

5. Create a .cfg file like below, where 'model = XXXXX' points towards your model

Close, but you only need one config file, it should look something like this:

KSP_MODEL_SHADER
{
	model = SSTU/Assets/ST-GEN-DSP-ISS
	MATERIAL
	{
		shader = SSTU/PBR/Metallic
		texture = _MainTex, SSTU-PBR/Assets/ST-GEN-DSP-ISS-DIFF-PBR
		texture = _BumpMap, SSTU/Assets/ST-GEN-DSP-ISS-NRM
		texture = _MetallicGlossMap, SSTU-PBR/Assets/ST-GEN-DSP-ISS-MET-PBR
		texture = _AOMap, SSTU/Assets/ST-GEN-DSP-ISS-AO
	}
}
@REFLECTION_CONFIG[default]
{
	%enabled = true
}

 

If you need multiple materials in a model, the config file becomes much more complex, but it can still be done.

9 hours ago, Jesse-Lacey said:

I have a slight suspicion that it's because ProbesPlus! hasn't been updated just yet, can you confirm this? If so it's not a big deal I'll just wait till things get updated to use them together.

Very likely the cause.  If they haven't updated yet, then there is zero expectation that it would work properly.

Link to comment
Share on other sites

On 4/5/2018 at 5:38 PM, Shadowmage said:

Apologies for the delay.  Far too many things contending for my far too limited time.

I was unable to spot anything in your log from a quick keyword search.  I will be reviewing it in more depth over the next few days to try and see if there is any cause stated in the log.

I have a feeling though that it is going to come down to the graphics chipset you are using not supporting the feature (even though spec-sheets say it should...wonderful Intel gfx...)

's fine. Yeah... good ol' laptops suck at gaming! Kinda annoying. Thanks for all the help!

Link to comment
Share on other sites

Thank you ShadowMage, Manwith Noname helped me alot yesterday to get my mod PBR ready, it work now ! Thank you !

Look like we can't refresh the gamedata with the PBR.cfg, the metallic value update each time but the smoothness won't update until i restart KSP completly. Can we fix this or ksp can't recompile shaders in runtime ?

12458B0DF48E99704596120486A86B8E11D51B3B7Bzn3D8.png

Edited by Warsoul
Link to comment
Share on other sites

1 minute ago, Jimbodiah said:

It's made for 1.4.2, not 1.3.1.   use 1.0.0.8 instead.

Yes, but when I tried that, it crashed. I was just wondering if 1.1.0.12 would do the same, so I dont end up wasting a lot of time.

Link to comment
Share on other sites

13 hours ago, DeltaDizzy said:

Yes, but when I tried that, it crashed. I was just wondering if 1.1.0.12 would do the same, so I dont end up wasting a lot of time.

No, the new versions of TU will not work on old versions of KSP.  Simply incompatible.  This is due to both API changes in KSP (.dlls incompatible), as well as asset bundle and shader changes in Unity (shader bundles incompatible).

19 hours ago, Warsoul said:

Thank you ShadowMage, Manwith Noname helped me alot yesterday to get my mod PBR ready, it work now ! Thank you !

Glad to hear you got it all working :)

19 hours ago, Warsoul said:

Look like we can't refresh the gamedata with the PBR.cfg, the metallic value update each time but the smoothness won't update until i restart KSP completly. Can we fix this or ksp can't recompile shaders in runtime ?

Likely there is something I'm caching that needs to be rebuilt when the MM cache is updated.  (You are reloading the database after making changes, right?)

Really not a high priority, but I'll add it onto the TODO list.

Link to comment
Share on other sites

On 08/04/2018 at 3:36 PM, Shadowmage said:

If you need multiple materials in a model, the config file becomes much more complex, but it can still be done.

Can we do this with a model which have only one mesh?

Link to comment
Share on other sites

5 minutes ago, Vandest said:

Really ?!

Can you tell me where I can found a exemple, I searched for but to no avail.

The config I posted previous is a perfect example of how to set it up for a model with only a single mesh.  (operating on all meshes in a model is the default mode)

KSP_MODEL_SHADER
{
	model = SSTU/Assets/ST-GEN-DSP-ISS
	MATERIAL
	{
		shader = SSTU/PBR/Metallic
		texture = _MainTex, SSTU-PBR/Assets/ST-GEN-DSP-ISS-DIFF-PBR
		texture = _BumpMap, SSTU/Assets/ST-GEN-DSP-ISS-NRM
		texture = _MetallicGlossMap, SSTU-PBR/Assets/ST-GEN-DSP-ISS-MET-PBR
		texture = _AOMap, SSTU/Assets/ST-GEN-DSP-ISS-AO
	}
}
@REFLECTION_CONFIG[default]
{
	%enabled = true
}

 

Where 'model = XXXX' points to the name of the model .mu file.  This particular config will apply the specified shader and textures to all meshes found in the model.

Link to comment
Share on other sites

Yes, I was understand this. But there is also only one material in this example. I need two materials with two different Metallic Gloss Map on only one mesh. And also two different MainTex (with different alfa)

Edited by Vandest
Link to comment
Share on other sites

3 minutes ago, Vandest said:

Yes, I was understand this. But there is also only one material in this example. I need two materials with two different Metallic Gloss Map on only one mesh.

KSP does not support multiple materials on a single mesh (e.g. submaterials, per-face materials, etc).  As such, TU does not support it either.

You will need to split that mesh into separate meshes, each with only a single material.  You would then write the config file with two MATERIAL blocks, using 'mesh = XXXX' to point the material blocks towards the proper meshes within the model.

Link to comment
Share on other sites

@Shadowmage So after having been stupid a number of times, it occurs to me... why not just default to enabled = true? This entire mod does not work at all unless this is true to begin with. In fact, if any other mod happens to include a TU config, but forgets to set enabled=true it will instead turn the textures black.

Link to comment
Share on other sites

27 minutes ago, Electrocutor said:

This entire mod does not work at all unless this is true to begin with.

Large portions of the mod work just fine without reflections -- asset bundle based model loading, basic texture sets, legacy texture replacement for database models.  Anything that doesn't need PBR shaders will work fine with reflections disabled.

There are actually quite a few mods using it just for those purposes, which would suffer a performance hit if reflections were enabled (  @bcink's mods ) .  SSTU -- even though it includes TU in the distribution, does not use PBR textures or need reflections in its default configuration (this might be changing with the 1.4 releases, but is true at the moment).

I'll give it some thought though.

Link to comment
Share on other sites

1 minute ago, Shadowmage said:

Large portions of the mod work just fine without reflections -- asset bundle based model loading, basic texture sets, legacy texture replacement for database models.  Anything that doesn't need PBR shaders will work fine with reflections disabled.

There are actually quite a few mods using it just for those purposes, which would suffer a performance hit if reflections were enabled (  @bcink's mods ) .  SSTU -- even though it includes TU in the distribution, does not use PBR textures or need reflections in its default configuration (this might be changing with the 1.4 releases, but is true at the moment).

I'll give it some thought though.

Okay. I guess my only thought would then be whether or not enabling it actually has any non-negligible performance hit. From what I've read, many people love this precisely because it doesn't affect their fps at all, even when using built-in Intel GPU. There is, unfortunately, a bad vibe from the word 'reflections' due to the poor-performance implementation of it left over from TextureReplacer.

Link to comment
Share on other sites

Have there been any changes to the code in the last update? Old configs (I'm using the ones for CxA and a few other mods made by @Electrocutor) for some reason don't work for me with the latest versions of KSP and TU. The texture set seems not to be found, even tough it's in the same .cfg file as the texture switch module...

The log file

fB6e8g5.png

Link to comment
Share on other sites

1 minute ago, notJebKerman said:

Have there been any changes to the code in the last update? Old configs (I'm using the ones for CxA and a few other mods made by @Electrocutor) for some reason don't work for me with the latest versions of KSP and TU. The texture set seems not to be found, even tough it's in the same .cfg file as the texture switch module...

The log file

fB6e8g5.png

I haven't updated any but PorkjetStock to the new syntax yet. You can read about Shadow's changes and update it yourself though, it's not too tough.

Link to comment
Share on other sites

2 minutes ago, notJebKerman said:

Have there been any changes to the code in the last update? Old configs (I'm using the ones for CxA and a few other mods made by @Electrocutor) for some reason don't work for me with the latest versions of KSP and TU. The texture set seems not to be found, even tough it's in the same .cfg file as the texture switch module...

The log file

 

 

In the texture-switch module configs, where texture set names used to be specified such as:

TEXTURESET
{
	name = XXXXXX
}

 

Should now be specified like so:

textureSet = XXXXX

E.G.

MODULE
{
	name = KSPTextureSwitch
	//the name of the 'default' texture set when the part is pulled out of the editor parts list
	currentTextureSet = XXXXX1
	//any other setting such as sectionName
	sectionName = Primary
	//then add your texture-set references, replacing the 'XXXXXN' with the name of the texture set
	textureSet = XXXXX1
	textureSet = XXXXX2
	textureSet = XXXXX3
}

 

Basically the change was to simplify the configs a bit and remove all of the extra TEXTURESET nodes.  AFAIK that should be the only 'breaking' change -- all other changes should have backwards compatibility in place.  (may fix the backwards compat on this as well in the next release if it won't interfere with anything else; no guarantees though, so it is best to fix/update your configs)

Link to comment
Share on other sites

I don't know if this will be helpful to many people, but you can update old configs to use the new syntax pretty quickly with some regular expression find/replace operations.

In Notepad++ on Windows, these seem to work. YMMV with other text editors / operating systems. Open the .cfg file in Notepad++. Press Ctrl-H to bring up the find/replace window. Make sure that the "Regular expression" radio button is selected and ". matches newline" is unchecked.

Find field:

(@|\+)*?TEXTURE(,[0-9]{1,2})*?( ?// ?.+)*?( ?\r?\n?\t{0,3}\{)

Replace field:

\1MATERIAL\2\3\4

Click "Replace All".

 

Then, find field:

(@|\+)*?TEXTURESET(,[0-9]{1,2})*?( ?// ?.+)*? ?\r?\n?\t{0,3}\{\r\n\t{1,3}name = (.+)\r\n\t{1,3}\}

Replace field:

\1textureSet\2 = \4 \3

Click "Replace All".

 

You can do this to a whole bunch of files at the same time by opening all the files in Notepad++ and clicking "Replace All in All Opened Documents" instead of "Replace All".

(Obviously now I've posted this there are likely to be several embarrassing syntax errors. And yes, I imagine there is a chance of false matches or misses. Such is life. If you show me a .cfg it doesn't work for, I can probably adapt the regex.)

Edited by UnanimousCoward
Modified regex expressions to catch lines ending in comments too.
Link to comment
Share on other sites

10 hours ago, Shadowmage said:

 

In the texture-switch module configs, where texture set names used to be specified such as:


TEXTURESET
{
	name = XXXXXX
}

 

Should now be specified like so:


textureSet = XXXXX

E.G.


MODULE
{
	name = KSPTextureSwitch
	//the name of the 'default' texture set when the part is pulled out of the editor parts list
	currentTextureSet = XXXXX1
	//any other setting such as sectionName
	sectionName = Primary
	//then add your texture-set references, replacing the 'XXXXXN' with the name of the texture set
	textureSet = XXXXX1
	textureSet = XXXXX2
	textureSet = XXXXX3
}

 

Basically the change was to simplify the configs a bit and remove all of the extra TEXTURESET nodes.  AFAIK that should be the only 'breaking' change -- all other changes should have backwards compatibility in place.  (may fix the backwards compat on this as well in the next release if it won't interfere with anything else; no guarantees though, so it is best to fix/update your configs)

Thank's I had the same problem and just assumed their was something missing in the base TU release that needed to be changed to get the textures working. I was thinking I needed to wait for a update to SSTU to get Vens and Porkjet cfgs working. guess I should have just asked. I really cant overstate how much I appreciate the work that goes into a mod like this .  Thanks.  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...