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

gl_NormalMatrix in GLSL

6 posts in this topic

Hi, In the FS, I am calculating the normals over the surface of a 3D cube dataset and then displaying the normals though gl_FragColor. As expected, 3 sides of the cube show up as red, blue and green, while the rest of the 3 are black. As I rotate the dataset, all the sides keep their colors and this is what should be happening. :) Now I want that the color of the normals to be updated while rotating. The side facing the camera is always blue. As I rotate the, values of the normals are updated. Problem: this is not happening. I multiplied the normals with the gl_NormalMatrix before displaying them through gl_FragColor, but I am getting garbage values. And the color of the sides of the cube are updated randomly. any advice on the problem regards
0

Share this post


Link to post
Share on other sites
You can try

vec3 mynormal=vec3(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));

since it will most likely give the same result. If your not using a non uniform scaling like glScalef(1.0, 2.0, 3.0) then you should be fine.
0

Share this post


Link to post
Share on other sites
if you want the side in front of camera to be always blue try this
gl_FragColor.rgb = gl_NormalMatrix * norm;
0

Share this post


Link to post
Share on other sites
thanks for the replies

I am using non-uniform scaling and
Quote:

vec3 mynormal=vec3(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));

shows the same results as before :(

Quote:

gl_FragColor.rgb = gl_NormalMatrix * norm;

This is what I am doing and does not work. I cant figure out why. program works correctly if i do:

gl_FragColor = vec4(norm,1.0);

as soon as I am doing:
norm = gl_NormalMatrix * norm;
gl_FragColor = vec4(norm,1.0);

it outputs garbage :(

0

Share this post


Link to post
Share on other sites
It's possible that those matrices are not being updated properly and that depends on your drivers.
Another thing to try is to generate that matrix yourself (gl_NormalMatrix is just the inverse transpose of the modelview) and upload it as a uniform in your shader.

Also, have you tried gl_NormalMatrix * norm; in your vertex shader? Does it work from there?
0

Share this post


Link to post
Share on other sites
I cannot try the gl_NormalMatrix in the vertex shader as I am doing volume rendering. Normals are calculated in the fragment shader and can be used there.

I will try to generate the matrix myself now.

hope that works :)
0

Share this post


Link to post
Share on other sites
Good news: its solved
bad one, i dont know why its solved

I tried to take the inverse transpose of the model view matrix in the C code and pass it on to the shader using a uniform variable and there was no change in results. I was getting the same image.

I then tried to multiply the normal with gl_ModelViewProjectionMatrix, just to see what happens, and it works :)

So I finalized it by multiplying the normal with the gl_ModelViewProjectionMatrixInverseTranspose and it works as it should.

but i cannot get why do I have to multiply it with gl_ModelViewProjectionMatrixInverseTranspose, as I think I should have got results by multiplying it with either gl_NormalMatrix or gl_ModelViewMatrixInverseTranspose.

any ideas on it

regards
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