Jump to content

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


Shadowmage

Recommended Posts

49 minutes ago, Gordon Dry said:

Which imho is weird - because DirectX 9 da fuq?

I thought so too... esp. as some of those effects won't even work on DX9....

50 minutes ago, Gordon Dry said:

neither

Noted; thx for the input :)

 

51 minutes ago, Electrocutor said:

I'd say Bloom and Lens Flare are the biggest ones for a PBR shader.

I hadn't even thought of lens flare, but I would imagine it should be relatively 'easy' as it shouldn't require any special information (just camera angle to light sources, some textures or procedural gen code for the flares, and controls for intensity).  Bloom I'm already about halfway done with a shader/script combo that works in the editor (had it sitting around awhile); nowhere close to trying it in KSP, but I'd imagine there isn't too much customization needed -- as it works on the finished image, there is no need for worrying about whatever the camera setup was that generated the image.

56 minutes ago, Electrocutor said:

The other would be the one that over-exposes shiny edges

If you can find out what it is called, please let me know.  Sounds like just another parameter in the bloom filter though, as you can adjust several of the thresholds to make those edges stand out more.  Could also be something that interacts at the surface-shader level to over-expose metallics in the original render steps?

57 minutes ago, Electrocutor said:

SSAO is only ok if you can optimize it well; staticobject-terrain, intra-vessel, and vessel-terrain (EVA is a vessel).

I'm not really set on having SSAO.  I love the concept, but the implementations that I've seen are far too wonky for my liking -- being very much camera/view dependent, moving around the scene makes the shading do... strange stuff.  In deferred rendering with the extra buffer data it might be able to be done better, but that is a moot point for KSP purposes.

 

54 minutes ago, Gordon Dry said:

I also can relinquish Motion Blur and Depth-of-Field.
So I am totally okay with bloom, AO and lens flare.

Yeah, motion-blur and depth-of-field I find are only nice in small doses, as they are often over-used in games.  Wouldn't mind some in-game toggles for them though (and config/parameter controls), which should be absolutely doable if I include them.


Sounds like at least bloom + lens flare should be on the list :)  Maybe start there, and work on adding others over time; no reason to rush it.

 

As this is primarily intended as a personal project, I'm mostly seeing if there is enough public interest to warrant either adding it to TU (as an optional, disabled by default feature) or packing it up separately.  Even if I don't end up including or 'releasing' it, I'll likely still have a repo on github with compiled and usable assets (and it will be licensed such that it will be downloadable and usable; it just wouldn't have a forum post anywhere).

The good thing about all of these is there is a multitude of sources available for implementation details, and even some 'ready to use' packages like the Unity PP stack, so I'm not going to have to invent any new mechanics... just implement the existing stuff such as to work with KSP.  The 'tricky' part will likely be hooking in to all of the cameras.  KSPs camera setup has always been a bit touchy...

Link to comment
Share on other sites

11 minutes ago, Electrocutor said:

(I am not seeing any clouds when I set a camera to any of those layers you mentioned above, so not sure what the deal is there).

Interesting, I just put EVE back in my install yesterday and haven't really tested it out much yet... let me make sure it is all still working (maybe its missing in TU as well?).

18 minutes ago, Electrocutor said:

artificial far cut-off that is much, much shorter than I specify.

Yeah, I ran into issues of that as well, only could solve it through the multi-pass render setup.

19 minutes ago, Electrocutor said:

I only see about 10 meters around me in local scenery and the rest is cut off.

Scaled space stuff actually isn't that far away from the camera/world origin... probably about 10m :).  Pretty sure the entire skybox is only a ~20m cube; at least the atmosphere is rendered inside of that (possibly scaled space as well), and then the depth buffer is cleared and the 'real world' is rendered on top of it all (local scenery, vessels, kerbals).  Again, was part of why I did the multi-pass rendering setup -- it is what KSP does, and the only way to get it rendered correctly.

23 minutes ago, Electrocutor said:

it looks like the Unity camera is either blending layers instead of stacking

