I'm re-writing my Unity game in Raylib and are trying to recreate a path/road-shader I made with Shader Graph.
The first picture is how it looks in Unity, with faded/blurred edges. The path is a 2D spline-mesh created as you can see in the second picture. The third image is a spline-mesh created the same way in Raylib.
Does anyone have an idea how to get faded edges with GLSL-code?
The Shader Graph looks like this:
I'm new to GLSL and have been at this for days. I would really appreciate any help!
Edit:
I also tried to manually convert the shader. Here is an example where I tried to convert the Shader Graph.
Vert:
in vec3 vertexPosition;
in vec2 vertexTexCoord;
uniform mat4 mvp;
uniform mat4 matModel;
out vec2 fragTexCoord;
out vec3 fragPosition;
void main() {
fragTexCoord = vertexTexCoord;
fragPosition = vertexPosition;
gl_Position = mvp * vec4(vertexPosition,1.0);
}
Frag:
in vec2 fragTexCoord;
in vec3 fragPosition;
uniform sampler2D texture0;
uniform float width;
uniform float blur;
void main()
{
vec4 texColor = texture2D(texture0, fragPosition.xy);
vec2 halfVec = vec2(0.5, 0.5);
float dist = distance(fragTexCoord, halfVec);
float smoothstep1 = smoothstep(width,blur,dist);
gl_FragColor = vec4(texColor.xyz, smoothstep1);
}
The result is this:
Or this, depending on width- and blur-parameters
Edit 2:
I translated the Shader Graph-code node by node and the result was basically what I already wrote i GLSL. The part I can't figure out is this Shader Graph-generated code.
(I simplified it from 5 to 2 lines and shortened the variable names)
UnityTexture2D unityTex = UnityBuildTexture2DStructNoScale(_Texture2D);
float4 texColor = SAMPLE_TEXTURE2D(unityTex.tex,UnityBuildSamplerStateStruct(SamplerState_Linear_Repeat).samplerstate, unityTex.GetTransformedUV((IN.WorldSpacePosition.xy) / _Size));
Does anyone know what GetTransformedUV does? I cant find any information on UnityTexture2D by googling.