CG 2 GLSL

Hi all!

Trying to convert from cg to glsl… it is pretty straight foward but i have a doubt:

CG

float3x3 mv		= float3x3(glstate.matrix.modelview[0]);
float4 pos		= float4(IN.pos.x,  IN.pos.y, IN.pos.z, 1.0);
OUT.vpos		= mul(glstate.matrix.modelview[0], pos).xyz;
float3 tangent	        = mul(mv, IN.tangent.xyz);
float3 binormal	        = mul(mv, IN.binormal.xyz);
float3 normal	        = mul(mv, IN.normal);
float3x3 ts		= float3x3(tangent, binormal, normal);
OUT.view		= mul(ts, OUT.vpos);
OUT.light		= mul(ts, lightpos.xyz - OUT.vpos);

glsl

vec3 vpos		= vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 tangent	        = vec3(gl_NormalMatrix * tangent);
vec3 binormal	        = vec3(gl_NormalMatrix * binormal);
vec3 normal		= gl_NormalMatrix * gl_Normal;
mat3 ts			= mat3(tangent, binormal, normal);
vec3 view		= normalize(ts * vpos);
vec3 light		= normalize(ts * gl_LightSource[0].position.xyz - vpos);

would light and view return the same in both shaders?

No, there’s one mistake:

vec3 light		= normalize(ts * gl_LightSource[0].position.xyz - vpos);

should be

vec3 light		= normalize(ts * (gl_LightSource[0].position.xyz - vpos));

Then they are (except the normalize funktions) the same.

Awesome!

thx Corrail! :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.