glsl/hlsl code help needed

Started by coderfreak2022, October 17, 2022, 07:57:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I am newbie to GLSL and HLSL programming. I am trying to do the below operations using some functions with shader programming. Any suggestions or reference code or links would help.

1)HLSL/GLSL function test to check if two vectors lie on single line
2) HLSL/GLSL function to find the angle between vectors v1 and v2 is acute (less than 90)
3)HLSL/GLSL function to convert linear value to gamma corrected value
4)HLSL/GLSL function to compute lambert diffuse term . Compute Lambert diffuse term where L = light vector, N = normal vector, V = view vector, Kd- diffuse coeff


For 1)

1) You can represent any line using two vectors, if each vector represent a point in 3D space and they aren't in the same position. If you want to know if a vector representing a point is in a line you need to get a point and a vector that represent this line: The code is something like that:

// p1 and p2 are points in the line
// p is a point that is to be tested if it is in the line

v1 = p2 - p1
v2 = p - p1
normal = cross(v1, v2)
isInLine = normal == vec3(0,0,0)