Am I completely off base here, or shouldn’t I be able to move a texture (basing this off of the Unshaded material/vert/frag) by updating texCoord1?
If I slowly increase the x or y of the vec2 from 0 to 1, shouldn’t it move the texture?
Reaaaaallly sorry for the stupid question.
Yes, it should. But if it isn’t then we haven’t been given enough information as to why it isn’t.
So, I updated the Unshaded.vert with the following (material def file allows for setting Offset)
[java]
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
#define NEED_TEXCOORD1
#endif
#ifdef NEED_TEXCOORD1
attribute vec2 inTexCoord;
varying vec2 texCoord1;
varying vec2 Offset;
#endif
#ifdef SEPARATE_TEXCOORD
attribute vec2 inTexCoord2;
varying vec2 texCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
attribute vec4 inColor;
varying vec4 vertColor;
#endif
void main(){
#ifdef NEED_TEXCOORD1
texCoord1 = vec2((inTexCoord[0]+Offset[0]),(inTexCoord[1]+Offset[1]));
#endif
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
vertColor = inColor;
#endif
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}
[/java]
So the loop updates Offset from value 0 to 1 in increments of .01f
The texture moves… only when I rotate the camera along the Zaxis (looking up and down). I know it has something to do with the last line (gl_Position). I am assuming I need to swap out WorldView for something Local to the rendered object?
Any help would be appreciated!
Offset is not a uniform it’s a varying… so it probably contains random garbage that changes as you look around.
I’m surprised it compiled at all.
Did you want it to be a uniform or a vertex attribute?
Also note that you can just use g_Time if you set that up right in the j3md.
I see now. Let me try setting it to a uniform.
Also, if you have a uniform named “Offset” then it will be “m_Offset” in the shaders.
This worked like a charm!
[java]
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;
#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
#define NEED_TEXCOORD1
#endif
#ifdef NEED_TEXCOORD1
attribute vec2 inTexCoord;
varying vec2 texCoord1;
uniform vec2 m_Offset;
#endif
#ifdef SEPARATE_TEXCOORD
attribute vec2 inTexCoord2;
varying vec2 texCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
attribute vec4 inColor;
varying vec4 vertColor;
#endif
void main(){
#ifdef NEED_TEXCOORD1
texCoord1 = vec2((inTexCoord[0]+m_Offset[0]),(inTexCoord[1]+m_Offset[1]));
#endif
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
#ifdef HAS_VERTEXCOLOR
vertColor = inColor;
#endif
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}
[/java]
Now to figure out how to set up the g_Time in the material def file. Although, I would love to be able to vary the speed, so I am assuming I’ll need to define this as well.
Thanks a ton for the help!
Yeah, but speed won’t need to be set as often as offset, probably.
Under WorldParameters… put Time
Then you will have access to g_Time in your shader.