Unity doesn't 'stack' layers (rendering order dependent on layer) -- if the objects layer is in the layer-mask, they all get thrown into the same bucket and rendered in a single 'pass', using the z-buffer for determining what is in front/behind.  Scaled space breaks this (and atmosphere, and skybox) because the objects are actually closer to the camera in the game scene (and just scaled down) than the surrounding scenery.

 

If it wasn't for all of those problems, TU wouldn't even need its reflection manager and rendering code -- I'd just slap the reflection-probe in the scene and update its position periodically.  I'm willing to try and help you sort these problems out (would be good for TU as well)... but I'm not sure some of them are fixable.

3 minutes ago, Electrocutor said:

Discovered that setting farClipPlane too high will cause all rendering to go up to 50% darker.

Probably causing imprecision in the depth-buffer (z-buffer), resulting in terrible z-culling and/or incorrect rendering orders.  The problem will mostly go away if you move the near-clip plane (a lot) further out.  Basically you want the orders-of-magnitude between your near and far clip planes to be as small as possible.  The more zeros in the differences, the less precise it will be, and the more artifacts that will occur.

I think ideally you only want 2-3 orders of magnitude between them.  If near-clip is 1m, you want far-clip to be 1,000m at most.  If near clip is 1,000m, your far clip could be ~1,000,000 without too much loss of precision.  (some of this may only apply to logarithmic depth buffers; not sure what the currently used default is...)

Link to comment
Share on other sites

38 minutes ago, Electrocutor said:

(I am not seeing any clouds when I set a camera to any of those layers you mentioned above, so not sure what the deal is there).

Quick testing shows that the EVE clouds definitely render for TU from orbit.  Strangely, the clouds on kerbin from 86k orbit are rendered in the 'local scenery' layer -- must be using a transparent shader so it renders after the opaque geometry, with depth-test disabled, or is being done in post-process.  I'm....guessing these are the non-scaled space clouds  (when does it cut off to using scaled space for kerbin? 100k?).

At ~150k orbit, the clouds are definitely only present in the 'scaled space/atmosphere' pass.

So there are definitely two different cloud sets for eve; standard and scaled.   Scaled space clouds are in either layer 9 or 10, and standard is in one of the four/five layers I posted above (sorry, can't really narrow it down too much more without compiling a custom debug version of TU, or digging through EVE source code...bleh).

 

Link to comment
Share on other sites

@alexus

I've figured out what is going on with the plants and glass in your greenhouse retexture.  The problem is that both of them are set to use the transparent shader, which has depth-writes disabled, and as transparent objects render front-to-back for a given render-pass, this causes the plants to be rendered -after- the glass.  In order to solve this you would need to change the render-queue of the material for the -plants- to be transparent-1 -- so far this capability does not exist in TU, but I will look into adding it for the 1.5 update, and will let you know when the feature is available and how to use it.

Link to comment
Share on other sites

That at least tells me that I am missing something, as opposed to them actually not being present.

 

As for the reflection probe:

My goal is to find the cleanest/cheapest way possible to get a usable reflection.

I'm not finished yet, but testing so far seems pretty good on this (just stock for now):

  • single reflectionProbe set to real-time, individual-faces
  • cullMask set on Vessel.SituationChanged event
    • If on planet, in air, or altitude < 10km, set to LocalScenery, Water, EVA
    • If in space, set to ScaledSpace, Atmosphere, EVA
  • clearFlags set to skybox
  • skybox set to renderTexture and updated only once per Vessel.SituationChanged event
    • If on planet, set to SkySphere, ScaledSpace, Atmosphere
    • If in space, set to SkySphere
Edited by Electrocutor
Link to comment
Share on other sites

34 minutes ago, Electrocutor said:

I'm not finished yet, but testing so far seems pretty good on this (just stock for now):

Ahh, I see what you are doing there :)

Might just appropriate some of it for myself.  Never really thought of using the actual Unity skybox as one of my renderTexture targets.

