• 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
vivendi

color per pixel

7 posts in this topic

This should be pretty basic stuff, but i just can't get my head around it.

Basically what i want to do is check wether a pixel is facing the camera or not. If the pixel is directly facing the camera, then i want to color it completely black. When it's 90 degrees rotated, then it should have full transparency.

I guess i have all the needed stuff in my vertex shader:

[code]
varying vec3 Normal;
varying vec3 EyeDir;
varying vec4 EyePos;

void main(void)
{
gl_Position = ftransform();
Normal = normalize(gl_NormalMatrix * gl_Normal);
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
EyeDir = pos.xyz;
EyePos = gl_ModelViewProjectionMatrix * gl_Vertex;
}
[/code]

In my fragment shader i have two textures. One is just some random image and the other is completely black. I guess i have to "mix" them some how, depending on the position of the pixel. But i have no idea how to calculate that...

[size=4]This is something i've tried, but didn't worked out as planned.[/size]
[code]
vec4 RefractionColor = texture2D(RefractionMap, index);

// Apply the black material
vec4 blackMat = texture2D(Black, gl_TexCoord[0].st);
float shade = dot(normalize(EyeDir), normalize(Normal));

// Blend the textures
RefractionColor = mix(blackMat, RefractionColor, shade);
gl_FragColor = RefractionColor;
[/code]

[size=4]Anyone any idea how to do this..??[/size]
0

Share this post


Link to post
Share on other sites
[quote]
Basically what i want to do is check wether a pixel is facing the camera or not. If the pixel is directly facing the camera, then i want to color it completely black. When it's 90 degrees rotated, then it should have full transparency.
[/quote]
If it's 45 degrees rotated is it should contain 50% - black and 50% - transparent? If yes:
[code]
float shade = max(dot(normalize(EyeDir), normalize(Normal)),0.0); // fixing 'solve' because dot returns [-1.0..1.0] but mix expects result in range [0.0...1.0]
[/code]
Otherwise:
[code]
float shade = float(dot(normalize(EyeDir), normalize(Normal))>0.0);
[/code]

Is this what you want?

Best wishes, FXACE.
1

Share this post


Link to post
Share on other sites
[quote name='FXACE' timestamp='1327853293' post='4907352']
If it's 45 degrees rotated is it should contain 50% - black and 50% - transparent? If yes:
[code]
float shade = max(dot(normalize(EyeDir), normalize(Normal)),0.0); // fixing 'solve' because dot returns [-1.0..1.0] but mix expects result in range [0.0...1.0]
[/code]

Is this what you want?

Best wishes, FXACE.
[/quote]

Yes, that's exactly what i mean. When it's 45 degrees then the color should be 50% transparent.

I tried your example, but it still paints my entire sphere black. I have no compile errors though. So the shader is fine. The calculation is somehow not correct.

Any idea what the problem could be?
0

Share this post


Link to post
Share on other sites
It's working now. I had to change the EyeDir with EyePos.

Just one other thing that i'm struggling with. Now the gradient goes from all black (0 degrees; a pixel which faces the camera), to 90 degrees, fully transparent (a pixel that isn't facing the camera). Like i wanted.

What if i want it to go from 0 degrees (fully black) to 30 degrees (100% transparent) instead of 90 degrees..?

I've tried to do some additions, subtractions on the dot product. But they didn't gave the desired result.

Anyone any idea?
0

Share this post


Link to post
Share on other sites
shade = max((dp - 0.866025) / (1.0 - 0.866025),0.0); where: "dp" is a dot production of EyePos to Normal; 0.866025 - cos(30 <your degrees> * Pi / 180).

Best wishes, FXACE.
1

Share this post


Link to post
Share on other sites
Hi, thanks alot for your help! It seems to be working fine when i use the following:

[code]
float dp = (max(dot(normalize(EyePos), normalize(Normal)), 0.0) + MixRatio); //MixRatio = for strength

float shade = max((dp - 0.866025) / (1.0 - 0.866025),0.0);
//float shade = dp - cos(30 * 3.14159 * 180);
[/code]

Although i wasn't sure what the 2nd formula you posted was for? It didn't seem to give the desired effect. And i'm also not sure how you got to the number '866025'. It looks like that when i change that number, that it also changes the range of the falloff. Kinda like i'm doing with the MixRatio variable when i caluclate the 'dp' variable.
0

Share this post


Link to post
Share on other sites
2nd formula from my first post?... Never mind. (It was variant "did you want to make it blended or not")

Hmmm, I would try to rewrite my previous post to make it more clear...

1. Dot product calculation looks like this:
[code]
float dp = dot(normalize(EyePos),normalize(Normal));
[/code]

2. Compute value for 'gradient' (from post #4, 0 degrees - black and 30 degrees - transparent):
[code]
float cMaxDegreesOfFacing = cos(30 * Pi / 180); // which equals to (0.866025...) <<<!
[/code]

0.866025..... was returned from calculation I made in 'Microsoft Calculator' (calc.exe) -> cos of 30 degrees. I don't think that was incorrect.


3.Finally compute 'shade':
[code]
float shade = max((dp - cMaxDegreesOfFacing) / (1.0 - cMaxDegreesOfFacing),0.0);
[/code]

That's all what I meaned...

Best wishes, FXACE.
1

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