Jump to content

Newbie Shader Help


Kronos
 Share

Recommended Posts

Hi,

 

I have finally started looking at shaders. I have made this little thing as a start based on something I found on the internet. This should take four textures, multiply them with alpha textures(red) and then add the results together. The sort of thing one might use for terrain texturing for instance.

 

uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7;
varying vec4 texCoord;

void main()
{
  	vec4 alpha1   = texture2D( texture0, texCoord.xy);
  	vec4 alpha2   = texture2D( texture1, texCoord.xy);
  	vec4 alpha3   = texture2D( texture2, texCoord.xy);
  	vec4 alpha4   = texture2D( texture3, texCoord.xy);

vec4 tex1  = texture2D( texture4, texCoord.xy * 100.0 );	
vec4 tex2  = texture2D( texture5, texCoord.xy * 100.0 );
vec4 tex3  = texture2D( texture6, texCoord.xy * 100.0 );
vec4 tex4  = texture2D( texture7, texCoord.xy * 100.0 );

tex1 *= alpha1.r;
tex2 *= alpha2.r;
tex3 *= alpha3.r;
tex4 *= alpha4.r;

vec4 outcolor = tex1+tex2+tex3+tex4;


  gl_FragColor = outcolor;
}



 

 

My question is what vertex shader (if any) should I use with this. Any other tips would be welcome.

intel i5 2500k, ram 16gb, nvidia Geforce GTX570, asus xonar sound card. Windows 7 64 bit

Link to comment
Share on other sites

Hmm that didnt really work. Just get an overall greenish colour on the surface and nothing else. The best I have got so far is using sprite.vert. I can see the texture(s) using that but there is some weird light error going on. it may be unrelated to the shader but when the camera turns in certain direction everything goes white on the surface of the mesh. I am just using a large squashed cube for testing purposes at the moment.

intel i5 2500k, ram 16gb, nvidia Geforce GTX570, asus xonar sound card. Windows 7 64 bit

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...