• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Corefanatic

[SOLVED] GLSL color mixing problem

6 posts in this topic

Hi guys,
I have the following problem. I've written a shader that takes in two textures and one float.

The first texture is my particle texture, the second is a gradient, which is 100x1.
Now I want to mix the color from a certain point from the gradient into the particle texture.

I've tested this in Render Monkey and it works, however it does not work in my render demo.The aim is to create a fireworks like effect.

Here are the sources for vert and frag shaders, where tex is particle texture, tex2 is the gradient and grad is a value from 0.0 to 1.0.

vert:

void main(void)
{
gl_Position = ftransform();
}




frag:

uniform sampler2D tex;
uniform sampler2D tex2;
uniform float grad;

void main(void)
{
vec4 color = texture2D(tex,gl_PointCoord);
vec4 color2 = texture2D(tex2, vec2(grad,1));
color.w *= (1.0 - grad); // Alpha, the particle becomes gradually more transparent
color.xyz *= color2.xyz; // multiplying the RGB values
gl_FragColor = color;
}





It seems like I'm not getting the color from tex2 aka the gradient.

[Edited by - Corefanatic on August 10, 2010 12:46:25 PM]
0

Share this post


Link to post
Share on other sites
Not sure what you mean, but here is my draw function code:


ShaderManager::Instance()->UseProg("testprog");

GLint uniformlocation = -1;

//particle texture
CHECKGL(uniformlocation = glGetUniformLocation(ShaderManager::Instance()->GetProg("testprog"), "tex"));

CHECKGL(glActiveTexture(GL_TEXTURE0));
CHECKGL(glBindTexture(GL_TEXTURE_2D,TextureManager::Instance()->Get("firework")));

CHECKGL(glUniform1i(uniformlocation,0));

//particle color gradient
CHECKGL(uniformlocation = glGetUniformLocation(ShaderManager::Instance()->GetProg("testprog"), "tex2"));

CHECKGL(glActiveTexture(GL_TEXTURE1));
CHECKGL(glBindTexture(GL_TEXTURE_2D,TextureManager::Instance()->Get("grad")));

CHECKGL(glUniform1i(uniformlocation,1));

//grad variable
CHECKGL(uniformlocation = glGetUniformLocation(ShaderManager::Instance()->GetProg("testprog"), "grad"));

CHECKGL(glUniform1f(uniformlocation,m_curretProgress));

CHECKGL(glEnableClientState(GL_VERTEX_ARRAY));

CHECKGL(glVertexPointer(3,GL_FLOAT,0,m_particles));

CHECKGL(glDrawArrays(GL_POINTS,0,m_particleCount));

CHECKGL(glDisableClientState(GL_VERTEX_ARRAY));



CHEKGL is opengl error checking macro.

Also, I've noticed that the first time I call glGetUniformLocation I get 1, the second time I get -1 and third I get 0, so there definitely is a problem with the second one.
0

Share this post


Link to post
Share on other sites
i had a similar problem the day before yesterday. i wanted to mix two texture maps, but it seems that only one of the two textures is loaded to the shader.

i then discovered the problem is that i created the uniform ids before linking the shade program.

like this:


uniform_texture1=glGetUniformLocation(program,"texture1");
uniform_texture2=glGetUniformLocation(program,"texture2");
linkShaderProgram();

I found out that both uniform_texture1 and uniform_texture2 were -1;

although the two uniform ids were wrong, one of the texture map did work.

so, i then reordered the three lines to:

linkShaderProgram();
uniform_texture1=glGetUniformLocation(program,"texture1");
uniform_texture2=glGetUniformLocation(program,"texture2");


everything worked.

this may not be your case, but you can check to see if you acquire for the uniform ids before linking the shader program.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by billconan
i had a similar problem the day before yesterday. i wanted to mix two texture maps, but it seems that only one of the two textures is loaded to the shader.

i then discovered the problem is that i created the uniform ids before linking the shade program.

like this:


uniform_texture1=glGetUniformLocation(program,"texture1");
uniform_texture2=glGetUniformLocation(program,"texture2");
linkShaderProgram();

I found out that both uniform_texture1 and uniform_texture2 were -1;

although the two uniform ids were wrong, one of the texture map did work.

so, i then reordered the three lines to:

linkShaderProgram();
uniform_texture1=glGetUniformLocation(program,"texture1");
uniform_texture2=glGetUniformLocation(program,"texture2");


everything worked.

this may not be your case, but you can check to see if you acquire for the uniform ids before linking the shader program.


if I put it before linking, I get -1 and -1, right after I get 1 and -1
0

Share this post


Link to post
Share on other sites
This may be your problem:
uniform sampler2D tex2;
didn't you state that one of the texture is a 1-dimensional texture. If so, why are you using a 2D texture lookup on a 1D texture?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by cgrant
This may be your problem:
uniform sampler2D tex2;
didn't you state that one of the texture is a 1-dimensional texture. If so, why are you using a 2D texture lookup on a 1D texture?


Well, I made the gradient a 128x128 texture and it works! Thx! What strikes me though is that I get the uniform before I bind the texture, therefore it should not return -1, but I guess there are more mysteries of OpenGL I have to uncover :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0