# TheOrestes

Member

46

## Community Reputation

282 Neutral

• Rank
Member

Yup. Totally. Thanks :-)

This is the problem. You should put w = 0 and not 1.0. This ensure that you are not translating the normal like position. You also need to renormalize the normal after that. Also make sure you aren't using nonuniform scaling.   Another way is to move directional light to object space. This way you don't need any transformations at vertex shader and just one inverse transform per object.     Ahhh ... the W being 1  :( that was purely insane mistake from my end as its the vector i am transforming and not the point!   However, your second suggestion is exactly what i did to recify the mistake. Thanks a lot for assistance. :)

Looks like bit of more perseverance from my end would have helped me. So, instead of me taking all the normals to world space, I applied World Inverse transformation on the light direction vector, which did the trick for me.   Here is the modified code : vs_outNormal = normalize(in_Normal); vs_outLightDir = normalize((matWorldInv * vec4(LightDirection,0.0)).xyz); Here is the output :     Thanks.   P.S :  Still in case you find anything wrong with the shader conceptually please let me know.

Hi,   I am encountering an issue where am sure I am the culprit but am not able to quite figure out what is it that I am doing wrong. Here is the vertex shader : #version 400 layout(location=0) in vec3 in_Position; layout(location=1) in vec3 in_Normal; layout(location=2) in vec2 in_Tex; out vec2 vs_outTex; out vec3 vs_outNormal; out vec3 vs_outLightDir; out vec4 vs_outObjColor; // uniforms... uniform mat4 matWorld; uniform mat4 matView; uniform mat4 matProj; vec3 LightDirection = vec3(1,1,1); vec4 objColor = vec4(1,0,0,1); void main() { mat4 WVP = matProj * matView * matWorld; gl_Position = WVP * vec4(in_Position, 1.0); vs_outNormal = in_Normal; vs_outLightDir = normalize(LightDirection); vs_outTex = in_Tex; vs_outObjColor = objColor; } and here is the fragment shader : #version 400 in vec2 vs_outTex; in vec3 vs_outNormal; in vec3 vs_outLightDir; in vec4 vs_outObjColor; out vec4 outColor; uniform sampler2D texture_diffuse1; void main() { vec4 baseColor = vec4(texture(texture_diffuse1, vs_outTex)); float NdotL = max(dot(vs_outNormal, vs_outLightDir), 0); vec4 Emissive = baseColor; vec4 Ambient = vec4(0.2, 0.2, 0.2, 1); vec4 DiffuseDirect = vec4(NdotL); outColor = vs_outObjColor * DiffuseDirect; //Emissive; // * (Ambient + DiffuseDirect); } Here is the output produced by the shader during rendering :     Obviously, you guys must have noticed that I have not transformed object normals from object space to world space. Due to this, when the object rotates the lighting rotates with it giving a feeling that light is attached to the object and rotates with it. However, logically what I am trying to do is implement simple directional light shader where direction is suppose to be in world space, so no matter what orientation object is in, lighting direction remains constant.   For this to work, I took my object space normals to world space by doing following changes to the code in vertex shader : vs_outNormal = (matWorld * vec4(in_Normal, 1.0)).xyz; After doing this, here is the output I get :     This time around, deer at the center receives proper lighting & gives impression of light ( which is global directional light ) being static if object rotates etc. However, other deer object's lighting has gone for the toss! Interestingly the closer i get left & right deers to the center deer object, lighting seems to be working fine. Here is the outptut :     Can anyone suggest where am I screwing up things? Why lighting seems to be working fine only when Object is at (0,0,0) but the time we move to left or right, lighting seem to be changing? ( Obviously this will happen in case the light source is point light with attenutation, but its directional light for me! )   Any thoughts or way forward in debugging will be really helpful.   Thanks.
5. ## Anyone here a self-taught graphics programmer?

Hi,   I am a self taught Graphics/Shader programmer. In India, we don't get luxury of having university courses dedicated to Games or Graphics. By the time you get good at math, you don't even know why you are doing Laplace's transfom & where it is used in pratice... Its just the fact that "How is this done?" made me take up graphics programming & C++ to learn new exciting stuff ...   My Story so far ...   1. Get overwhelmed by seeing what people have been doing, wondering how they did it 2. Study, take each topic at once, there is a huge mountain to climb & you always start at the base 3. Get more overwhelmed as each day passes by 4. Study more, implement stuff, keep learning 5. Even more overwhelmed 6. Tell it to yourself that one day you will reach there ....  (After all , this journey has been awesome knowing there is still so much to learn ! )   Cheers.
6. ## D3DXMatrixLookAtLH vs Custom View Matrix

