Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About rampster

  • Rank
  1. Hi! I am trying to implement a spot light shader with bumpmapping and I am having problems getting the right output! I have the necessary spot light pixel shader inputs (vertex to light direction and spot direction) in view space and would like to convert them to tangent space. But I have only been able to find this version that converts world space to tangent space. // Create a transform to convert a world space vector to tangent space. mat3 tangentSpaceTransformMatrix = mat3(tangentVector, binormalVector, normalVector); my question here is : does the following matrix convert vertors from view space to tangent space? // Transform the normal, tangent and binormals to view space. mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix); vec3 tangentVector = inverseTransposeWorldViewMatrix * a_tangent; vec3 normalVector = inverseTransposeWorldViewMatrix * a_normal; vec3 binormalVector = inverseTransposeWorldViewMatrix * a_binormal; // Create a transform to convert a vector to tangent space. mat3 tangentSpaceTransformMatrix = mat3(tangentVector, binormalVector, normalVector); I am under an impression it does.. But please correct me if I am wrong! Thanks! mrp
  2. Hi, I have implemented a spot light shader with light range, inner cone angle, outer cone angle and spot direction as prime inputs. This shader is inspired from Wolfgang Engel's book programming vertex and fragment shader. My question is how do I get get my spot light shader inputs (light range, inner angle and outer angle) from a collada spot light node info (constant attenuation, linear attenuation, quadratic attenuation, fall off angle and fall off exponent) from the look of it outer cos angle = fall off angle but not very sure how to calculate the light range and inner cos angle. Is it even possible? Any help is much appreciated!! Thanks in advance, Ram
  3. rampster

    Point light shader question

    Thanks for your Reply MJP .. that helped! I found some explanations here : http://developer.dow...el_Lighting.pdf that was great as well! I am going for the solution 1 because that meets all my needs for the application! Thanks again!
  4. Hey guys, I am trying to implement a simple point light shader in glsl and not sure which equation calculates the right attenuation from the below two links: 1. XNA shader programming tutorials says attenuation = 1 - dot (L/r , L/r). I like this one because of the point light radius parameter we could pass in. 2. Now Lighthouse3d tutorials (and most text books) says: attenuation = 1 / (KC + (kL * D) + (KQ * D * D)). Now which one do you guys think gives the right attenuation? If both are right what is the relation between them? Thanks in advance!
  5. rampster

    Normalmap shader

    [color="#1C2837"] [color="#1C2837"]solved! [color="#1C2837"] "v_lightDirectionTangentSpace = u_directionalLight.direction * tangentSpaceTransform;" [color="#1C2837"] [color="#1C2837"]must have been [color="#1C2837"] [color="#1C2837"]v_lightDirectionTangentSpace = [color="#1C2837"]tangentSpaceTransform * [color="#1C2837"]u_directionalLight.direction; [color="#1C2837"] [color="#1C2837"]This was messing up the light direction and hence the lighting calculations!
  6. Hi, I am trying to draw a cube with a bump map using normal maps but I really cant see any bump effect on a spinning cube. My unit cube is imported out of maya as a collada file with geometric tangents option (and they seem right). My worldspace light direction is (0.0, 0.0, 1.0). My camera position is (0.0, 0.0, 5.0). I am rotating my cube across Y axis. Am I missing anything in my shader that could cause a problem? Thanks in advance! My vertex shader: // Structs struct DirectionalLight { vec3 direction; vec3 color; }; // Uniforms uniform DirectionalLight u_directionalLight; uniform mat4 u_worldViewProjectionMatrix; // Inputs attribute vec4 a_position; attribute vec3 a_normal; attribute vec2 a_texCoord; attribute vec3 a_tangent; attribute vec3 a_binormal; // Outputs varying vec3 v_lightDirectionTangentSpace; varying vec2 v_texCoord; void main() { gl_Position = u_worldViewProjectionMatrix * a_position; // Create a transform to convert a vector to tangent space. mat3 tangentSpaceTransform = mat3(a_tangent, a_binormal, a_normal); // Transform light direction to tangent space. v_lightDirectionTangentSpace = u_directionalLight.direction * tangentSpaceTransform; v_texCoord = a_texCoord; } Fragement shader precision highp float; // Structs struct DirectionalLight { vec3 direction; // Direction of the light vec3 color; // RGB color of the light }; // Uniforms uniform DirectionalLight u_directionalLight; // Directional Light uniform vec3 u_ambientColor; // Ambient color uniform sampler2D u_diffuseTexture; uniform sampler2D u_normalMapTexture; // Inputs varying vec3 v_lightDirectionTangentSpace; varying vec2 v_texCoord; void main() { vec3 normalVector = normalize(texture2D(u_normalMapTexture, v_texCoord).xyz * 2.0 - 1.0); vec4 baseColor = texture2D(u_diffuseTexture, v_texCoord); vec4 ambientColor = vec4(u_ambientColor, 1.0) * baseColor; // Diffuse float diffuseIntensity = max(0.0, dot(normalVector, v_lightDirectionTangentSpace)); vec4 diffuseColor = (vec4(u_directionalLight.color, 1.0) * diffuseIntensity) * baseColor; gl_FragColor = ambientColor + diffuseColor; }
  • 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!