Jump to content

Parts shaders replacement, PBR, WIP release!


Lilleman

Recommended Posts

Hard to explain (my poor english level don't help). For me it's normal to modify these variables, because I know exactly how they will react, and how the engine will (or should) render them. But I'm afraid that modifying some contrat and brightness values to get a mask could be confusing.

Should've mentionned the mask is created in real-time, so you can see your changes directly, and save it from the game. You probably won't use it if you make your textures in an external editor.

This is not a intended to give perfect results, but it should be good enough to convert simple parts mods.
 

Quote

The only real point of confusion is Rough/Gloss map; that is more less solved by inverting one for the other.

 

Invert the colors. I don't have that yet. Noted.

 

1 hour ago, nli2work said:

Not sure if I really understand your algorithm to be honest, It looks like you'd get the same result for Metal/Gloss/Occlusion since you're just basing the return on texture's grayscale. What's the point of that?

It's an approximation, based on the assumption that parts will mostly be gray/black in KSP. Black being the painting (less reflective, more occlusion), lighter areas will have slightly higher values, making them more reflective/shinier.

It does not work with engines textures, where this logic is inverted (painting is lighter than the metal), that's also why I'm looking for another way to make masks.

 

Edit: how it looks on the FT-400 texture

No values, actual values, High values, Extreme values.

07PxPXIm.jpg

Edited by Lilleman
Link to comment
Share on other sites

Ok I see what you mean, at least better than before. :) All in all I think it'll work well enough. When Squad switches to standard shaders, I expect all the parts and textures will get remade; the textures at least... or they might borrow your code. Who knows.

I think your assumptions will work for Metal/Gloss, though giving the controls to the end user might be more confusing since they likely won't know what Metal/Gloss values are intended to do. Simple sliders for Reflection brightness and saturation should be enough in-game, I expect this is the biggest reason most players will use this mod, for real-time reflections. The masks can be generated at load time with values from a config file. Power users can adjust the config file if they feel the need to. 

For Occlusion some kind of unsharp mask should work better since occluded areas are most likely seams and not large flat surfaces. Seams most likely are where there's high contrast in diffuse texture values.

Edited by nli2work
Link to comment
Share on other sites

Made small progress. It's still a lot of trial and errors at this point.

Got inspired by this http://forum.unity3d.com/threads/shadow-fadeoff-approaching-far-clip-plane.356893/ , and found a way to use the original cameras to render cubemaps.

So, to get the galaxy skybox, I can use ScaledCamera.Instance.galaxyCamera.RenderToCubemap(), and to get the ground skybox, I can use ScaledCamera.Instance.cam.RenderToCubemap().

If I replace my reflection probe by a camera, I'll have three cubemaps... And no idea on how to make them blend nicely (I need to blend day/night cubemaps, then add the local reflections over it).

The blending factor will depends on the rotation of the planet, and the position of the player on it.

To makes things a bit more complicated: the ground skybox is way brighter than the other reflections, and it's worse at night, where it turns white/yellowish.

And yet I still haven't found the camera who will be able to render the ground. I'm looking for the "far" camera mentionned in the link above, if this one does not render the ground, I don't wich one will.

 

If you have any lecture on cubemap blending / know a mod who use the game's cameras, it'll be appreciated. Thanks!

Edited by Lilleman
Link to comment
Share on other sites

4 hours ago, Lilleman said:

Made small progress. It's still a lot of trial and errors at this point.

Got inspired by this http://forum.unity3d.com/threads/shadow-fadeoff-approaching-far-clip-plane.356893/ , and found a way to use the original cameras to render cubemaps.

So, to get the galaxy skybox, I can use ScaledCamera.Instance.galaxyCamera.RenderToCubemap(), and to get the ground skybox, I can use ScaledCamera.Instance.cam.RenderToCubemap().

If I replace my reflection probe by a camera, I'll have three cubemaps... And no idea on how to make them blend nicely (I need to blend day/night cubemaps, then add the local reflections over it).

The blending factor will depends on the rotation of the planet, and the position of the player on it.

To makes things a bit more complicated: the ground skybox is way brighter than the other reflections, and it's worse at night, where it turns white/yellowish.

And yet I still haven't found the camera who will be able to render the ground. I'm looking for the "far" camera mentionned in the link above, if this one does not render the ground, I don't wich one will.

 

If you have any lecture on cubemap blending / know a mod who use the game's cameras, it'll be appreciated. Thanks!

Not sure about blending multiple cube maps but why use three cameras instead of one? Use one camera and change its position then RenderToCubemap()

			if (!HighLogic.LoadedSceneIsEditor)
			{
				// Render skybox
				_go.transform.position = GalaxyCubeControl.Instance.transform.position;
				_cam.farClipPlane = 100.0f;
				_cam.cullingMask = 1 << 18;
				_cam.clearFlags = CameraClearFlags.Skybox;
				if (_cam.RenderToCubemap (_rtex, faceMask))
					result = true;
				
				// Render terrain before scaled space to avoid terrain artifacting
				_go.transform.position = transform.position;
				_cam.farClipPlane = scaledFaderEnd * 3;
				_cam.cullingMask = (1 << 15);
				_cam.clearFlags = CameraClearFlags.Depth;
				if (_cam.RenderToCubemap (_rtex, faceMask))
					result = true;
				
				// Render scaled space
				_go.transform.position = ScaledSpace.Instance.transform.position;
				_cam.farClipPlane = 3.0e7f;
				_cam.cullingMask = (1 << 10)  | (1 << 9);
				if (_cam.RenderToCubemap (_rtex, faceMask))
					result = true;

				// Render everything else
				_go.transform.position = transform.position;
				_cam.farClipPlane = scaledFaderEnd;
				_cam.cullingMask = (1 << ) | (1 << 1) | (1 << 4);
				if (_cam.RenderToCubemap (_rtex, faceMask))
					result = true;
			} 
			else
			{
				_go.transform.position = this.transform.position;
				_cam.farClipPlane = 1000f;
				_cam.cullingMask = ~((1 << 5) | (1 << 11) | (1 << 12) | (1 << 13));
				if (_cam.RenderToCubemap (_rtex, faceMask))
					result = true;
			}

 

Link to comment
Share on other sites

The two other cameras are already initialized when I need them, I thought it would be an easy way to get these two cubemap in the final reflection cubemap

//Skybox
ScaledCamera.Instance.galaxyCamera.RenderToCubemap(rtex);
//Scaled space
ScaledCamera.Instance.cam.RenderToCubemap(rtex);
//Scene
//(...)

Instead of setting the culling mask and position each time. But I realized this afternoon after testing a bit more that I don't have enough control on these cameras.

 

There's something I didn't tried yet in your snippet. I will make the camera render the terrain before the scaled space, and see how it turns out. Thanks!

 

Edited by Lilleman
Link to comment
Share on other sites

  • 3 weeks later...

Since 1.1 hit, the optional part reflection in Texture Replacer has been wreaking havoc on my game's FPS, so I thought I'd give this a try.

Unfortunately, after removing the old mod and putting this in, it doesn't actually seem to work. Not sure if this is still being supported, but the readme said to post in this thread so--why not?

Is anyone able to get this running along KSPRC? I have a pretty robust system (even considering how unoptimized KSP is), but so far Texture Replacer's reflection solution is the only one that seems to actually make parts reflect. This one didn't get any parts reflecting, but it did butcher my framerates for a small ship in orbit to test it. :(

Maybe it's not compatible with KSPRC? 

Link to comment
Share on other sites

  • 1 month later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

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...