Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

219 Neutral

About handoman

  • Rank
  1. handoman

    GLSL 1.20 Lighting Problem

    okay so I just downloaded the source files from http://www.opengl-tutorial.org and built the projects. I ran the tut 8 project and it seems to be working perfect. So, i guess i will be studying the code to see where i went wrong.
  2. So, I've been following the tuts from http://www.opengl-tutorial.org, (using the opengl 2.1 versions) and came across a problem in Tutorial 8: Basic Shading. Basically, my shading comes out calculated wrong(noticable around the edges of the triangle faces). After hours of comparing the tut code with my code, i could find anythign wrong. I finally jus copied and pasted everything from the tut, but nothing help. I am pretty sure the problem with the shaders, here is the code: #version 120 // Interpolated values from the vertex shaders varying vec2 UV; varying vec3 Position_worldspace; varying vec3 Normal_cameraspace; varying vec3 EyeDirection_cameraspace; varying vec3 LightDirection_cameraspace; // Values that stay constant for the whole mesh. uniform sampler2D myTextureSampler; uniform mat4 MV; uniform vec3 LightPosition_worldspace; void main(){ // Light emission properties // You probably want to put them as uniforms vec3 LightColor = vec3(1,1,1); float LightPower = 30.0; // Material properties vec3 MaterialDiffuseColor = texture2D(myTextureSampler,UV).rgb; vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor; vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3); // Distance to the light float distance2 = length( LightPosition_worldspace - Position_worldspace ); // Normal of the computed fragment, in camera space vec3 n = normalize( Normal_cameraspace ); // Direction of the light (from the fragment to the light) vec3 l = normalize( LightDirection_cameraspace ); // Cosine of the angle between the normal and the light direction, // clamped above 0 // - light is at the vertical of the triangle -> 1 // - light is perpendicular to the triangle -> 0 // - light is behind the triangle -> 0 float cosTheta = clamp( dot( n,l ), 0.0,1.0); // Eye vector (towards the camera) vec3 E = normalize(EyeDirection_cameraspace); // Direction in which the triangle reflects the light vec3 R = reflect(-l,n); // Cosine of the angle between the Eye vector and the Reflect vector, // clamped to 0 // - Looking into the reflection -> 1 // - Looking elsewhere -> < 1 float cosAlpha = clamp( dot( E,R ), 0,1 ); gl_FragColor.rgb = // Diffuse : "color" of the object MaterialDiffuseColor* LightColor * LightPower /(distance2*distance2) ; }   #version 120 // Input vertex data, different for all executions of this shader. attribute vec3 vertexPosition_modelspace; attribute vec2 vertexUV; attribute vec3 vertexNormal_modelspace; // Output data ; will be interpolated for each fragment. varying vec2 UV; varying vec3 Position_worldspace; varying vec3 Normal_cameraspace; varying vec3 EyeDirection_cameraspace; varying vec3 LightDirection_cameraspace; // Values that stay constant for the whole mesh. uniform mat4 MVP; uniform mat4 V; uniform mat4 M; uniform vec3 LightPosition_worldspace; uniform int vertex_image_type; void main(){ // Output position of the vertex, in clip space : MVP * position gl_Position = MVP * vec4(vertexPosition_modelspace,1); // Position of the vertex, in worldspace : M * position Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz; // Vector that goes from the vertex to the camera, in camera space. // In camera space, the camera is at the origin (0,0,0). vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz; EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace; // Vector that goes from the vertex to the light, in camera space. M is ommited because it's identity. vec3 LightPosition_cameraspace = ( V * vec4(LightPosition_worldspace,1)).xyz; LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace; // Normal of the the vertex, in camera space Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace,0)).xyz; // Only correct if ModelMatrix does not scale the model ! Use its inverse transpose if not. // UV of the vertex. No special space for this one. UV = vertexUV; if (vertex_image_type==2) { UV.y =-UV.y;//invierse v if dds } }      i just kept the diffuse, thats where the problem seems to be. maybe the problem is with the glsl and opengl versions? edit: Just to add some more info. I kinda think the problem has something to do with that cosTheta variable. when I remove it from the equation, the problem is no longer there(but faces are lit up eventhough they are facing away from the light) I understand the purpose of the cosTheta is to calculate the brightness based on the angle of the face compared to the angle of the light, but maybe there is something wrong here...
  3. Hmm, ECS seems interesting, so according to my research, I would have Human( an entity) and instead of inheriting visible and physical, it has instances of visible and physical?
  4. one question: what is the difference, or the point of having two constructors: Counted() { ++number_of; } Counted(const Counted &) { ++number_of; }
  5. oh cool, I was wondering how I would do it with a template. So any class that I want to have an instance counter can inherit that template
  6. haha yea @Spiro, Thats what I have already. But if I want to do that for every class, I would have to write that over and over. for example class visible //can see it, but can't touch it { static int numberOf = 0; public: visible(){numberOf++;} ~visible(){numberOf--;} }; class physical // can feel it but can't see it { static int numberOf = 0; public: physical(){numberOf++;} ~physical(){numberOf--;} }; class human: public physical, public visible // can see it and touch it { static int numberOf = 0; public: human(){numberOf++;} ~human(){numberOf--;} }; class girl: public human // a human girl { static int numberOf = 0; public: girl(){numberOf++;} ~girl(){numberOf--;} }; visible sky; physical boundary; human being; girl princess;   at the end of this I would have: visible::numberOf = 4, physical::numberOf = 4, human::numberOf = 2, girl::numberOf = 1. 
  7. Lets say that I want all of my classes to have their own private static int called "numberOf" that is basically has the total number of instances of that class. Right now I have a way that works simple enough: typing the declaration/definition of the variable for every class and new class I create and their constructors/destructors. it works but I was wondering if there is an easier way to do this, to have all of the classes have a their own (private/non-inherited) static variable of the same name, or is my way just basically it? 
  8. okay, I actually now concluded that its not the code...its my comp:    I ran the exe(not with code::blocks) on my pc, and the situation is the same. but then I take it to my dad's laptop and it runs normal and smooth no matter what else is open! gunna start comparing all of our setting and stuff.
  9. ah okay, I'm not gunna bother with the code anymore, the game loop and timing are pretty precise ..gunna go try it on other computers to be sure its not just mine... or I'll just have to play with Chrome open all the time! thanks for the help guys, Ill probly be back when it doesnt work
  10. I decided to created a log and output the time since each update into a file... if the game loop was working right, the time time between each frame should be the same right? well there were slightly different:(here is just some of the times)     0.0167939 0.0197271 0.0204671 0.0206342 0.0188694 0.0201671 0.0196725 0.0219421 0.0180132 0.020587 0.0197747   are these times close enough, or should the game loop really be calling the update equally every time??
  11. cool so I got the chrono classes to work and convert my game loop to use the high resolution clock insted of sf clock, and it works but it still looks smoother while Chrome is open!! haha it seems so odd to me.
  12. okay I guess its not working... I keep getting: undefined reference to `boost::chrono::steady_clock::now()' I don't understand...I don't have to link the chrono file do I?
  13. ugh, so I think I got it to work, but not how it says to do it. I had to copy the include files into mingw's include folder, instead of linking it through compiler settings. It's pretty stupid, I don't understand I why It wouldnt work when putting the file locations in the search directory...
  14. I've been trying to get boost libraries to work with code::blocks(mingw), but I can't seem to get it right. I have followed the instructions on official website: http://www.boost.org/doc/libs/1_53_0/more/getting_started/windows.html#link-your-program-to-a-boost-library   I built the libs and everything and added the include and lib to my compiler search directory... but what do i do next? when I write #include <boost... nothing comes up. I copied the test code, and it failed saying :fatal error: boost/lambda/lambda.hpp: No such file or directory.    any help?
  15. yea, I got c++11 to work. I guess code::blocks just doesnt recognize some of the classes( it doesnt highlight them or anything), but they still work
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!