mob-sakai / ParticleEffectForUGUI

Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The values passing from custom vertex stream to shader are not correct.

LenbaSun opened this issue · comments

Describe the bug
Hi, I uses UIParticle.cs to control my custom particle system on UI.
I write a custom shader which uses "custom vertex streams" to control like "uv flow" of texture by artists.
But I found it looks like only TEXCOORD0.xyzw will work well.
If I use TEXCOORD1, TEXCOORD2.... , the values fetched in shader not correct.
I have tried to use the same setting (with same particle system and same shader), make particle system not controlled by "UIParticle.cs", it will be correct.

I am not sure whether it's limitation for UIParticle.cs or maybe just I didn't setup correctly?

Like the image below, I use Custom1.xyzw (TEXCOORD0.zw/xy) as custom value.
It will use
custom1.xy => represent TEXCOORD0.zw in shader.
custom1.zw => represent TEXCOORD1.xy in shader.
This is how I get particle system input value in shader, in this case, TEXCOORD0.zw are correct, but TEXCOORD1.xy are always wrong....

I have no idea what happened....

image

To Reproduce
Steps to reproduce the behavior:

  1. Enable "Custom Vertex Stream" of renderer of particle system.
  2. Add Custom1.xyzw (TEXCOORD0.zw|xy)
  3. Implement custom shader and declare attribute like the "offset" below to fetch custom data input on particle system:
        struct Attributes
        {
            float4 positionOS   : POSITION;
            half4 texcoord     : TEXCOORD0;
            half2 offset : TEXCOORD1;
            half4 color        : COLOR;
        };

  1. Make texture "offset" in shader like :
Varyings Vertex(Attributes input)
{
	Varyings output = (Varyings)0;
	output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
	output.uv = input.texcoord.xy + input.offset;
	return output;
}

half4 Fragment(Varyings input) : SV_TARGET
{
	return SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv);
}

Expected behavior
If you feed "offset" value by "custom data" on particle system, the texture should be "offset".

Environment (please complete the following information):

  • Version 3.3.9
  • Platform: Standalone(Windows)
  • Unity version: 2020.3.14
  • Build options: Not built, editor can reproduce it.

@LenbaSun

In UI, TEXCOORD0.zw, TEXCOORD1.zw, TEXCOORD2.zw ... components will be discarded.
So you can use only TEXCOORD0.xy, TEXCOORD1.xy, TEXCOORD2.xy ... components for custom vertex stream.
TEXCOORD0.zw, TEXCOORD1.zw, TEXCOORD2.zw ... components must to be filled with "unnecessary" data (such as Size.xy.)

In addition, add the channels you want to use to Canvas.AdditionalShaderChannels.