light work

This commit is contained in:
yangxiao 2014-09-11 15:46:32 +08:00
parent e849b997ed
commit df9ab144fe
6 changed files with 54 additions and 48 deletions

View File

@ -2772,6 +2772,9 @@
B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = "<group>"; };
B609E64C19C136F9003D0074 /* CCLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCLight.cpp; sourceTree = "<group>"; };
B609E64D19C136F9003D0074 /* CCLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCLight.h; sourceTree = "<group>"; };
B609E65C19C17FF0003D0074 /* ccShader_3D_ColorNormal.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorNormal.frag; sourceTree = "<group>"; };
B609E65D19C17FF0003D0074 /* ccShader_3D_ColorNormalTex.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorNormalTex.frag; sourceTree = "<group>"; };
B609E65E19C17FF0003D0074 /* ccShader_3D_PositionNormalTex.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_PositionNormalTex.vert; sourceTree = "<group>"; };
ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -4446,6 +4449,9 @@
5034CA5D191D591900CE6051 /* shaders */ = {
isa = PBXGroup;
children = (
B609E65C19C17FF0003D0074 /* ccShader_3D_ColorNormal.frag */,
B609E65D19C17FF0003D0074 /* ccShader_3D_ColorNormalTex.frag */,
B609E65E19C17FF0003D0074 /* ccShader_3D_PositionNormalTex.vert */,
B29594AF1926D5D9003EEF37 /* ccShader_3D_Color.frag */,
B29594B01926D5D9003EEF37 /* ccShader_3D_ColorTex.frag */,
B29594B11926D5D9003EEF37 /* ccShader_3D_PositionTex.vert */,

View File

@ -18,7 +18,7 @@ Light3D::~Light3D()
Light3D* Light3D::createDirectionalLight( const Vec3 &direction, const Color3B &color )
{
Light3D *light = new Light3D;
light->_lightType = DIRECTIONAL;
light->_lightType = Light3D::LightType::DIRECTIONAL;
light->calculateRotation(direction);
light->setColor(color);
light->autorelease();
@ -28,7 +28,7 @@ Light3D* Light3D::createDirectionalLight( const Vec3 &direction, const Color3B &
Light3D* Light3D::createPointLight( const Vec3 &position, const Color3B &color, float range )
{
Light3D *light = new Light3D;
light->_lightType = POINT;
light->_lightType = Light3D::LightType::POINT;
light->setPosition3D(position);
light->setColor(color);
light->_range = range;
@ -39,7 +39,7 @@ Light3D* Light3D::createPointLight( const Vec3 &position, const Color3B &color,
Light3D* Light3D::createSpotLight( const Vec3 &direction, const Vec3 &position, const Color3B &color, float innerAngle, float outerAngle, float range )
{
Light3D *light = new Light3D;
light->_lightType = SPOT;
light->_lightType = Light3D::LightType::SPOT;
light->calculateRotation(direction);
light->setPosition3D(position);
light->setColor(color);

View File

@ -26,14 +26,15 @@
#define __CCLIGHT_H__
#include "2d/CCNode.h"
#include "3d/3dExport.h"
NS_CC_BEGIN
class CC_DLL Light3D : public Node
class CC_3D_DLL Light3D : public Node
{
public:
enum LightType
enum class LightType
{
DIRECTIONAL = 0,
POINT = 1,

View File

@ -989,7 +989,7 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
{
col = Color3B::BLACK;
}
if (light->getLightType() == Light3D::DIRECTIONAL)
if (light->getLightType() == Light3D::LightType::DIRECTIONAL)
{
CCASSERT(enabledDirLightNum < CC_MAX_DIRECTIONAL_LIGHT_NUM, "");
Vec3 dir = light->getWorldDirection();
@ -1000,8 +1000,7 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
setUniformLocationWith3f(glGetUniformLocation(_program, str), dir.x, dir.y, dir.z);
++enabledDirLightNum;
}
else
if (light->getLightType() == Light3D::POINT)
else if (light->getLightType() == Light3D::LightType::POINT)
{
CCASSERT(enabledPointLightNum < CC_MAX_POINT_LIGHT_NUM, "");
Mat4 mat= light->getNodeToWorldTransform();

View File

@ -58,13 +58,13 @@ LightTestDemo::LightTestDemo()
TTFConfig ttfConfig("fonts/arial.ttf", 15);
_directionalLightLabel = Label::createWithTTF(ttfConfig,"Directional Light ON");
_directionalLightLabel->retain();
auto menuItem1 = MenuItemLabel::create(_directionalLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::DIRECTIONAL));
auto menuItem1 = MenuItemLabel::create(_directionalLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::LightType::DIRECTIONAL));
_pointLightLabel = Label::createWithTTF(ttfConfig,"Point Light OFF");
_pointLightLabel->retain();
auto menuItem2 = MenuItemLabel::create(_pointLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::POINT));
auto menuItem2 = MenuItemLabel::create(_pointLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::LightType::POINT));
_spotLightLabel = Label::createWithTTF(ttfConfig,"Spot Light OFF");
_spotLightLabel->retain();
auto menuItem3 = MenuItemLabel::create(_spotLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::SPOT));
auto menuItem3 = MenuItemLabel::create(_spotLightLabel, CC_CALLBACK_1(LightTestDemo::SwitchLight,this,Light3D::LightType::SPOT));
auto menu = Menu::create(menuItem1,menuItem2,menuItem3,NULL);
menu->setPosition(Vec2::ZERO);
menuItem1->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
@ -205,18 +205,18 @@ void LightTestDemo::addSprite()
void LightTestDemo::addLights()
{
auto s = Director::getInstance()->getWinSize();
_directionalLight = Light3D::CreateDirectionalLight(Vec3(-1.0f, -1.0f, 0.0f), Color3B(200, 200, 200));
_directionalLight = Light3D::createDirectionalLight(Vec3(-1.0f, -1.0f, 0.0f), Color3B(200, 200, 200));
_directionalLight->retain();
addChild(_directionalLight);
_directionalLight->setCameraMask(2);
_pointLight = Light3D::CreatePointLight(Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 10000.0f);
_pointLight = Light3D::createPointLight(Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 10000.0f);
_pointLight->retain();
_pointLight->setEnabled(false);
addChild(_pointLight);
_pointLight->setCameraMask(2);
_spotLight = Light3D::CreateSpotLight(Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 0.0, 0.5, 10000.0f);
_spotLight = Light3D::createSpotLight(Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 0.0, 0.5, 10000.0f);
_spotLight->retain();
_spotLight->setEnabled(false);
addChild(_spotLight);
@ -280,7 +280,7 @@ void LightTestDemo::SwitchLight( Ref* sender,Light3D::LightType lightType )
{
switch (lightType)
{
case Light3D::DIRECTIONAL:
case Light3D::LightType::DIRECTIONAL:
{
char str[32];
bool isON = !_directionalLight->getEnabled();
@ -290,7 +290,7 @@ void LightTestDemo::SwitchLight( Ref* sender,Light3D::LightType lightType )
}
break;
case Light3D::POINT:
case Light3D::LightType::POINT:
{
char str[32];
bool isON = !_pointLight->getEnabled();
@ -300,7 +300,7 @@ void LightTestDemo::SwitchLight( Ref* sender,Light3D::LightType lightType )
}
break;
case Light3D::SPOT:
case Light3D::LightType::SPOT:
{
char str[32];
bool isON = !_spotLight->getEnabled();

View File

@ -552,7 +552,7 @@ void Effect3DOutline::draw(const Mat4 &transform)
_glProgramState->apply(transform);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->getIndexBuffer());
glDrawElements(mesh->getPrimitiveType(), mesh->getIndexCount(), mesh->getIndexFormat(), 0);
glDrawElements(mesh->getPrimitiveType(), (GLsizei)mesh->getIndexCount(), mesh->getIndexFormat(), 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, mesh->getIndexCount());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);