вращать часть текстуры вокруг оси - PullRequest
0 голосов
/ 02 ноября 2019

Я хотел бы «замаскировать» область выборочной текстуры и вращать эту часть круговыми движениями. маска также перемещается по ультрафиолетовой карте.

https://ibb.co/JshCDFZ

плохо знакомы с этим .. Я знаю, что где-то пропускаю шаг ... любые советы приветствуются!

float4 PS_circleSampler(psInput In): SV_Target
{
    float2 uv = In.TexCd.xy;
    float4 col;

    float s = sin(phase);
    float c = cos(phase);
    float2x2 rotationMatrix = float2x2(c, -s, 
                                      s, c);    

    float4 colOriginal = texA.Sample(linearSampler, uv);
    float4 colRotated = texA.Sample(linearSampler,  mul( pos - uv, rotationMatrix ));       

    float inCircle = 0.5 - distance (In.TexCd.xy, pos);

    colOriginal *= 1- ceil(inCircle);
    colRotated *= ceil(inCircle) ;


    return colOriginal + colRotated;
}


1 Ответ

0 голосов
/ 03 ноября 2019

сам нашел решение ..

вращать в вершинном шейдере проще, потому что он использует систему координат -1 к 1. сначала переводим уф в центр, потом вращаемся, потом переводим обратно в исходное положение


float2 pos;
float radius;
float phase;

Texture2D texA <string uiname="Texture A";>;
Texture2D texB <string uiname="Texture B";>;

cbuffer cbPerDraw : register( b0 )
{
    float4x4 tVP : LAYERVIEWPROJECTION; 
};

cbuffer cbPerObj : register( b1 )
{
    float4x4 tW : WORLD;
};

SamplerState linearSampler
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};

struct vsInput
{
    float4 PosO : POSITION;
    float2 TexCd : TEXCOORD0;

};

struct psInput
{
    float4 PosWVP: SV_Position;
    float2 TexCd: TEXCOORD0;
    float2 TexCdRotated: TEXCOORD1;
};

psInput VS(vsInput In)
{   
    psInput output;

    float2 uv = In.TexCd;
    float2 center = pos;


    float s = sin(phase);
    float c = cos(phase);       

    float2x2 rotationMatrix = float2x2(c, -s,
                                        s, c);

    float2 uv2 = uv - center; // translate into center
    uv2 = mul(uv2, rotationMatrix);    // rotate the space    
    uv2 += center; // move it back to the original place


    output.TexCdRotated = uv2;

    output.PosWVP = In.PosO;
    output.TexCd = In.TexCd;


    return output;
}


float4 PS_circleSampler(psInput In): SV_Target
{
    float2 uv = In.TexCd.xy;
    float2 uvRot = In.TexCdRotated.xy;      

    float4 colOriginal = texA.Sample(linearSampler, uv);
    float4 colRotated = texA.Sample(linearSampler,  uvRot );


    float inCircle = radius - distance (In.TexCd.xy, pos);

    colOriginal *= 1- ceil(inCircle);
    colRotated *= ceil(inCircle) ;

    return colOriginal + colRotated;
}


technique10 circleSampler
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetPixelShader( CompileShader( ps_4_0, PS_circleSampler() ) );
    }
}


``
...