I’m putting this in the shader category because the more important of the two problems fits it. Basically I’m encountering two strange behaviors:
-
When I move my mouse over the game view, the cursor turns to a larger rectangle with garbled pixels (probably rendering some random data as a graphic).
-
When I use tex2Dlod in the vertex function of a shader, the values I get aren’t the expected ones. If an RGBA value is exactly 1 or 0, it is the correct value. For anything in between I get a smaller value than it is supposed to.
I reproduced the issue in a simplified shader for demonstration purposes. But when I use this shader in a new project, it works as intended. Also, the garbled mouse cursor appears in three different Unity Editor versions, but only in this one project. Not in the new one I made to test the demo shader.
The code for the demo shader:
Shader "Debug/WrongSampleData"
{
Properties
{
_MainTex("MainTex (RGBA)", 2D) = "black" {}
}
SubShader
{
CGPROGRAM
#pragma surface surf Standard vertex:vert
#include "UnityCG.cginc"
sampler _MainTex;
struct Input
{
float4 color;
};
void vert(inout appdata_full v, out Input o) {
float4 data = tex2Dlod(_MainTex, float4(0, 0, 0, 0));
if (data.x > 0.85)
o.color = float4(1,0,0,1);
else
o.color = float4(0, 0, 1, 1);
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
o.Albedo = IN.color.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
I use a texture with one pixel that has the color rgba(0.9, 0,0.9,1). So it should render as red, because 0.9 is bigger than 0.85. But it gives me blue, which means the value coming back from tex2Dlod is equal or smaller than 0.85.
When I use another texture that has rgba(1, 0, 1, 1), it renders red as expected:
In my completely fresh and new project, when I copy over this shader and the textures, both render red as expected:
So my question is, what could cause these bugs in my project? What could change the mouse cursor? What could affect the tex2Dlod function (which I assume is a native function)?
The textures are attached to this post.