Pryme8 Posted April 4, 2018 Share Posted April 4, 2018 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 4, 2018 Share Posted April 4, 2018 Hey! I assume you are using ShaderMaterial so: * projection = projection * modelview = worldView * normalMat = world (in this case) Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 5, 2018 Author Share Posted April 5, 2018 This is the stuff that is setting me back cool thanks! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 5, 2018 Author Share Posted April 5, 2018 What kinds of varying and attribute params do I have access to in a custom PostProccess? is it just vUV? I assume vPosition is moot cause there are no vertices. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 5, 2018 Share Posted April 5, 2018 Only vUV my friend https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/postprocess.vertex.fx Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted May 4, 2018 Author Share Posted May 4, 2018 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2018 Share Posted May 4, 2018 You should not use worldViewProjection as you found you can just set it up manually: https://github.com/BabylonJS/Babylon.js/blob/master/materialsLibrary/src/simple/babylon.simpleMaterial.ts#L210 Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted May 4, 2018 Author Share Posted May 4, 2018 You are a boss. ASDKLFHLKASDFHLSJAFLJSAD HOLY CRAP MAN! This library constantly blows my mind. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.