Forum

Scale point sprite texture from center, HLSL

Hi guys,

i´m scaling the quads in a point sprite shader, but they look scaled from the corner not from center.

Out.TexCdCol = mul(TexCdCol, tTexCol*Scale);

i´ve tried also to use this in the technique, and it allows to change the point uniform scale, but it kills the previous transformations (rotation).

FillMode = POINT;
PointScaleEnable = true;
PointSpriteEnable = true;

I think i have to scale the texture from (0.5,0.5) not from (0.0,0.0), but i don´t know how to do it.

Any idea?

Thanks in advance,

Ari.

scale from the center would be

TexCd=(TexCd-0.5)*Scale+0.5;

Hi Unc,
thanks for the tip, but it seems that i´m doing something wrong because it still scales from the corner.

My VertexShader looks like that.

// --------------------------------------------------------------------------------------------------
// VERTEXSHADERS
// --------------------------------------------------------------------------------------------------

vs2ps VS(
    float4 Pos : POSITION ,
    float4 TexCd : TEXCOORD0 ,
    float4 TexCdCol : TEXCOORD1
  
                                )
{
    //inititalize all fields of output struct with 0
    vs2ps Out = (vs2ps)0;

    //get the position info from the Position-velocity texture:
    float2 particlePosition = tex2Dlod(SampData, TexCd).rg;
    float Accel  =  abs[tex2Dlod(SampData, TexCd).ab)+(tex2Dlod(SampData, TexCd).ba](https://vvvv.org/documentation/tex2Dlod(SampData,-TexCd).ab)+(tex2Dlod(SampData,-TexCd).ba)*10*Gamma;
	//float Accel2 =  min(1/MinSize, [ max (1,(1/abs(((tex2Dlod(SampData, TexCd).ab)+(tex2Dlod(SampData, TexCd).ba](https://vvvv.org/documentation/max-(1,(1/abs(((tex2Dlod(SampData,-TexCd).ab)+(tex2Dlod(SampData,-TexCd).ba)*20*Gamma))))));
	float Accel2 =  min(1/MinSize, [ max (1,(1/abs(((tex2Dlod(SampData, TexCd).ab)+(tex2Dlod(SampData, TexCd).ba](https://vvvv.org/documentation/max-(1,(1/abs(((tex2Dlod(SampData,-TexCd).ab)+(tex2Dlod(SampData,-TexCd).ba)*20*Gamma))))));
	float2 Accel3 = (normalize(tex2Dlod(SampData, TexCd).ba));
	float Angle  = atan2 [Accel3.x),(-Accel3.y](https://vvvv.org/documentation/Accel3.x),(-Accel3.y)/TwoPi;
		
	if(Accel >= MaxColor)
        { Accel= MaxColor;}
        else 
        { Accel= Accel; }
   
	 Pos = mul(Pos, tW);
     
     //now apply the position taken from the texture
 
     Pos.xy = rotate( (Pos.xyz), 0, 0, (Angle))+particlePosition.xy;   //rotate1.z does the roll
     Pos = mul(Pos, tPost);
     Out.Pos = mul(Pos, (tVP));
     
     TexCdCol= (TexCdCol-0.5)*Accel2+0.5; //<--------------it should work  ??
     Out.TexCdCol = mul[TexCdCol), (tTexCol](https://vvvv.org/documentation/TexCdCol),-(tTexCol);

     Out.Vcol = (tex2Dlod(SampColPP1, TexCd)*(1-MaxColor+Accel)+ tex2Dlod(SampColPP2, TexCd)*(MaxColor-Accel));
	
	return Out;
    }

// --------------------------------------------------------------------------------------------------
// PIXELSHADERS:
// --------------------------------------------------------------------------------------------------

float4 PS(vs2ps In): COLOR
{
    return In.Vcol * tex2D(SampCol, In.TexCdCol)*Color;
 }

Any idea?

Thanks

Ari.

if it is float4, i guess you only need to scale first two components

TexCdCol.xy=(TexCdCol.xy-0.5)*Accel2+0.5;

and then probably, if you want to transform them with the center in 0.5 (with your matrix tTexCol), should probably do this

Out.TexCdCol = mul(float4(TexCdCol.xy-.5,TexCdCol.zw), tTexCol)+float4(0.5,0.5,0,0);

Thanks a lot unc,

very appreciated, it works perfect now!
Ari,