• 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

color stripes based on time

1 post in this topic

In a class I am taking, we had to create an object, make it rotate and scale (done) and have rainbow stripes moving upwards towards the Y direction as it is scaling and rotating. I was unable to get the last part done. Still passed though :), but I don't believe in "good enough" so even though it's aready graded, I want to finish it and make sure that I am able to do it again if I ever need to.

So I'm using FX Composer, and I set up the pixer shader to return the world location, which I know changes the color based on the location. But what I WANT to happen is create a stripe pattern full of colors of the rainbow, and they'll be moving upwards as time goes by. All I know is that it'll involve sine, cosine, and tangent. But I have absolutely no clue how that would work or why. I haven't done trig or calc related stuff in years so if someone could also explain how manipulating the sin,cos,and tan waves works also that would be awesome.

Share this post

Link to post
Share on other sites

If you want a more or less correct rainbow, you could do the following:
(Though it’s probably a little overkill. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img])

In the vertex shader, add to the y-coordinate an effect parameter “time” that you increment each frame and pass the sum on to the pixel shader. The “time” parameter lets your rainbow move. By using frac() (gives the fractional part) you can turn the value into something periodic in [0..1]. Perhaps scale the value before using frac, to adjust “how many” rainbows you see, i.e. how often it repeats.

Now, the overkill part:
If you assume the scalar value being passed in from the vertex shader to be a wave length, you can use the CIE response curves to retrieve the activation of the RGB receptors. This way you get a true rainbow. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Modelling the CIE curves with Gaussian mixture models gives eventually:

[CODE]// CIE response curves using Gaussians fitting
const vec4 CIEX0 = vec4(0.26714125, 0.173056848724526, -0.0517890668554628, 0.369341509681465);
const vec4 CIEX1 = vec4(0.0, 0.510852785928701, 0.636521548441552, -0.324530476950362);
const vec4 CIEX2 = vec4(1.0622, 0.547302197035226, 0.0899535691555178, 1.10399973088081);

const vec4 CIEY0 = vec4(0.2671425, 0.86798560108836, 0.150307921271593, -0.354744089805774);
const vec4 CIEY1 = vec4(0, 0.10539332389757, 0.168752691961971, -0.289650515359526);
const vec4 CIEY2 = vec4(1.0002, 0.445956775505726, 0.0920541376951253, 0.814888040084084);

const vec4 CIEZ0 = vec4(0.26714375, 0.174251742295476, -0.0569218355789753, 1.72408897831517);
const vec4 CIEZ1 = vec4(0.0, 0.0542544622978704, 0.0457454482464726, -0.442679263574661);
const vec4 CIEZ2 = vec4(1.7826, 0.711309229610584, 0.285040831286585, -0.407629686738774);

float Gaussian(const float x0, const float s, const float w, const float x)
return w * exp( -(x - x0) * (x - x0) / (2.0 * s * s + 1.0e-20) );

float GaussianMixture(const float lambda, const vec4 Data0, const vec4 Data1, const vec4 Data2)
float t = (lambda - 0.380) / (0.780 - 0.380);
float g0 = Gaussian(Data0.y, Data0.z, Data0.w, t);
float g1 = Gaussian(Data1.y, Data1.z, Data1.w, t);
float g2 = Gaussian(Data2.y, Data2.z, Data2.w, t);

return min(max(g0 + g1 + g2 + Data0.x, Data1.x), Data2.x);

vec3 Spectrum2RGB(const float lambda)
float x = GaussianMixture(lambda, CIEX0, CIEX1, CIEX2);
float y = GaussianMixture(lambda, CIEY0, CIEY1, CIEY2);
float z = GaussianMixture(lambda, CIEZ0, CIEZ1, CIEZ2);

// E to D65
// 0.26713798 is for mapping spectrum 1.0 into rgb (1.0, 1.0, 1.0)
x = x * 0.9504700 / 0.26713798;
y = y * 1.0000000 / 0.26713798;
z = z * 1.0888300 / 0.26713798;

// sRGB (D65)
vec3 rgb;
rgb.r = (x * ( 3.2404542) + y * (-1.5371385) + z * (-0.4985314));
rgb.g = (x * (-0.9692660) + y * ( 1.8760108) + z * ( 0.0415560));
rgb.b = (x * ( 0.0556434) + y * (-0.2040259) + z * ( 1.0572252));

return rgb;

Spectrum2RGB converts from wave length to color. (The GLSL code is from Toshiya Hachisuka’s GPU SPPM implementation: “[url="http://cs.au.dk/~toshiya/"]Parallel Progressive Photon Mapping on GPUs[/url]”.)

You could as well just use the wavelength variable and apply some sin/cos stuff and use different phase shifts for the RGB components. This is probably more what was intended by your teachers. ;)
Something like:
color.r = sin( input.posY_plus_time );
color.g = sin( input.posY_plus_time + 2/3*Pi);
color.b = sin( input.posY_plus_time + 4/3*Pi);

Have fun with that. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Best regards!

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