- Home /
Accessing uv without a texture
Hi, I'm in the middle of writing a few shaders, all based on vertex colors. In my water shader, I would like to be able to use the uv coords for some anmations, but I can't find a way to access them without first adding a texture to the shader
the below code works as intended, but I would like to just access uv without having to add the _MainTex property.
struct Input {
float4 color : COLOR;
half2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = IN.color.rgb;
o.Alpha = IN.color.a + sin(_Time.y * IN.uv_MainTex.x) * IN.uv_MainTex.y;
}
alternative ways of saving values other than color in the mesh is also very welcome :)
Thanks - Jannek
also, isn't it better for water shader to use the world position rather than uv?
no :/ uv : TEXCOORD0; just gives me empty uv coords. It gives me the warning Shader warning in 'Custom/TexturelessAlphe': Program 'vert_surf', not enough actual parameters for macro 'TRANSFOR$$anonymous$$_TEX'.
And I'm animating the water on a spehere, so worldPos gives weird results.
Answer by Bunny83 · Jan 20, 2014 at 03:29 AM
You wrote a Surface-shader. As the linked page explains, a Surface shader "is a code generation approach". It's a high-level language which does a lot stuff in the background. As far as i can tell you can't prevent the compiler from creating the _MainTex variable since the "Surface Shader compiler then figures out what inputs are needed".
You might be able to adapt the shader by looking at the compiled shader. If you don't need automatic lighting and all that stuff you probably should write a "normal" (vertex + fragment) shader on your own.
Thanks, I've looked a bit more at it, and implementing basic light in the vertex/fragment shaders looks doable. I don't need shadows for the water, but I need some light.