I needed a stable place to post this package, and I figured this might be interesting to somebody here. It was a fun little challenge for me. Maybe you have a great solution ready to go that accounts for all possible vertex positions? I could go further with it but I’m done for the time being.
Hello I got that error when importing your package
would u please share again? I am using Unity 3.5 yet
maybe this is the problem?
No, that’s not the problem, but I don’t know what is. Works fine for me.
Your problem is that you’re on Windows. You’ll have to force Unity into OpenGL mode.
Would you please explain more about what you have done in the shader or give me a reference to understand it
specifically the calculations you did
for exmple this statement
gl_FragColor = texture2D(_MainTex, shiftedPosition / width_height);
You’d need to look at AffineUVFix.cs, which feeds the necessary data to the shader. The key is that at every pixel, the texture coordinate is the a fraction of the way to both dimensions of the quad.
hmm, ya
I have written the Shader in Cg for windows users it could be helpful for some people
here it is
Shader "Custom/Affine UV fix Cg" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
pass{
CGPROGRAM
uniform sampler2D _MainTex;
#pragma vertex vert
#pragma fragment frag
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
float4 uv2 : TEXCOORD1;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
output.uv = input.texcoord;
output.uv2 = input.texcoord1 ;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.uv)/float2(input.uv2 ));
}
ENDCG // here ends the part in Cg
}
}
}
Why bother to use float4s for the UVs?
because I am very new to shaders, I change it to float2 and it worked
thank you
Would you please replay my pm sir,
thanks in advance
someone try to use this package on unity 5?
I tried to import it but does not work.
use it
Shader "Custom/Affine UV fix Cg" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
pass{
CGPROGRAM
uniform sampler2D _MainTex;
#pragma vertex vert
#pragma fragment frag
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
output.uv = input.texcoord;
output.uv2 = input.texcoord1 ;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.uv)/float2(input.uv2 ));
}
ENDCG // here ends the part in Cg
}
}
}