PDA

View Full Version : water effect work on ogles 2.0 again



feelthat
02-07-2015, 11:45 AM
in example 8

mesh = 0;//smgr->addHillPlaneMesh( "myHill",
// core::dimension2d<f32>(20,20),
// core::dimension2d<u32>(40,40), 0, 0,
// core::dimension2d<f32>(0,0),
// core::dimension2d<f32>(10,10));

I try the water effect in OGLES2.0 good in ios 7.1 emulator

so i enable the effect again

please add stones.jpg and water.jpg in bin/game/ directory

https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225/6113068605573837074?banner=pwa&pid=6113068605573837074&oid=106185541018774360364

download site
https://github.com/fatalfeel/proton_sdk_source

feelthat
02-09-2015, 07:08 AM
https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225/6113738197506253266?banner=pwa&pid=6113738197506253266&oid=106185541018774360364

today successful on android and ios


Heil Proton
Heil Proton
Heil Proton

all demo here
https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225


in example 8

mesh = 0;//smgr->addHillPlaneMesh( "myHill",
// core::dimension2d<f32>(20,20),
// core::dimension2d<u32>(40,40), 0, 0,
// core::dimension2d<f32>(0,0),
// core::dimension2d<f32>(10,10));

I try the water effect in OGLES2.0 good in ios 7.1 emulator

so i enable the effect again

please add stones.jpg and water.jpg in bin/game/ directory

https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225/6113068605573837074?banner=pwa&pid=6113068605573837074&oid=106185541018774360364

download site
https://github.com/fatalfeel/proton_sdk_source

feelthat
02-11-2015, 05:17 PM
https://code.google.com/p/jpcsp/source/browse/trunk/src/jpcsp/graphics/shader.vert?r=1639

i will follow above code to add spot light


https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225/6113738197506253266?banner=pwa&pid=6113738197506253266&oid=106185541018774360364

today successful on android and ios


Heil Proton
Heil Proton
Heil Proton

all demo here
https://plus.google.com/photos/106185541018774360364/albums/5964765088859640225

feelthat
02-11-2015, 05:27 PM
add spot light today in ogles2!!!

the way to use spot and directional light

SLight spotLightData;
ILightSceneNode* scnode = smgr->addLightSceneNode(0, core::vector3df(0,5,20), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 100.0f, -1);

spotLightData = scnode->getLightData();

spotLightData.Type = video::ELT_DIRECTIONAL;
spotLightData.Direction = core::vector3df(0,0.3,1);
spotLightData.Falloff = 60.0f;
spotLightData.OuterCone = 20;
scnode->setLightData(spotLightData);

feelthat
02-12-2015, 12:56 PM
Matrix_V.transformVect(CurrentLight.Position) = vce3( ViewMatrix * vec4(CurrentLight.Position,1)) -> get xyz

LightDirInView(Matrix_V, CurrentLight.Direction) = Matrix_V.rotateVect( CurrentLight.Direction )
=> vec3(ViewMatrix * vec4(CurrentLight.Direction, 0)) ->get xyz

Homogeneous coordinates

Until then, we only considered 3D vertices as a (x,y,z) triplet. Let’s introduce w. We will now have (x,y,z,w) vectors.

This will be more clear soon, but for now, just remember this :

If w == 1, then the vector (x,y,z,1) is a position in space.
If w == 0, then the vector (x,y,z,0) is a direction.

ref. http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

- - - Updated - - -

//faster for spot light in GLSL

void CLightSceneNode::setLightData(const video::SLight& light)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();

LightData = light;

if( driver->getDriverType() == video::EDT_OGLES2 )
{
LightData.OuterCone = (float)cos(LightData.OuterCone * 3.141615926 / 180.0f);
LightData.InnerCone = (float)cos(LightData.InnerCone * 3.141615926 / 180.0f);
}
}

//then in vsh

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])))
if (spotEffect >= uLightOuterCone[index] ) //-->simplize
{
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);
.
.
.
}
}

feelthat
02-12-2015, 01:10 PM
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-> vec3(Vmatrix*vec4(Position, 1))
//Matrix_V.rotateVect -> vec3(Vmatrix*vec4(Direction,0))
switch (CurrentLight.Type)
{
case ELT_DIRECTIONAL:
LightType[i] = 2;
//put on Position, for the same use as opengl and oges1
Matrix_V.rotateVect(-CurrentLight.Position, CurrentLight.Direction);
break;
case ELT_SPOT:
LightType[i] = 1;
Matrix_V.transformVect(CurrentLight.Position);
Matrix_V.rotateVect(CurrentLight.Direction);
CurrentLight.Direction = LightDirInView(Matrix_V, CurrentLight.Direction);
break;
default: // ELT_POINT
Matrix_V.transformVect(CurrentLight.Position);
LightType[i] = 0;
break;
}

LightPosition[i] = CurrentLight.Position;
LightDirection[i] = CurrentLight.Direction;
LightAttenuation[i] = CurrentLight.Attenuation;
LightAmbient[i] = CurrentLight.AmbientColor;
LightDiffuse[i] = CurrentLight.DiffuseColor;
LightSpecular[i] = CurrentLight.SpecularColor;
LightOuterCone[i] = 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,reinterp ret_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);
}



Matrix_V.transformVect(CurrentLight.Position) = vce3( ViewMatrix * vec4(CurrentLight.Position,1)) -> get xyz

LightDirInView(Matrix_V, CurrentLight.Direction) = Matrix_V.rotateVect( CurrentLight.Direction )
=> vec3(ViewMatrix * vec4(CurrentLight.Direction, 0)) ->get xyz

Homogeneous coordinates

Until then, we only considered 3D vertices as a (x,y,z) triplet. Let’s introduce w. We will now have (x,y,z,w) vectors.

This will be more clear soon, but for now, just remember this :

If w == 1, then the vector (x,y,z,1) is a position in space.
If w == 0, then the vector (x,y,z,0) is a direction.

ref. http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

- - - Updated - - -

//faster for spot light in GLSL

void CLightSceneNode::setLightData(const video::SLight& light)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();

LightData = light;

if( driver->getDriverType() == video::EDT_OGLES2 )
{
LightData.OuterCone = (float)cos(LightData.OuterCone * 3.141615926 / 180.0f);
LightData.InnerCone = (float)cos(LightData.InnerCone * 3.141615926 / 180.0f);
}
}

//then in vsh

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])))
if (spotEffect >= uLightOuterCone[index] ) //-->simplize
{
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);
.
.
.
}
}