Hi everyone, in this project im trying to make game like a Subway Surf, Angry granny, etc. i’ve done with the logic and here what the games look like.
and now, i try to make at the end of road looks slighty curve just look like subway surf
to make it happen, im using a custom shader. and finally at the end of my road has become slighty curve just like in subway surve. But, my 3D texture gone wrong just like this.
Below how do i make a shader and apply it to 3D object.
vertex file.vert
uniform float u_bound;
uniform float u_farplane;
uniform vec4 u_cam;
uniform vec4 u_color;
uniform mat4 u_MVPMatrix;
attribute vec4 a_position;
attribute vec2 a_texCoord;
varying vec2 v_texture_coord;
void main(void)
{
vec4 real_pos = u_MVPMatrix * a_position;
gl_Position = real_pos;
}
Frag file.frag
#ifdef GL_ES
varying mediump vec2 v_texture_coord;
#else
varying vec2 v_texture_coord;
#endif
varying float v_shade;
uniform sampler2D u_sampler0;
uniform vec4 u_color;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
vec4 blur(vec2);
uniform vec4 u_Time;
void main (void)
{
gl_FragColor = texture2D(u_sampler0, v_texture_coord);
}
SceneGame.cpp
#define SET_UNIFORM(ps, name, value) do { \
decltype(value) __v = value; \
auto __loc = (ps)->getUniformLocation(name); \
(ps)->setUniform(__loc, &__v, sizeof(__v)); \
} while(false)
bool SceneGame::init()
{
float shaderBound = 5100;
float shaderFarPlane = 4 * 5100;
auto vertexSource = FileUtils::getInstance()->getStringFromFile("shaders/3D_curvature.vert");
auto fragSource = FileUtils::getInstance()->getStringFromFile("shaders/3D_texture.frag");
auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource);
_programState = new backend::ProgramState(program);
SET_UNIFORM(_programState, "u_bound", shaderBound);
SET_UNIFORM(_programState, "u_farplane", shaderFarPlane);
// EXAMPLE
for(auto data : vecData3D)
{
auto spr3DRoad = Sprite3D::create(data.path3D);
this->addChild(spr3DRoad);
addShaderCurve(spr3DRoad)
}
}
void SceneGame::addShaderCurve(Sprite3D* spr)
{
for(auto Mesh : spr->getMeshes())
{
Mesh->setProgramState(_programState);
}
}
Anyone can help me ? i’ve try to search but still no clue. Please if you have any thought or solution let me know. Thanks !
Note: Im using cocos2dx-v4