Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

GLSL Referencing a texture unit by variable

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 empirical2   Members   

567
Like
0Likes
Like

Posted 14 September 2013 - 05:48 AM

Basically before I abandon this I just want to check if what I am doing is even possible. I have tried googling but guess im not using the right keywords.

This is my shader

$VERTEX


varying vec2 vTexCoord;

varying vec4 vColor;

varying vec3 vertex_light_position;

varying vec3 vertex_normal;


void main(void)

{

 	vertex_normal = normalize(gl_NormalMatrix * gl_Normal);

	vertex_light_position = normalize(gl_LightSource[0].position.xyz);

	vTexCoord = gl_MultiTexCoord0;

	vColor=gl_Color;

	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


}




$FRAGMENT


uniform sampler2D Texture[8];


varying vec2 vTexCoord;

varying vec4 vColor;

varying vec3 vertex_light_position;

varying vec3 vertex_normal;


void main (void)  

{

	int i1=int(vColor.r*10);

	int i2=int(vColor.g*10);


	vec4 c1= texture2D(Texture[i1], vTexCoord).rgba;

	vec4 c2= texture2D(Texture[i2], vTexCoord).rgba;


	float diffuse_value = max(dot(vertex_normal, vertex_light_position), 0.0)*1.3;

	gl_FragColor=((c1*vColor.b)+(c2*(1.0-vColor.b)))*(diffuse_value+0.3);

	gl_FragColor.a=1.0;

}


What am I trying to do?

Each triangle in the VBO is a blend of two textures. But the two textures vary with each triangle. I am trying to specify which two textures to use in the R & G color components. With conditional branching instead it works as I want, but I wanted to make it more efficient and scale-able for the future.

When I try to use the above code it compiles OK, but fails to link. I am unable to retrieve a link log.
However, if I use constants (e.g i1=0; i2=1) it compiles and links. I assume because all that is optimized away.

Im new to shaders so Im hoping someone will cast an eye over and say either "You cant do that" in which case I can switch to branching or look further into texture arrays, or "you can do that" in which case Ill plod on with it.

Cheers.

#2 Brother Bob   Moderators   

10322
Like
2Likes
Like

Posted 14 September 2013 - 07:30 AM

Looks like you want texture arrays; clicky.



#3 empirical2   Members   

567
Like
0Likes
Like

Posted 14 September 2013 - 10:04 AM

Thanks very much that did the trick!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.