Thank you so much guys! Appreciate all the help...   Cheers.
7. ## D3DXMatrixLookAtLH vs Custom View Matrix

Yup!   Thats exactly what i did & it worked.  So basically the cross product for LH matrix doesnt seem to follow right hand thumb rule but rather left hand convention?  As conventionally in right hand thumb rule.... "LookAt X Up" should point to right hand side... and "Up X LookAt" should  point to left side ....
8. ## D3DXMatrixLookAtLH vs Custom View Matrix

Hi tonemgub,   Thanks for the reply. The code is not copied from anywhere, but rather I am referring to the book by Frank luna on DirectX9 using Shader approach.         I am not quite sure how this will result in camera right vector as the calculation should give you camera lookat vector itself. unless its a typo. Right vector will be obtained only when you take the cross product of lookat vector & reference up vector.   I got the right output after changing the order of cross product. As per msdn, zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) Whereas I was doing it cross(zaxis, up) thinking it follows right hand thumb rule ( cross(zaxis, Up) will point to the right side)  for the cross product but being Left handed view matrix its the other way around ?   Once again thanks to your input, I started looking vars more carefully   Cheers.
9. ## D3DXMatrixLookAtLH vs Custom View Matrix

Hi,   I am quite sure am doing something wrong here but not able to figure it out. Basically, D3DXMatrixLookAtLH(&m_matView, &m_vecPosition, &m_vecLookAtPoint, &m_WorldUp); results in :   Whereas. custom view matrix calculation : m_vecLookAtPoint = m_vecLookAtPoint - m_vecPosition;     D3DXVec3Normalize(&m_vecLookAtPoint, &m_vecLookAtPoint);          D3DXVec3Cross(&m_vecRight, &m_vecLookAtPoint, &m_WorldUp);     D3DXVec3Normalize(&m_vecRight, &m_vecRight);     D3DXVec3Cross(&m_WorldUp, &m_vecLookAtPoint, &m_vecRight);     D3DXVec3Normalize(&m_WorldUp, &m_WorldUp);     m_matView._11 = m_vecRight.x; m_matView._12 = m_WorldUp.x; m_matView._13 = m_vecLookAtPoint.x; m_matView._14 = 0;     m_matView._21 = m_vecRight.y; m_matView._22 = m_WorldUp.y; m_matView._23 = m_vecLookAtPoint.y; m_matView._24 = 0;     m_matView._31 = m_vecRight.z; m_matView._32 = m_WorldUp.z; m_matView._33 = m_vecLookAtPoint.z; m_matView._34 = 0;          m_matView._41 = -D3DXVec3Dot(&m_vecPosition, &m_vecRight);     m_matView._42 = -D3DXVec3Dot(&m_vecPosition, &m_WorldUp);     m_matView._43 = -D3DXVec3Dot(&m_vecPosition, &m_vecLookAtPoint);     m_matView._44 = 1.0f; results in :     If i manually change the WorldUp vector to (0,-1,0) instead of (0,1,0) i get the default output as in first image.   These are my vectors used for the matrix calculations :     m_vecPosition    = D3DXVECTOR3(3.0f, 3.0f, -10.0f);     m_WorldUp        = D3DXVECTOR3(0.0f, 1.0f, 0.0f);     m_vecRight        = D3DXVECTOR3(1.0f, 0.0f, 0.0f);     m_vecLookAtPoint= D3DXVECTOR3(0.0f, 0.0f, 0.0f);   The question is, why I have to invert my World up vector during custom view matrix calculation? what is it that am doing wrong?   Cheers.
10. ## Free game engine that is really well documented and has good tutorials?

Unity & I must mention Cinder.. Both are easy to learn and get started ..
11. ## Good Direct3D 11 book for someone who already knows OpenGL

Completely agree with Icebone1000, Practical Rendering and Computation with Direct3D 11 is a great book. Tons of details & great explanation.
12. ## PC to Browser

Hi,   Thanks for the reply. Yes, absolutely! am quite aware of the fact that DirectX cannot be used on browser, hence all the questions related to porting existing code to browser compaible codebase. However for that, does above mentioned approach makes sense? Am going to explore HLSL to GLSL converter at first place to see its correctness & how much extra work that should be done. If shaders am encountering are the simple ones, then re-writing them again shouldn't be much of a problem. The main issue is choosing between three.js & X3D. Any inputs on that would be great.   Once again, thanks for the reply. :)

Anyone?