If I'm reading between the lines correctly, you are rendering the 'doesn't change very often' layers into a cubemap(render-texture), and pushing that into RenderSettings.Skybox ?  (or camera.skybox?)  From there, the probe only captures the local geometry (by culling mask) + pre-rendered skybox behind it all.  I like where you are going with it (if I'm correct in at least some of that).

Link to comment
Share on other sites

1 minute ago, Shadowmage said:

Ahh, I see what you are doing there :)

Might just appropriate some of it for myself.  Never really thought of using the actual Unity skybox as one of my renderTexture targets.

If I'm reading between the lines correctly, you are rendering the 'doesn't change very often' layers into a cubemap(render-texture), and pushing that into RenderSettings.Skybox ?  (or camera.skybox?)  From there, the probe only captures the local geometry (by culling mask) + pre-rendered skybox behind it all.  I like where you are going with it (if I'm correct in at least some of that).

You could actually use the existing ReflectionProbe, just during 1 frame you set the cull mask to your static skybox settings, force-render, then set it to what it should be. I haven't tested this yet to make sure it doesn't cause a flash though.

Link to comment
Share on other sites

13 minutes ago, Electrocutor said:

You could actually use the existing ReflectionProbe,

Or a second probe, specifically for updating of the skyboxes?  Could leave it set up full-time, and only enable it for the one frame to force-render.  Hmm.. I see what you are saying with the flicker though... (wait... I think there is an .Influence property on the probe itself that you might be able to set to zero so that it doesn't get used in active reflections)

Using a probe though would be perhaps less efficient, as it will still do convolution on the image (blurring mip-maps), and we really only care about mip0 for the skybox texture.  But, at the same time, I noticed that the reflection probes 'renderToCubeMap' routines are far more efficient than calling the same function from c# script -- might still be a net gain...

Link to comment
Share on other sites

Well, underwater fogging works... yes, that is a pair of MOLE tracks being used for water propulsion...

nT5nbZ4.png

 

Haven't been able to figure out where the stock shaders/rendering does its 'ambient light boost'; looks like it may be a Unity built-in that only works with legacy shaders, as the functions are not present in the stock shader code that I can find.  Still investigating...  probably won't spend too much time on it though, as I think the concept is flawed (if you really want the scene to be brighter... turn up the brightness/gamma on your monitor), and the implementation may not even have hooks that I can use.  (if someone has info on this, please let me know)

Link to comment
Share on other sites

4 hours ago, Shadowmage said:

While I've been working on updating the shaders and adding features, I've also been deliberating on adding some post-processing effects to TU (or as another small mod).  Essentially some parts of what KS3P does.... but functional with OpenGL and DX11 (as the KS3P author has expressed no desire to make it functional on either platform last I checked), and with a much simpler to set up and use config system (as well as an in-game GUI for real-time tweaking and generation of configs).

Is there anyone else who would be interested in Bloom, Motion Blur, Depth-of-Field and Screen-Space Ambient Occlusion effects?  I'm not personally interested in tone-mapping, eye-adaption, or vignette.... though might consider implementing them as well (esp. if I just do as KS3P did and import the entire PP stack).

Fairly certain that I'm going to be doing this for myself, either way, but if there is enough interest in the features I will consider including it in TU or spinning it off as a new stand-alone mod.  Would really rather not  make a new stand-alone, as KS3P is already there for filling that need, but it is an option.  I'd also be willing to contribute the work back into KS3P if the author was receptive to it... but first he would have to completely redo his config system (which is one of the major reasons I won't use it as-is).

In game tweaking would fix my largest complaint with KS3P. I tried using the unity testing setup described by the author, but it looked different from KSP to me. I'd be happy to give up on eye-adaption and vignette too (I think they look bad unless barely noticeable). Bloom and SSAO give the most bang-for-buck, I think.

Link to comment
Share on other sites

29 minutes ago, Electrocutor said:

I really wish I knew why my EVE is acting differently from yours. This is with cullingMask set to 9 and 10.

 

Sec... checking the near/far clips I have for those layers, as I use different vals for each pass that I kind of trial-and-errored to get (actually built the GUI to adjust them from in-game).

Strange - I'm using essentially 'float.max' for far clip when rendering those layers --

near = 1.0f

far = 3.0e7f

I think I probably grabbed those values from KSPs cameras...

Link to comment
Share on other sites

8 hours ago, Electrocutor said:

The skybox thing has me a bit stuck: there are no cubemap shaders to use as a material for the skybox so far as I know, and you cannot just directly assign a cubemap to the skybox.

Hmm...There should be the 6-sided (separate image) cubemap shader, as that is used by KSP.. of course that would require splitting your cubemap render-texture into 6 separate textures.

^^ is why I included the SSTU/Skybox/Cubed shader in TU;  KSP did not build with the Unity equivalent, so I had to create and import my own.

Link to comment
Share on other sites

This yields a skybox that is all sorts of messed up, and the camera seems to completely ignore the cullingMask. Any ideas?

Spoiler

private void SetSkybox()
        {
            Material oMaterial;
            RenderTexture oTex;
            Shader[] aryShaders = Resources.FindObjectsOfTypeAll<Shader>();

            foreach (Shader oShader in aryShaders)
            {
                if (oShader.name == "Hidden/CubeCopy")
                {
                    oMaterial = new Material(oShader);

                    oTex = new RenderTexture(1024, 1024, 1024);
                    oTex.dimension = UnityEngine.Rendering.TextureDimension.Cube;

                    oMaterial.mainTexture = oTex;

                    _Skybox = oMaterial;
                }
            }
        }

        private void UpdateSkybox(Vessel oVessel, Vessel.Situations oSituation)
        {
            GameObject oObject = new GameObject("SkyBoxCam");

            oObject.transform.position = oVessel.gameObject.transform.position;
            
            Camera oCamera = oObject.AddComponent<Camera>();
            oCamera.enabled = false;

            List<KSPLayer> oLayers = new List<KSPLayer>();

            if (oSituation == Vessel.Situations.PRELAUNCH
                || oSituation == Vessel.Situations.LANDED
                || oSituation == Vessel.Situations.SPLASHED
                || oSituation == Vessel.Situations.FLYING
                || oVessel.altitude < 10000)
            { oLayers.Add(KSPLayer.Atmosphere); }
            else
            { oLayers.Add(KSPLayer.SkySphere); }

            oCamera.useOcclusionCulling = true;
            oCamera.cullingMask = GetCullingMask(oLayers);

            oCamera.RenderToCubemap((RenderTexture)_Skybox.mainTexture);

            RenderSettings.skybox = _Skybox;
        }

 

 

I've also wondered why Squad was so adamant about removing all the built-in Unity features and assets; never made any sense to me.

What does the SSTU skybox shader render?

Edited by Electrocutor
Link to comment
Share on other sites

30 minutes ago, Electrocutor said:

Any ideas?

That shader (Hidden/CubeCopy) does... strange things; I couldn't get it working properly either.  The culling mask bit doesn't make sense though, as that should be handled by Unity before the geometry is ever sent to the render pipeline (unless the shader has something regarding ignoring culling masks? idk if thats even a thing).   Really that shader is for only copying of one cubemap input to another cubemap output, while sampling of a specific mip-map.

Shader "Hidden/CubeCopy" {
	Properties {
		_MainTex ("Main", CUBE) = "" {}
		_Level ("Level", Float) = 0.
	}
	CGINCLUDE
	#pragma vertex vert
	#pragma fragment frag
			
	#include "UnityCG.cginc"

	float _Level;

	struct v2f {
		float4 pos : SV_POSITION;
		float4 uvw : TEXCOORD0;
	};

	v2f vert(appdata_base v)
	{
		v2f o;
		o.pos = UnityObjectToClipPos(v.vertex);
		o.uvw = v.texcoord;
		return o;
	}

	UNITY_DECLARE_TEXCUBE(_MainTex);

	float4 frag(v2f  i) : SV_Target
	{
		return UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, i.uvw.xyz, _Level);
	}
	ENDCG
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		Pass {
			ZTest Always
			Blend Off
			AlphaTest off
			Cull Off
			ZWrite Off
			Fog { Mode off }
			CGPROGRAM
			#pragma target 3.0
			ENDCG
		}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		Pass {
			ZTest Always
			Blend Off
			AlphaTest off
			Cull Off
			ZWrite Off
			Fog { Mode off }
			CGPROGRAM
			#pragma target 2.0
			ENDCG
		}
	}
}

 

Here is what SSTU's skybox shader code is (mostly copied from Unity Skybox/Cubemap shader, with some modifications/simplifications)

Shader "SSTU/Skybox/Cubemap" {
Properties {
	[NoScaleOffset] _Tex ("Cubemap", Cube) = "grey" {}
}

SubShader {
	Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
	Cull Front ZWrite Off

	Pass {
		
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		#pragma target 2.0

		#include "UnityCG.cginc"

		samplerCUBE _Tex;
		
		struct appdata_t {
			float4 vertex : POSITION;
		};

		struct v2f {
			float4 vertex : SV_POSITION;
			float3 texcoord : TEXCOORD0;
		};

		v2f vert (appdata_t v)
		{
			v2f o;
			o.vertex = UnityObjectToClipPos(v.vertex);
			o.texcoord = v.vertex.xyz;
			return o;
		}

		fixed4 frag (v2f i) : SV_Target
		{
			half4 c = texCUBE (_Tex, i.texcoord);
			return half4(c.rgb, 1);
		}
		ENDCG 
	}
} 	


Fallback Off

}

It literally just reads the cubemap, and renders that pixel with zero additional processing.  No lighting, no mip-maps (I think?),  about as simple as it can get.  Granted, I'm not really an expert on straight HLSL style shaders (vert/frag setup), so I could be off on some of this.

If you want, I can pack up an asset bundle for you with just that shader in it, or you are otherwise free to use that shaders' source from the TU repository (with/without modifications) if you want to compile your own.

Link to comment
Share on other sites

52 minutes ago, Electrocutor said:

I've also wondered why Squad was so adamant about removing all the built-in Unity features and assets; never made any sense to me.

Its the default behavior of Unity to not include unused assets in the builds.  Its actually quite a PITA to force it to include something that isn't used in any of the scenes or assets that are built; it can be done, but has to be done on a per-asset basis -- in the instance of like the Unity Standard shader, they would need to include a material for every keyword combination they wished to make available in-game.  Easier for them to not do any of that extra work.

Link to comment
Share on other sites

I used the SSTU skybox shader as well as a test: the output texture is identical to using CubeCopy: there has to be something seriously wrong with the camera.

One thing I noticed is that if you create a camera of any kind, it seems that the game automatically sets it as the main game camera unless it's disabled.

The trouble I am having right now is that reflection probe culling seems to work fine, but camera culling doesn't: it will always include layer 0, no matter what you set it to.

1 minute ago, Shadowmage said:

Its the default behavior of Unity to not include unused assets in the builds.  Its actually quite a PITA to force it to include something that isn't used in any of the scenes or assets that are built; it can be done, but has to be done on a per-asset basis -- in the instance of like the Unity Standard shader, they would need to include a material for every keyword combination they wished to make available in-game.  Easier for them to not do any of that extra work.

No, Unity added a checkbox to just include everything a while back.

Link to comment
Share on other sites

7 minutes ago, Electrocutor said:

No, Unity added a checkbox to just include everything a while back.

Yes, if you want everything.  Including a ton of stuff that would be of zero use in KSP.  .... I really shouldn't be trying to defend them... I think they should have included a lot more of the standard assets as well.

8 minutes ago, Electrocutor said:

The trouble I am having right now is that reflection probe culling seems to work fine, but camera culling doesn't: it will always include layer 0, no matter what you set it to.

That doesn't seem right... they work fine when TU uses a camera to render with layer-masks.   How specifically are you setting the masks to the camera?  Could be a bit-masking issue where the bit for layer zero is still flipped.

https://github.com/shadowmage45/TexturesUnlimited/blob/master/Plugin/SSTUTools/KSPShaderTools/Addon/ReflectionManager.cs#L415

^^ is what TU is using; but again, I'm using manually bit-bashed values for the masks.

To ignore layer 0, make sure that bit 0 (the value for 1) is not flipped in your mask -- e.g. if you display the value it should be an even number.

 

LoL, here soon you will end up with a functional equivalent of what TU has had to do for the reflection stuff.  I tried, and tried... and tried more... to keep it simple... but it was just one ridiculous hurdle after another to get even the basics working.

Link to comment
Share on other sites

1 minute ago, Shadowmage said:

LoL, here soon you will end up with a functional equivalent of what TU has had to do for the reflection stuff.  I tried, and tried... and tried more... to keep it simple... but it was just one ridiculous hurdle after another to get even the basics working.

Honestly, I mostly wanted to figure this out for the galaxy map when your ship is space, but it's not a big deal.

 

Here is all the code for stock:

Spoiler

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace UnofficialPatch
{
    public class FixReflections
    {
        private EventData<GameEvents.HostedFromToAction<Vessel, Vessel.Situations>>.OnEvent VesselSituationChangedEvent;

        public void Start()
        {
            this.VesselSituationChangedEvent = new EventData<GameEvents.HostedFromToAction<Vessel, Vessel.Situations>>.OnEvent(VesselSituationChangedEventHandler);
            GameEvents.onVesselSituationChange.Add(this.VesselSituationChangedEvent);
        }

        private void VesselSituationChangedEventHandler(GameEvents.HostedFromToAction<Vessel, Vessel.Situations> oSituation)
        {
            if (oSituation.host == null)
            { return; }

            UpdateProbe(oSituation.host, oSituation.to);
        }

        private void UpdateProbe(Vessel oVessel, Vessel.Situations oSituation)
        {
            ReflectionProbe oProbe = null;
            List<KSPLayer> oLayers = new List<KSPLayer>();

            oProbe = oVessel.gameObject.GetComponent<ReflectionProbe>();

            if (oProbe == null)
            {
                oProbe = oVessel.gameObject.AddComponent<ReflectionProbe>();

                oProbe.mode = UnityEngine.Rendering.ReflectionProbeMode.Realtime;
                oProbe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.EveryFrame;
                oProbe.timeSlicingMode = UnityEngine.Rendering.ReflectionProbeTimeSlicingMode.IndividualFaces;
                oProbe.nearClipPlane = 0.1f;
                //oProbe.farClipPlane = 5000f;
                oProbe.farClipPlane = float.MaxValue / 1.2f;

                Debug.Log("[UnofficialPatch] Created ReflectionProbe on '" + oVessel.name + "'.");
            }

            if (oSituation == Vessel.Situations.PRELAUNCH
                || oSituation == Vessel.Situations.LANDED
                || oSituation == Vessel.Situations.SPLASHED
                || oSituation == Vessel.Situations.FLYING
                || oVessel.altitude < 10000)
            {
                oLayers.Add(KSPLayer.LocalScenery);
                oLayers.Add(KSPLayer.Water);

                oProbe.clearFlags = UnityEngine.Rendering.ReflectionProbeClearFlags.Skybox;
            }
            else
            {
                oLayers.Add(KSPLayer.Atmosphere);
                oLayers.Add(KSPLayer.ScaledScenery);

                oProbe.clearFlags = UnityEngine.Rendering.ReflectionProbeClearFlags.SolidColor;
                oProbe.backgroundColor = Color.black;
            }

            oProbe.cullingMask = GetCullingMask(oLayers);
        }

        public static int GetCullingMask(List<KSPLayer> oLayers)
        {
            int iCullingMask = 0;

            foreach (KSPLayer oLayer in oLayers)
            { iCullingMask = (iCullingMask | (1 << (int)oLayer)); }

            return iCullingMask;
        }

        public enum KSPLayer
        {
            Default = 0,
            TransparentFX = 1,
            IgnoreRaycast = 2,

            Water = 4,
            UI = 5,


            PartsList_Icons = 8,
            Atmosphere = 9,
            ScaledScenery = 10,
            UI_Dialog = 11,
            UI_Vectors = 12,
            UI_Mask = 13,
            Screens = 14,
            LocalScenery = 15,
            Unknown = 16,
            EVA = 17,
            SkySphere = 18,
            PhysicalObjects = 19,
            InternalSpace = 20,
            PartTriggers = 21,
            KerbalInstructors = 22,
            AeroFxIgnore = 23,
            MapFX = 24,
            UI_Additional = 25,
            WheelCollidersIgnore = 26,
            WheelColliders = 27,
            TerrainColliders = 28,
            DragRender = 29,
            SurfaceFx = 30,
            Vectors = 31
        }
    }
}

 

It works just fine as long as you don't have scatterer installed. Having a tiny whiff of cloud show up from Eve and the galaxy when in space isn't a huge thing: would just be nice if I could figure out why my camera is showing things it shouldn't.

Link to comment
Share on other sites

15 minutes ago, Electrocutor said:

 could figure out why my camera is showing things it shouldn't. 

  Are you talking about a camera you have added, or one for a reflection probe?  (I'm only seeing the probe in the code sample you posted)  (really though, it shouldn't make a difference, they should both respect culling masks)

Edit, to eliminate possible errors in your layer-masking function, try feeding it a manually specified mask.  Something like 

~1

Which should be all layers except layer zero.  Or try setting it to zero, which should disable -all- layers.

Edited by Shadowmage
Link to comment
Share on other sites

I setup a test to actually take a screenshot of the camera render: it is in fact correct.

Hammered away at some other things, and came to this: the problem is coming from here:

foreach (Shader oShader in aryShaders)
            {
                if (oShader.name == "SSTU/Skybox/Cubemap")
                {
                    oMaterial = new Material(oShader);
                    RenderSettings.skybox = oMaterial;
                    break;
                }
            }

It doesn't matter what I set the oMaterial.SetTexture("_Tex" to, the resulting skybox will always be a montage of ReflectionProbe data instead of the Cube that I set it to. It's like the skybox is being overriden by the reflectionProbe camera textures.

 

Here is the unity skybox shader:
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Skybox.shader

 

[Edit]
I'm calling it quits on this for now: way too much time and not getting anywhere. The root of the problem seems to be that using a skybox in KSP just flat-out doesn't work. No matter what material you set the skybox to, it always gets reset to some some reflectionprobe.

Edited by Electrocutor
Link to comment
Share on other sites

1 hour ago, Electrocutor said:

I'm calling it quits on this for now: way too much time and not getting anywhere. The root of the problem seems to be that using a skybox in KSP just flat-out doesn't work. No matter what material you set the skybox to, it always gets reset to some some reflectionprobe.

Sorry to hear that, but understandable.  Often its good to take a break and let your mind crunch on it.

There is probably a reason why I'm not currently using the skybox; I did experiment with it in the beginning, and ended up going a different route for some reason.  Could very well be I ran into something similar to what you are encountering.  To me it almost looked like the render-probe was re-using -my- RenderTexture as one of its blit targets;  perhaps there is some Unity method to make a render-texture 'uniquely owned' or persistent or somesuch?  I never felt like spending too much time investigating it either, as it was hard to determine if it was a quirk in KSP or something in Unity that was misconfigured.

The solution that I used was to 'build your own' skybox -- the skybox-sphere.  Use the built-in unity methods to spawn a sphere, make sure to remove the collider with destroyImmediate :(, assign it your material with your skybox shader and cubemap, and let the reflection probe capture that as the skybox.  Size the sphere such that it is at the extents of the reflection probe cameras far-clip, OR set its material render queue to geometry-1 and adjust your shader to disable z-writes.  The sphere gets stuck in a layer not captured by KSP cameras (I think I used wheelColliderIgnore/27), and the render probe is set to capture that layer (as well as anything else you need it to cap).

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