User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Offscreen Texture Alpha

06 Apr 2019, 16:06

I added Blend Off, which I believe was already on as a default setting.
Shader "Noesis/Alpha Blended Premultiply" {
	Properties{
		_MainTex("RenderTexture", 2D) = "black" {}
	}

		Category{
			Blend Off
			Cull Off 
		    Lighting Off 
		    ZWrite Off 
		    Fog { Mode Off }

			SubShader {
				Pass {

					CGPROGRAM
					#pragma vertex vert
					#pragma fragment frag
					#include "UnityCG.cginc"

					sampler2D _MainTex;

					struct appdata_t {
						float4 vertex : POSITION;
						float2 texcoord : TEXCOORD0;
					};

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

					float4 _MainTex_ST;

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

					fixed4 frag(v2f i) : SV_Target
					{
						fixed4 c = tex2D(_MainTex, i.texcoord);
						c.r *= c.a;
						c.g *= c.a;
						c.b *= c.a;
				
						return c;
					}
					ENDCG
				}
			}
		}
}
Re: doing the operation during object vs render target camera rendering... The reason I am applying this shader to the output texture instead of the rendered object is so that I am not required to change the many shaders used by different game objects! I'm honestly at a loss for how to make this work with Noesis.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Offscreen Texture Alpha

08 Apr 2019, 17:49

Could you please capture and attach the generated image with that shader? I want to analyze the RGBA values.
 
User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Offscreen Texture Alpha

09 Apr 2019, 22:02

Yes. What texture format should the bytes be written as? (argb32)?
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Offscreen Texture Alpha

10 Apr 2019, 20:22

If possible, exported in a known format (png). If not possible, any raw format is valid, I will do the conversion. Thanks
 
User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Offscreen Texture Alpha

21 May 2019, 22:20

OK, I have an update around this. This was a case of user error. I had some rogue shaders that were setting alpha to 1 for certain things.. The shader shared above is useful if you want it to make/remove all alpha, i.e. add ColorMask RGB, and have it remove alpha. Otherwise, a standard PBR shader seems to work well with Unity if the texture format is ARGB32.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Offscreen Texture Alpha (User Error)

25 May 2019, 10:13

Great! Do you have a screenshot of the final result?
 
User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Offscreen Texture Alpha (User Error)

03 Jun 2019, 06:50

Sure! Here's an example. The blended alpha of the planet atmosphere inline with the Noesis View/XAML was my goal. Very happy with the result!

Image
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Offscreen Texture Alpha (User Error)

03 Jun 2019, 12:15

Awesome! Glad to know you solved it.
 
User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Offscreen Texture Alpha (User Error)

15 Oct 2019, 23:47

Hi jstantos!

Hoping you are well. I just wanted to run this by you. The difference in color shown, where the render target texture (bottom left) is darker than what is shown in a Noesis rectangle (center - brighter) .... is that likely a premultiply alpha issue? I thought I had worked through this since you can clearly see that alpha is cut-out.

Image

If I turn off post-processing it remains bright -- so I think I can rule it out.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Offscreen Texture Alpha (User Error)

16 Oct 2019, 08:54

That's seem to be a sRGB thing, I see the texture format is R8G8B8A8_SRGB. Are you using linear rendering in your project?

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 87 guests