OpenGL ES 2.0 Fixed Pipeline Emulation
OpenGL ES 2.0 Fixed Pipeline Emulation
Ref.
if (ecNormalDotLightHalfplane > 0.0)
{
specularLight = pow(ecNormalDotLightHalfplane, u_material.shininess) * u_directionalLight.specularColor *
u_material.specularFactor;
}
and ref.
https://github.com/kizzx2/irrlicht-ogl- ... peline.vsh
//////// suggest way
//////// COGLES2Solid.vsh and COGLES2Solid2.vsh
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
float NdotH = max(0.0, dot(normal, HalfVector));
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor * Attenuation;
}
//to
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
}
vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
specular += pow(NdotH, uMaterialShininess) * uLightSpecular[index] * Attenuation;
}
if (ecNormalDotLightHalfplane > 0.0)
{
specularLight = pow(ecNormalDotLightHalfplane, u_material.shininess) * u_directionalLight.specularColor *
u_material.specularFactor;
}
and ref.
https://github.com/kizzx2/irrlicht-ogl- ... peline.vsh
//////// suggest way
//////// COGLES2Solid.vsh and COGLES2Solid2.vsh
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
float NdotH = max(0.0, dot(normal, HalfVector));
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor * Attenuation;
}
//to
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
}
vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
specular += pow(NdotH, uMaterialShininess) * uLightSpecular[index] * Attenuation;
}
Last edited by feelthat on Sat Feb 14, 2015 5:54 pm, edited 3 times in total.
Re: Android Port
I suspect what you mean is that we should change it? But given that those will have the same result as far as I can see I'm not sure why you propose it? Did it get noticably faster that way? I doubt it as I tried something similar in the past and it didn't get faster but slower (if's tend to be slow in shader-code).
If you propose changes please explain why you think it should be changed...
If you propose changes please explain why you think it should be changed...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Android Port
When I make a example for test on git version 4906
added 2 light source and a big ground texture
smgr->addLightSceneNode(0, vector3df(+20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
smgr->addLightSceneNode(0, vector3df(-20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
Node_GND->setMaterialFlag(video::EMF_LIGHTING, true);
Node_GND->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
normally camera look forward is fine, but camera look on the ground directly.
the ground texture become all deep black~~~
after add if (NdotH > 0.0) then good
added 2 light source and a big ground texture
smgr->addLightSceneNode(0, vector3df(+20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
smgr->addLightSceneNode(0, vector3df(-20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
Node_GND->setMaterialFlag(video::EMF_LIGHTING, true);
Node_GND->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
normally camera look forward is fine, but camera look on the ground directly.
the ground texture become all deep black~~~
after add if (NdotH > 0.0) then good
CuteAlien wrote:I suspect what you mean is that we should change it? But given that those will have the same result as far as I can see I'm not sure why you propose it? Did it get noticably faster that way? I doubt it as I tried something similar in the past and it didn't get faster but slower (if's tend to be slow in shader-code).
If you propose changes please explain why you think it should be changed...
Re: Android Port
How does it behave with fixed-function pipeline (es1)? The idea is to simulate that - so we generally try to have identical (or near identical) results. If you can give us your test we can also compare.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Android Port
a spot light shader source code
https://code.google.com/p/jpcsp/source/ ... ert?r=1639
http://en.wikibooks.org/wiki/GLSL_Progr ... Highlights
and a question rDotE or nDotH which is good?
1. reflect and eye cos(angle)
vec3 E = normalize(-V); //dir vertex to eye
vec3 R = reflect(-L, N); //dir light after reflect on object
float rDotE = dot(R,E); //cos(angle RtoE)
2. Jim Blinn Model for Specular Reflection (assume best normal and objnormal cos(angle). )
vec3 E = normalize(-V); //dir vertex to eye
vec3 HalfVector = normalize(L + E); // dir light and dir eye half vector(assume this is the best reflect normal)
float nDotH = dot(N,H); //cos(angle ObjNormal to LE)
//////
float nDotL = dot(N,L);
if (nDotL > 0.0) {
// TODO Which model is correct?
if (true)
{
vec3 E = normalize(-V);
vec3 R = reflect(-L, N);
float rDotE = dot(R,E);
if (rDotE > 0.0)
{
float pf = pow(rDotE, gl_FrontMaterial.shininess);
specular += gl_LightSource.specular * attenuation * pf;
}
}
else
{
vec3 E = normalize(-V);
vec3 H = normalize(L + E);
float nDotH = dot(N,H);
if (nDotH > 0.0)
{
float pf = pow(nDotH, gl_FrontMaterial.shininess);
specular += gl_LightSource.specular * attenuation * pf;
}
}
diffuse += gl_LightSource.diffuse * attenuation * nDotL;
}
https://code.google.com/p/jpcsp/source/ ... ert?r=1639
http://en.wikibooks.org/wiki/GLSL_Progr ... Highlights
and a question rDotE or nDotH which is good?
1. reflect and eye cos(angle)
vec3 E = normalize(-V); //dir vertex to eye
vec3 R = reflect(-L, N); //dir light after reflect on object
float rDotE = dot(R,E); //cos(angle RtoE)
2. Jim Blinn Model for Specular Reflection (assume best normal and objnormal cos(angle). )
vec3 E = normalize(-V); //dir vertex to eye
vec3 HalfVector = normalize(L + E); // dir light and dir eye half vector(assume this is the best reflect normal)
float nDotH = dot(N,H); //cos(angle ObjNormal to LE)
//////
float nDotL = dot(N,L);
if (nDotL > 0.0) {
// TODO Which model is correct?
if (true)
{
vec3 E = normalize(-V);
vec3 R = reflect(-L, N);
float rDotE = dot(R,E);
if (rDotE > 0.0)
{
float pf = pow(rDotE, gl_FrontMaterial.shininess);
specular += gl_LightSource.specular * attenuation * pf;
}
}
else
{
vec3 E = normalize(-V);
vec3 H = normalize(L + E);
float nDotH = dot(N,H);
if (nDotH > 0.0)
{
float pf = pow(nDotH, gl_FrontMaterial.shininess);
specular += gl_LightSource.specular * attenuation * pf;
}
}
diffuse += gl_LightSource.diffuse * attenuation * nDotL;
}
Last edited by feelthat on Tue Feb 03, 2015 9:07 pm, edited 3 times in total.
Re: Android Port
Blinn is an approximation, only correct when E = R.
Re: Android Port
SO why irrlicht use (L+E) ??? could u explain
mongoose7 wrote:Blinn is an approximation, only correct when E = R.
Re: Android Port
If you mean EGL2, I don't know. In the trunk, Irrlicht does not support specular.
Re: Android Port
guys, Which Shading you feel better???
Half vector or Reflect vector?
http://en.wikipedia.org/wiki/Blinn–Phong_shading_model
http://www.arcsynthesis.org/gltut/Illum ... Model.html
http://www.lighthouse3d.com/tutorials/g ... -lights-ii
//Calculate the half vector between the light vector and the view vector.
//This is faster than calculating the actual reflective vector.
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
faster then
vec3 E = normalize(-position);
vec3 R = reflect(-L, normal);
float rDotE = dot(R,E);
Half vector or Reflect vector?
http://en.wikipedia.org/wiki/Blinn–Phong_shading_model
http://www.arcsynthesis.org/gltut/Illum ... Model.html
http://www.lighthouse3d.com/tutorials/g ... -lights-ii
//Calculate the half vector between the light vector and the view vector.
//This is faster than calculating the actual reflective vector.
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
faster then
vec3 E = normalize(-position);
vec3 R = reflect(-L, normal);
float rDotE = dot(R,E);
feelthat wrote:SO why irrlicht use (L+E) ??? could u explain
mongoose7 wrote:Blinn is an approximation, only correct when E = R.
Last edited by feelthat on Tue Feb 03, 2015 2:18 pm, edited 7 times in total.
Re: Android Port
Hardly worth the effort these days. Best to do it correctly I think.
Re: Android Port
Here is spot light vsh
help me
Nadro or Cutealien please check if you are free.
anything wrong?
/////
uniform float uSpotOuter[MAX_LIGHTS];
uniform float uFallOff[MAX_LIGHTS];
void spotLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
//normalize spot light direction in worldview matrix
vec3 NspotDir = normalize((uNMatrix * vec4(uLightDirection[index], 0.0)).xyz);
//dot(NspotDir and lightvector) = cos(angle)
float spotEffect = dot(NspotDir, -L);
if (spotEffect >= cos( radians(uSpotOuter[index]) ))
{
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
Attenuation *= pow(spotEffect, uFallOff[index]);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = max(0.0, dot(normal, HalfVector));
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor * Attenuation;
}
}
}
//source ref. site
https://code.google.com/p/jpcsp/source/ ... ert?r=1639
http://en.wikibooks.org/wiki/GLSL_Progr ... Highlights
//ogles2 api
https://www.khronos.org/opengles/sdk/do ... e-card.pdf
help me
Nadro or Cutealien please check if you are free.
anything wrong?
/////
uniform float uSpotOuter[MAX_LIGHTS];
uniform float uFallOff[MAX_LIGHTS];
void spotLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
//normalize spot light direction in worldview matrix
vec3 NspotDir = normalize((uNMatrix * vec4(uLightDirection[index], 0.0)).xyz);
//dot(NspotDir and lightvector) = cos(angle)
float spotEffect = dot(NspotDir, -L);
if (spotEffect >= cos( radians(uSpotOuter[index]) ))
{
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
Attenuation *= pow(spotEffect, uFallOff[index]);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = max(0.0, dot(normal, HalfVector));
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor * Attenuation;
}
}
}
//source ref. site
https://code.google.com/p/jpcsp/source/ ... ert?r=1639
http://en.wikibooks.org/wiki/GLSL_Progr ... Highlights
//ogles2 api
https://www.khronos.org/opengles/sdk/do ... e-card.pdf
Last edited by feelthat on Mon Feb 09, 2015 9:36 pm, edited 3 times in total.
Re: Android Port
for spot light in
void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
.
.
.
for (s32 i = 0; i < LightCount; ++i)
{
SLight CurrentLight = driver->getDynamicLight(i);
//Matrix.transformVect(CurrentLight.Position);
Matrix_V.transformVect(CurrentLight.Position);
switch (CurrentLight.Type)
{
case ELT_DIRECTIONAL:
LightType = 2;
break;
case ELT_SPOT:
LightType = 1;
break;
default: // ELT_POINT
LightType = 0;
break;
}
LightPosition = CurrentLight.Position;
LightDirection = CurrentLight.Direction;
LightAttenuation = CurrentLight.Attenuation;
LightAmbient = CurrentLight.AmbientColor;
LightDiffuse = CurrentLight.DiffuseColor;
LightSpecular = CurrentLight.SpecularColor;
LightOuterCone = CurrentLight.OuterCone;
LightFallOff[i] = CurrentLight.Falloff;
}
const int MAX_SHADER_LIGHTS = 8; // must be the same as MAX_LIGHTS define in the shader
services->setPixelShaderConstant(LightTypeID, LightType, MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(uLightOuterConeID, reinterpret_cast<f32*>LightOuterCone, MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightFallOffID, reinterpret_cast<f32*>LightFallOff, MAX_SHADER_LIGHTS);
.
.
.
}
void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
.
.
.
for (s32 i = 0; i < LightCount; ++i)
{
SLight CurrentLight = driver->getDynamicLight(i);
//Matrix.transformVect(CurrentLight.Position);
Matrix_V.transformVect(CurrentLight.Position);
switch (CurrentLight.Type)
{
case ELT_DIRECTIONAL:
LightType = 2;
break;
case ELT_SPOT:
LightType = 1;
break;
default: // ELT_POINT
LightType = 0;
break;
}
LightPosition = CurrentLight.Position;
LightDirection = CurrentLight.Direction;
LightAttenuation = CurrentLight.Attenuation;
LightAmbient = CurrentLight.AmbientColor;
LightDiffuse = CurrentLight.DiffuseColor;
LightSpecular = CurrentLight.SpecularColor;
LightOuterCone = CurrentLight.OuterCone;
LightFallOff[i] = CurrentLight.Falloff;
}
const int MAX_SHADER_LIGHTS = 8; // must be the same as MAX_LIGHTS define in the shader
services->setPixelShaderConstant(LightTypeID, LightType, MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(uLightOuterConeID, reinterpret_cast<f32*>LightOuterCone, MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightFallOffID, reinterpret_cast<f32*>LightFallOff, MAX_SHADER_LIGHTS);
.
.
.
}
feelthat wrote:Here is spot light vsh
help me
Nadro or Cutealien please check if you are free.
anything wrong?
/////
uniform float uLightOuterCone[MAX_LIGHTS];
uniform float uLightFallOff[MAX_LIGHTS];
void spotLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
//normalize spot light direction in worldview matrix
vec3 NspotDir = normalize((uNMatrix * vec4(uLightDirection[index], 0.0)).xyz);
//dot(NspotDir and lightvector) = cos(angle)
float spotEffect = dot(NspotDir, -L);
if (spotEffect >= cos( radians(uLightOuterCone[index]) ))
{
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
Attenuation *= pow(spotEffect, uLightFallOff[index]);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL * Attenuation;
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = max(0.0, dot(normal, HalfVector));
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor * Attenuation;
}
}
}
//source ref. site
https://code.google.com/p/jpcsp/source/ ... ert?r=1639
http://http.developer.nvidia.com/CgTuto ... ter05.html
http://www.lighthouse3d.com/tutorials/g ... potlights/
http://www.blitzbasic.com/Community/pos ... opic=65243
https://www.khronos.org/registry/webgl/ ... jects.vert
http://en.wikibooks.org/wiki/GLSL_Progr ... Highlights
//ogles2 api
https://www.khronos.org/opengles/sdk/do ... e-card.pdf
Re: Android Port
//already compare with OGLES1 spot and direct light~~~ both work
//fixed for direct light and spot light --part one for vsh
#define MAX_LIGHTS 8
/* Attributes */
attribute vec3 inVertexPosition;
attribute vec3 inVertexNormal;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
attribute vec2 inTexCoord1;
/* Uniforms */
uniform mat4 uWVPMatrix;
uniform mat4 uWVMatrix;
uniform mat4 uNMatrix;
uniform mat4 uTMatrix0;
uniform vec4 uMaterialAmbient;
uniform vec4 uMaterialDiffuse;
uniform vec4 uMaterialEmissive;
uniform vec4 uMaterialSpecular;
uniform float uMaterialShininess;
uniform int uLightCount;
uniform int uLightType[MAX_LIGHTS];
uniform vec3 uLightPosition[MAX_LIGHTS];
uniform vec3 uLightDirection[MAX_LIGHTS];
uniform vec3 uLightAttenuation[MAX_LIGHTS];
uniform vec4 uLightAmbient[MAX_LIGHTS];
uniform vec4 uLightDiffuse[MAX_LIGHTS];
uniform vec4 uLightSpecular[MAX_LIGHTS];
uniform float uLightOuterCone[MAX_LIGHTS];
uniform float uLightFallOff[MAX_LIGHTS];
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying float vFogCoord;
void dirLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
//vec3 L = normalize(-uLightDirection[index]);
vec3 L = normalize(uLightPosition[index]); //direction same as opengl and oges1 use
ambient += uLightAmbient[index];
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL;
//vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor;
}
}
}
void pointLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * (NdotL * Attenuation);
//vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
//Blinn shading, in camera space which the camera position is (0,0,0)
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * (SpecularFactor * Attenuation);
}
}
}
void spotLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
//must do outside or become flashlight follow camera
//vec3 NSpotDir = (uViewMatrix * vec4(uLightDirection[index],0)).xyz;
vec3 NSpotDir = normalize(uLightDirection[index]);
//dot(NSpotDir and lightvector) = cos(angle)
float spotEffect = dot(NSpotDir, -L);
if (spotEffect >= cos(radians(uLightOuterCone[index])))
{
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
Attenuation *= pow(spotEffect, uLightFallOff[index]);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * (NdotL * Attenuation);
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * (SpecularFactor * Attenuation);
}
}
}
}
void main()
{
gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 0.0, 0.0);
vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
vVertexColor = inVertexColor.bgra;
vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
if (uLightCount > 0)
{
//VertexNormal(in camera space) = ObjVertexNormal * (worldview Matrix^-1)T
//NMatrixID = getVertexShaderConstantID("uNMatrix");
//setPixelShaderConstant(NMatrixID, Matrix.makeInverse().getTransposed().pointer(), 16);
vec3 Normal = normalize((uNMatrix * vec4(inVertexNormal, 0.0)).xyz);
vec4 Ambient = vec4(0.0, 0.0, 0.0, 0.0);
vec4 Diffuse = vec4(0.0, 0.0, 0.0, 0.0);
vec4 Specular = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 0)
pointLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 1)
spotLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 2)
dirLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
vec4 LightColor = Ambient * uMaterialAmbient + Diffuse * uMaterialDiffuse + Specular * uMaterialSpecular;
LightColor = clamp(LightColor, 0.0, 1.0);
LightColor.w = 1.0;
vVertexColor *= LightColor;
vVertexColor += uMaterialEmissive;
vVertexColor = clamp(vVertexColor, 0.0, 1.0);
}
vFogCoord = length(Position);
}
//fixed for direct light and spot light --part one for vsh
#define MAX_LIGHTS 8
/* Attributes */
attribute vec3 inVertexPosition;
attribute vec3 inVertexNormal;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
attribute vec2 inTexCoord1;
/* Uniforms */
uniform mat4 uWVPMatrix;
uniform mat4 uWVMatrix;
uniform mat4 uNMatrix;
uniform mat4 uTMatrix0;
uniform vec4 uMaterialAmbient;
uniform vec4 uMaterialDiffuse;
uniform vec4 uMaterialEmissive;
uniform vec4 uMaterialSpecular;
uniform float uMaterialShininess;
uniform int uLightCount;
uniform int uLightType[MAX_LIGHTS];
uniform vec3 uLightPosition[MAX_LIGHTS];
uniform vec3 uLightDirection[MAX_LIGHTS];
uniform vec3 uLightAttenuation[MAX_LIGHTS];
uniform vec4 uLightAmbient[MAX_LIGHTS];
uniform vec4 uLightDiffuse[MAX_LIGHTS];
uniform vec4 uLightSpecular[MAX_LIGHTS];
uniform float uLightOuterCone[MAX_LIGHTS];
uniform float uLightFallOff[MAX_LIGHTS];
/* Varyings */
varying vec2 vTextureCoord0;
varying vec4 vVertexColor;
varying float vFogCoord;
void dirLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
//vec3 L = normalize(-uLightDirection[index]);
vec3 L = normalize(uLightPosition[index]); //direction same as opengl and oges1 use
ambient += uLightAmbient[index];
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * NdotL;
//vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * SpecularFactor;
}
}
}
void pointLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * (NdotL * Attenuation);
//vec3 HalfVector = normalize(L + vec3(0.0, 0.0, 1.0));
//Blinn shading, in camera space which the camera position is (0,0,0)
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * (SpecularFactor * Attenuation);
}
}
}
void spotLight(in int index, in vec3 position, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
vec3 L = uLightPosition[index] - position;
float D = length(L);
L = normalize(L);
//must do outside or become flashlight follow camera
//vec3 NSpotDir = (uViewMatrix * vec4(uLightDirection[index],0)).xyz;
vec3 NSpotDir = normalize(uLightDirection[index]);
//dot(NSpotDir and lightvector) = cos(angle)
float spotEffect = dot(NSpotDir, -L);
if (spotEffect >= cos(radians(uLightOuterCone[index])))
{
float Attenuation = 1.0 / (uLightAttenuation[index].x + uLightAttenuation[index].y * D +
uLightAttenuation[index].z * D * D);
Attenuation *= pow(spotEffect, uLightFallOff[index]);
ambient += uLightAmbient[index] * Attenuation;
float NdotL = dot(normal, L);
if (NdotL > 0.0)
{
diffuse += uLightDiffuse[index] * (NdotL * Attenuation);
vec3 E = normalize(-position);
vec3 HalfVector = normalize(L + E);
float NdotH = dot(normal, HalfVector);
if (NdotH > 0.0)
{
float SpecularFactor = pow(NdotH, uMaterialShininess);
specular += uLightSpecular[index] * (SpecularFactor * Attenuation);
}
}
}
}
void main()
{
gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 0.0, 0.0);
vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
vVertexColor = inVertexColor.bgra;
vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
if (uLightCount > 0)
{
//VertexNormal(in camera space) = ObjVertexNormal * (worldview Matrix^-1)T
//NMatrixID = getVertexShaderConstantID("uNMatrix");
//setPixelShaderConstant(NMatrixID, Matrix.makeInverse().getTransposed().pointer(), 16);
vec3 Normal = normalize((uNMatrix * vec4(inVertexNormal, 0.0)).xyz);
vec4 Ambient = vec4(0.0, 0.0, 0.0, 0.0);
vec4 Diffuse = vec4(0.0, 0.0, 0.0, 0.0);
vec4 Specular = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 0)
pointLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 1)
spotLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
for (int i = 0; i < int(uLightCount); i++)
{
if (uLightType == 2)
dirLight(i, Position, Normal, Ambient, Diffuse, Specular);
}
vec4 LightColor = Ambient * uMaterialAmbient + Diffuse * uMaterialDiffuse + Specular * uMaterialSpecular;
LightColor = clamp(LightColor, 0.0, 1.0);
LightColor.w = 1.0;
vVertexColor *= LightColor;
vVertexColor += uMaterialEmissive;
vVertexColor = clamp(vVertexColor, 0.0, 1.0);
}
vFogCoord = length(Position);
}
Last edited by feelthat on Wed Feb 11, 2015 9:03 pm, edited 2 times in total.
Re: Android Port
//already compare with OGLES1 spot and direct light~~~ both work
//ref. https://github.com/daw42/glslcookbook/b ... er/spot.fs
//fixed for direct light and spot light --part two for COGLES2FixedPipelineRenderer.cpp
void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
int MAX_SHADER_LIGHTS;
IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdateBase)
{
WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix");
WVMatrixID = services->getVertexShaderConstantID("uWVMatrix");
NMatrixID = services->getVertexShaderConstantID("uNMatrix");
MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient");
MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse");
MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive");
MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular");
MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess");
LightCountID = services->getVertexShaderConstantID("uLightCount");
LightTypeID = services->getVertexShaderConstantID("uLightType");
LightPositionID = services->getVertexShaderConstantID("uLightPosition");
LightDirectionID = services->getVertexShaderConstantID("uLightDirection");
LightAttenuationID = services->getVertexShaderConstantID("uLightAttenuation");
LightAmbientID = services->getVertexShaderConstantID("uLightAmbient");
LightDiffuseID = services->getVertexShaderConstantID("uLightDiffuse");
LightSpecularID = services->getVertexShaderConstantID("uLightSpecular");
FogEnableID = services->getVertexShaderConstantID("uFogEnable");
FogTypeID = services->getVertexShaderConstantID("uFogType");
FogColorID = services->getVertexShaderConstantID("uFogColor");
FogStartID = services->getVertexShaderConstantID("uFogStart");
FogEndID = services->getVertexShaderConstantID("uFogEnd");
FogDensityID = services->getVertexShaderConstantID("uFogDensity");
LightOuterConeID = services->getVertexShaderConstantID("uLightOuterCone");
LightFallOffID = services->getVertexShaderConstantID("uLightFallOff");
FirstUpdateBase = false;
}
const core::matrix4 W = driver->getTransform(ETS_WORLD);
const core::matrix4 V = driver->getTransform(ETS_VIEW);
const core::matrix4 P = driver->getTransform(ETS_PROJECTION);
/*core::matrix4 Matrix = P * V * W;
services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16);
Matrix = V * W;
services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16);
Matrix.makeInverse();
services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16);*/
core::matrix4 Matrix_V;
core::matrix4 Matrix_V_W = V * W;
core::matrix4 Matrix_P_V_W = P * Matrix_V_W;
services->setPixelShaderConstant(WVPMatrixID, Matrix_P_V_W.pointer(), 16);
services->setPixelShaderConstant(WVMatrixID, Matrix_V_W.pointer(), 16);
Matrix_V_W.makeInverse();
services->setPixelShaderConstant(NMatrixID, Matrix_V_W.getTransposed().pointer(), 16);
s32 LightCount = LightEnable ? driver->getDynamicLightCount() : 0;
services->setPixelShaderConstant(LightCountID, &LightCount, 1);
if (LightCount > 0)
{
services->setPixelShaderConstant(MaterialAmbientID, reinterpret_cast<f32*>(&MaterialAmbient), 4);
services->setPixelShaderConstant(MaterialDiffuseID, reinterpret_cast<f32*>(&MaterialDiffuse), 4);
services->setPixelShaderConstant(MaterialEmissiveID, reinterpret_cast<f32*>(&MaterialEmissive), 4);
services->setPixelShaderConstant(MaterialSpecularID, reinterpret_cast<f32*>(&MaterialSpecular), 4);
services->setPixelShaderConstant(MaterialShininessID, &MaterialShininess, 1);
//Matrix = V;
Matrix_V = V;
for (s32 i = 0; i < LightCount; ++i)
{
SLight CurrentLight = driver->getDynamicLight(i);
//Matrix.transformVect(CurrentLight.Position);
Matrix_V.transformVect(CurrentLight.Position);
switch (CurrentLight.Type)
{
case ELT_DIRECTIONAL:
LightType = 2;
//for same as opengl and oges1 use, void COpenGLDriver::assignHardwareLight(u32 lightIndex)
//CurrentLight.Direction = LightDirInView(Matrix_V, CurrentLight.Direction)
CurrentLight.Position = -LightDirInView(Matrix_V, CurrentLight.Direction);
break;
case ELT_SPOT:
LightType = 1;
CurrentLight.Direction = LightDirInView(Matrix_V, CurrentLight.Direction);
break;
default: // ELT_POINT
LightType = 0;
break;
}
LightPosition = CurrentLight.Position;
LightDirection = CurrentLight.Direction;
LightAttenuation = CurrentLight.Attenuation;
LightAmbient = CurrentLight.AmbientColor;
LightDiffuse = CurrentLight.DiffuseColor;
LightSpecular = CurrentLight.SpecularColor;
LightOuterCone = CurrentLight.OuterCone;
LightFallOff[i] = CurrentLight.Falloff;
}
MAX_SHADER_LIGHTS = 8;
services->setPixelShaderConstant(LightTypeID, reinterpret_cast<s32*>(LightType), MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightPositionID, reinterpret_cast<f32*>(LightPosition), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightDirectionID, reinterpret_cast<f32*>(LightDirection), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightAttenuationID,reinterpret_cast<f32*>(LightAttenuation), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightAmbientID, reinterpret_cast<f32*>(LightAmbient), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightDiffuseID, reinterpret_cast<f32*>(LightDiffuse), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightSpecularID, reinterpret_cast<f32*>(LightSpecular), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightOuterConeID, reinterpret_cast<f32*>(LightOuterCone), MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightFallOffID, reinterpret_cast<f32*>(LightFallOff), MAX_SHADER_LIGHTS);
}
services->setPixelShaderConstant(FogEnableID, &FogEnable, 1);
if (FogEnable)
{
SColor TempColor(0);
E_FOG_TYPE TempType = EFT_FOG_LINEAR;
bool TempPerFragment = false;
bool TempRange = false;
driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange);
FogType = (s32)TempType;
FogColor = SColorf(TempColor);
services->setPixelShaderConstant(FogTypeID, &FogType, 1);
services->setPixelShaderConstant(FogColorID, reinterpret_cast<f32*>(&FogColor), 4);
services->setPixelShaderConstant(FogStartID, &FogStart, 1);
services->setPixelShaderConstant(FogEndID, &FogEnd, 1);
services->setPixelShaderConstant(FogDensityID, &FogDensity, 1);
}
}
core::vector3df COGLES2MaterialBaseCB::LightDirInView(core::matrix4 matrix, core::vector3df vec3_dir)
{
struct _Vec4_T
{
f32 x,y,z,w;
};
struct _Vec4_T vec4_dir;
vec4_dir.x = vec3_dir.X;
vec4_dir.y = vec3_dir.Y;
vec4_dir.z = vec3_dir.Z;
vec4_dir.w = 0.0;
vec4_dir.x = matrix[0*4+0]*vec4_dir.x + matrix[1*4+0]*vec4_dir.y + matrix[2*4+0]*vec4_dir.z; // + matrix[3*4+0]*vec4_dir.w;
vec4_dir.y = matrix[0*4+1]*vec4_dir.x + matrix[1*4+1]*vec4_dir.y + matrix[2*4+1]*vec4_dir.z; // + matrix[3*4+1]*vec4_dir.w;
vec4_dir.z = matrix[0*4+2]*vec4_dir.x + matrix[1*4+2]*vec4_dir.y + matrix[2*4+2]*vec4_dir.z; // + matrix[3*4+2]*vec4_dir.w;
//vec4_dir.w = matrix[0*4+3]*vec4_dir.x + matrix[1*4+3]*vec4_dir.y + matrix[2*4+3]*vec4_dir.z + matrix[3*4+3]*vec4_dir.w; //no need return
return core::vector3df(vec4_dir.x, vec4_dir.y, vec4_dir.z);
}
//ref. https://github.com/daw42/glslcookbook/b ... er/spot.fs
//fixed for direct light and spot light --part two for COGLES2FixedPipelineRenderer.cpp
void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
int MAX_SHADER_LIGHTS;
IVideoDriver* driver = services->getVideoDriver();
if (FirstUpdateBase)
{
WVPMatrixID = services->getVertexShaderConstantID("uWVPMatrix");
WVMatrixID = services->getVertexShaderConstantID("uWVMatrix");
NMatrixID = services->getVertexShaderConstantID("uNMatrix");
MaterialAmbientID = services->getVertexShaderConstantID("uMaterialAmbient");
MaterialDiffuseID = services->getVertexShaderConstantID("uMaterialDiffuse");
MaterialEmissiveID = services->getVertexShaderConstantID("uMaterialEmissive");
MaterialSpecularID = services->getVertexShaderConstantID("uMaterialSpecular");
MaterialShininessID = services->getVertexShaderConstantID("uMaterialShininess");
LightCountID = services->getVertexShaderConstantID("uLightCount");
LightTypeID = services->getVertexShaderConstantID("uLightType");
LightPositionID = services->getVertexShaderConstantID("uLightPosition");
LightDirectionID = services->getVertexShaderConstantID("uLightDirection");
LightAttenuationID = services->getVertexShaderConstantID("uLightAttenuation");
LightAmbientID = services->getVertexShaderConstantID("uLightAmbient");
LightDiffuseID = services->getVertexShaderConstantID("uLightDiffuse");
LightSpecularID = services->getVertexShaderConstantID("uLightSpecular");
FogEnableID = services->getVertexShaderConstantID("uFogEnable");
FogTypeID = services->getVertexShaderConstantID("uFogType");
FogColorID = services->getVertexShaderConstantID("uFogColor");
FogStartID = services->getVertexShaderConstantID("uFogStart");
FogEndID = services->getVertexShaderConstantID("uFogEnd");
FogDensityID = services->getVertexShaderConstantID("uFogDensity");
LightOuterConeID = services->getVertexShaderConstantID("uLightOuterCone");
LightFallOffID = services->getVertexShaderConstantID("uLightFallOff");
FirstUpdateBase = false;
}
const core::matrix4 W = driver->getTransform(ETS_WORLD);
const core::matrix4 V = driver->getTransform(ETS_VIEW);
const core::matrix4 P = driver->getTransform(ETS_PROJECTION);
/*core::matrix4 Matrix = P * V * W;
services->setPixelShaderConstant(WVPMatrixID, Matrix.pointer(), 16);
Matrix = V * W;
services->setPixelShaderConstant(WVMatrixID, Matrix.pointer(), 16);
Matrix.makeInverse();
services->setPixelShaderConstant(NMatrixID, Matrix.getTransposed().pointer(), 16);*/
core::matrix4 Matrix_V;
core::matrix4 Matrix_V_W = V * W;
core::matrix4 Matrix_P_V_W = P * Matrix_V_W;
services->setPixelShaderConstant(WVPMatrixID, Matrix_P_V_W.pointer(), 16);
services->setPixelShaderConstant(WVMatrixID, Matrix_V_W.pointer(), 16);
Matrix_V_W.makeInverse();
services->setPixelShaderConstant(NMatrixID, Matrix_V_W.getTransposed().pointer(), 16);
s32 LightCount = LightEnable ? driver->getDynamicLightCount() : 0;
services->setPixelShaderConstant(LightCountID, &LightCount, 1);
if (LightCount > 0)
{
services->setPixelShaderConstant(MaterialAmbientID, reinterpret_cast<f32*>(&MaterialAmbient), 4);
services->setPixelShaderConstant(MaterialDiffuseID, reinterpret_cast<f32*>(&MaterialDiffuse), 4);
services->setPixelShaderConstant(MaterialEmissiveID, reinterpret_cast<f32*>(&MaterialEmissive), 4);
services->setPixelShaderConstant(MaterialSpecularID, reinterpret_cast<f32*>(&MaterialSpecular), 4);
services->setPixelShaderConstant(MaterialShininessID, &MaterialShininess, 1);
//Matrix = V;
Matrix_V = V;
for (s32 i = 0; i < LightCount; ++i)
{
SLight CurrentLight = driver->getDynamicLight(i);
//Matrix.transformVect(CurrentLight.Position);
Matrix_V.transformVect(CurrentLight.Position);
switch (CurrentLight.Type)
{
case ELT_DIRECTIONAL:
LightType = 2;
//for same as opengl and oges1 use, void COpenGLDriver::assignHardwareLight(u32 lightIndex)
//CurrentLight.Direction = LightDirInView(Matrix_V, CurrentLight.Direction)
CurrentLight.Position = -LightDirInView(Matrix_V, CurrentLight.Direction);
break;
case ELT_SPOT:
LightType = 1;
CurrentLight.Direction = LightDirInView(Matrix_V, CurrentLight.Direction);
break;
default: // ELT_POINT
LightType = 0;
break;
}
LightPosition = CurrentLight.Position;
LightDirection = CurrentLight.Direction;
LightAttenuation = CurrentLight.Attenuation;
LightAmbient = CurrentLight.AmbientColor;
LightDiffuse = CurrentLight.DiffuseColor;
LightSpecular = CurrentLight.SpecularColor;
LightOuterCone = CurrentLight.OuterCone;
LightFallOff[i] = CurrentLight.Falloff;
}
MAX_SHADER_LIGHTS = 8;
services->setPixelShaderConstant(LightTypeID, reinterpret_cast<s32*>(LightType), MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightPositionID, reinterpret_cast<f32*>(LightPosition), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightDirectionID, reinterpret_cast<f32*>(LightDirection), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightAttenuationID,reinterpret_cast<f32*>(LightAttenuation), 3*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightAmbientID, reinterpret_cast<f32*>(LightAmbient), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightDiffuseID, reinterpret_cast<f32*>(LightDiffuse), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightSpecularID, reinterpret_cast<f32*>(LightSpecular), 4*MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightOuterConeID, reinterpret_cast<f32*>(LightOuterCone), MAX_SHADER_LIGHTS);
services->setPixelShaderConstant(LightFallOffID, reinterpret_cast<f32*>(LightFallOff), MAX_SHADER_LIGHTS);
}
services->setPixelShaderConstant(FogEnableID, &FogEnable, 1);
if (FogEnable)
{
SColor TempColor(0);
E_FOG_TYPE TempType = EFT_FOG_LINEAR;
bool TempPerFragment = false;
bool TempRange = false;
driver->getFog(TempColor, TempType, FogStart, FogEnd, FogDensity, TempPerFragment, TempRange);
FogType = (s32)TempType;
FogColor = SColorf(TempColor);
services->setPixelShaderConstant(FogTypeID, &FogType, 1);
services->setPixelShaderConstant(FogColorID, reinterpret_cast<f32*>(&FogColor), 4);
services->setPixelShaderConstant(FogStartID, &FogStart, 1);
services->setPixelShaderConstant(FogEndID, &FogEnd, 1);
services->setPixelShaderConstant(FogDensityID, &FogDensity, 1);
}
}
core::vector3df COGLES2MaterialBaseCB::LightDirInView(core::matrix4 matrix, core::vector3df vec3_dir)
{
struct _Vec4_T
{
f32 x,y,z,w;
};
struct _Vec4_T vec4_dir;
vec4_dir.x = vec3_dir.X;
vec4_dir.y = vec3_dir.Y;
vec4_dir.z = vec3_dir.Z;
vec4_dir.w = 0.0;
vec4_dir.x = matrix[0*4+0]*vec4_dir.x + matrix[1*4+0]*vec4_dir.y + matrix[2*4+0]*vec4_dir.z; // + matrix[3*4+0]*vec4_dir.w;
vec4_dir.y = matrix[0*4+1]*vec4_dir.x + matrix[1*4+1]*vec4_dir.y + matrix[2*4+1]*vec4_dir.z; // + matrix[3*4+1]*vec4_dir.w;
vec4_dir.z = matrix[0*4+2]*vec4_dir.x + matrix[1*4+2]*vec4_dir.y + matrix[2*4+2]*vec4_dir.z; // + matrix[3*4+2]*vec4_dir.w;
//vec4_dir.w = matrix[0*4+3]*vec4_dir.x + matrix[1*4+3]*vec4_dir.y + matrix[2*4+3]*vec4_dir.z + matrix[3*4+3]*vec4_dir.w; //no need return
return core::vector3df(vec4_dir.x, vec4_dir.y, vec4_dir.z);
}
Last edited by feelthat on Thu Feb 12, 2015 12:11 am, edited 3 times in total.
Re: Fixed pipeline emulation in OpenGL ES 2.0
@feelthat: I appreciate that you post code. But please also talk and explain what this is about. Is this code to show what you are working at? Or is it something you want us to add to the engine? Or do you want us to replace an engine shader by it?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm