Jump to content

Connecting Some Dots - GLSL BJS convention.


Pryme8
 Share

Recommended Posts

mmmkay I have been bashing my head for days now, just trying to get a simple Blinn Phong Lighting model working... (fml)

anyways I found : http://www.mathematik.uni-marburg.de/~thormae/lectures/graphics1/code/WebGLShaderLightMat/ShaderLightMat.html

which seems to be a really simple deployment of it, but I have some questions...
first,  what is the bjs equivalent to uniform mat4 projection, modelview, normalMat;

I'm assuming projection is worldViewProjection, what what is the modelview Matrix, and the normal Matrix?
its not normal/position attributes so what are they?

I have a couple other questions but well start with this.
 

Link to comment
Share on other sites

  • 4 weeks later...

Im kinda struggling with some of the naming differences still.

In the default material there are these uniforms:
uniform mat4 viewProjection;
uniform mat4 view;
uniform mat4 world;

vs a Custom Shader mat seems to come with these:

world
worldView
worldViewProjection
view
projection

but see nothing about viewProjection.

so I assume (but am prolly wrong) that to get my viewProjection in a custom Shader I would do
mat4 viewProjection = view * projection?

these are shots in the dark though...  Im going off of the information available here:
https://doc.babylonjs.com/how_to/shader_material


Ive ended up with a Vertex Shader that looks like this:
 

precision highp float;
//Attributes
attribute vec3 position;
attribute vec2 uv;	
attribute vec3 normal;
// Uniforms

uniform mat4 worldViewProjection;
uniform float time;

uniform mat4 projection;
uniform mat4 view;

//Varyings
varying vec2 vUV;
varying vec3 vNormal;
varying vec3 vPositionW;


#if NUM_BONE_INFLUENCERS > 0
	uniform mat4 mBones[BonesPerMesh];

	attribute vec4 matricesIndices;
	attribute vec4 matricesWeights;
	#if NUM_BONE_INFLUENCERS > 4
		attribute vec4 matricesIndicesExtra;
		attribute vec4 matricesWeightsExtra;
	#endif
#endif

#ifdef INSTANCES
	attribute vec4 world0;
	attribute vec4 world1;
	attribute vec4 world2;
	attribute vec4 world3;
#else
	uniform mat4 world;
#endif

void main(void) {
   
    vec4 p = vec4( position, 1. );

    #ifdef INSTANCES
	    mat4 finalWorld = mat4(world0, world1, world2, world3);
    #else
	    mat4 finalWorld = world;
    #endif

    #if NUM_BONE_INFLUENCERS > 0
	mat4 influence;
	influence = mBones[int(matricesIndices[0])] * matricesWeights[0];

	#if NUM_BONE_INFLUENCERS > 1
		influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
	#endif	
	#if NUM_BONE_INFLUENCERS > 2
		influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
	#endif	
	#if NUM_BONE_INFLUENCERS > 3
		influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
	#endif	

	#if NUM_BONE_INFLUENCERS > 4
		influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
	#endif	
	#if NUM_BONE_INFLUENCERS > 5
		influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
	#endif	
	#if NUM_BONE_INFLUENCERS > 6
		influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
	#endif	
	#if NUM_BONE_INFLUENCERS > 7
		influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
	#endif

	finalWorld = finalWorld * influence;

    #endif

    gl_Position = worldViewProjection * finalWorld * p;
    vUV = uv;

    mat3 normalWorld = mat3(finalWorld);
    vNormal = normalize(normalWorld * normal);

    vPositionW = vec3(finalWorld * p);


Which kinda works, but for some reason if applied to a ground mesh it makes it into a billboard...
good news is the actor mesh seems to be animated correctly, but some of the shading is off which I am assuming is because I am using the wrong projection.

*EDIT* I think I fixed the lighting by fixing the normal's after transformation.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...