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

Decal Rotation #119

Open
Rafacasari opened this issue Sep 20, 2023 · 4 comments · May be fixed by #182
Open

Decal Rotation #119

Rafacasari opened this issue Sep 20, 2023 · 4 comments · May be fixed by #182
Labels
bug Something isn't working

Comments

@Rafacasari
Copy link

Rafacasari commented Sep 20, 2023

Currently, if I try to rotate the decal that I've positioned, it will totally move and lose the position that I've already set.

lilToon
https://github.com/lilxyzw/lilToon/assets/32463720/e5ef559a-8f7d-47df-adea-4b9ac3518f4c

Poiyomi (for example)
https://github.com/lilxyzw/lilToon/assets/32463720/71953808-d3c3-4538-aac8-208de0e80e62

Seems that the decal isn't rotating in its own axis

@Rafacasari
Copy link
Author

Rafacasari commented Sep 27, 2023

I've tried to fix it by myself, but I've never touched shader coding and my brain was on fire trying to understand math. But I was able to almost fix it by changing the end of lilCalcDecalUV function

float2 lilCalcDecalUV(float2 uv, float4 uv_ST, float angle, bool isLeftOnly, bool isRightOnly, bool shouldCopy, bool shouldFlipMirror, bool shouldFlipCopy, bool isRightHand)
{
    float2 outUV = uv;

    // Copy
    if(shouldCopy) outUV.x = abs(outUV.x - 0.5) + 0.5;

    // Scale & Offset
    outUV = outUV * uv_ST.xy + uv_ST.zw;

    // Flip
    if(shouldFlipCopy && uv.x<0.5) outUV.x = 1.0 - outUV.x;
    if(shouldFlipMirror && isRightHand) outUV.x = 1.0 - outUV.x;

    // Hide
    if(isLeftOnly && isRightHand) outUV.x = -1.0;
    if(isRightOnly && !isRightHand) outUV.x = -1.0;

    // Rotate
    
    // FROM THIS
    //outUV = (outUV - uv_ST.zw) / uv_ST.xy;
    //outUV = lilRotateUV(outUV, angle);
    //outUV = outUV * uv_ST.xy + uv_ST.zw;

    // TO THIS
    float2 center = (uv_ST.zw / 2) / uv_ST.xy;
    outUV = lilRotateUV(outUV - center, angle) + center;
        
    return outUV;
}

It's kinda a hacky way, but I think with some polishment it will be totally fixed.

@lilxyzw
Copy link
Owner

lilxyzw commented Oct 3, 2023

Thank you! I will also think about the calculation method.

@lilxyzw lilxyzw added the bug Something isn't working label Oct 3, 2023
@Rafacasari Rafacasari reopened this Apr 24, 2024
@Rafacasari Rafacasari linked a pull request Apr 24, 2024 that will close this issue
@Rafacasari
Copy link
Author

Rafacasari commented Apr 24, 2024

@lilxyzw
Updating the center variable to this seems to completely fix my issue, feel free to give some tests before merging. (full code in PR #182)

float2 center = (uv_ST.zw / 2) / (uv_ST.xy * uv_ST.zw);

@Rafacasari
Copy link
Author

@lilxyzw Any news about this? I'm waiting for the implementation of this fix to release a thing I made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants