Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LenbaSun opened this issue Jan 17, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working faq

Comments

@LenbaSun
Copy link

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 LenbaSun added the bug Something isn't working label Jan 17, 2022
@mob-sakai
Copy link
Owner

mob-sakai commented Feb 17, 2022

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

@mob-sakai mob-sakai pinned this issue May 15, 2022
@mob-sakai mob-sakai added the faq label Jun 9, 2022
@mob-sakai mob-sakai unpinned this issue Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working faq
Projects
None yet
Development

No branches or pull requests

2 participants