// Scene doesn't use both of point and directional light\r
NONE = 0,\r
// Scene use point light\r
- POINT_LIGHT,\r
+ POINT_LIGHT = 1,\r
// Scene use directional light\r
- DIRECTIONAL_LIGHT,\r
- // Scene use Image Based Lighting\r
- IMAGE_BASED_LIGHT,\r
- // Scene use Image Based Lighting and point light\r
- IMAGE_BASED_LIGHT_AND_POINT_LIGHT,\r
- // Scene use Image Based Lighting and directional light\r
- IMAGE_BASED_LIGHT_AND_DIRECTIONAL_LIGHT\r
+ DIRECTIONAL_LIGHT = 2\r
};\r
\r
/**\r
VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data();
FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data();
- bool useIBL = (scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT);
+ bool useIBL = scene3dView.HasImageBasedLighting();
if(isMaterial)
{
MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
actor.RotateBy(orientation);
actor.SetProperty(Actor::Property::POSITION, translation);
- shader.RegisterProperty("uLightType", (scene3dView.GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT));
+ float hasLightSource = static_cast<float>(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)));
+ float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
+ shader.RegisterProperty("uHasLightSource", hasLightSource);
+ shader.RegisterProperty("uIsPointLight", isPointLight);
shader.RegisterProperty("uLightVector", scene3dView.GetLightVector());
shader.RegisterProperty("uLightColor", scene3dView.GetLightColor());
- actor.RegisterProperty("uIsColor", meshInfo.attribute.COLOR.size() > 0);
+ actor.RegisterProperty("uHasVertexColor", meshInfo.attribute.COLOR.size() > 0 ? 1.0f : 0.0f);
if(isMaterial)
{
MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
if(materialInfo.alphaMode == "OPAQUE")
{
- actor.RegisterProperty("alphaMode", 0);
+ actor.RegisterProperty("uAlphaMode", 0.0f);
}
else if(materialInfo.alphaMode == "MASK")
{
- actor.RegisterProperty("alphaMode", 1);
+ actor.RegisterProperty("uAlphaMode", 1.0f);
}
else
{
- actor.RegisterProperty("alphaMode", 2);
+ actor.RegisterProperty("uAlphaMode", 2.0f);
}
actor.RegisterProperty("alphaCutoff", materialInfo.alphaCutoff);
mAnimationArray(),
mLightType(Toolkit::Scene3dView::LightType::NONE),
mLightVector(Vector3::ONE),
- mLightColor(Vector3::ONE)
+ mLightColor(Vector3::ONE),
+ mUseIBL(false)
{
}
bool Scene3dView::SetLight(Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor)
{
- if(type > Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)
- {
- return false;
- }
-
- mLightType = static_cast<Toolkit::Scene3dView::LightType>(
- (mLightType >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT) ? Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT + type : type);
-
+ mLightType = type;
mLightVector = lightVector;
mLightColor = lightColor;
for(auto&& shader : mShaderArray)
{
- shader.RegisterProperty("uLightType", (GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT));
+ float hasLightSource = static_cast<float>(!!(GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)));
+ float isPointLight = static_cast<float>(!!(GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
+ shader.RegisterProperty("uHasLightSource", hasLightSource);
+ shader.RegisterProperty("uIsPointLight", isPointLight);
shader.RegisterProperty("uLightVector", lightVector);
shader.RegisterProperty("uLightColor", lightColor);
}
void Scene3dView::SetCubeMap(const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor)
{
- mLightType = Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT;
-
// BRDF texture
const std::string imageDirPath = AssetManager::GetDaliImagePath();
const std::string imageBrdfUrl = imageDirPath + IMAGE_BRDF_FILE_NAME;
mSpecularTexture.GenerateMipmaps();
mIBLScaleFactor = scaleFactor;
+ mUseIBL = true;
}
bool Scene3dView::SetDefaultCamera(const Dali::Camera::Type type, const float nearPlane, const Vector3 cameraPosition)
return mSpecularTexture;
}
+bool Scene3dView::HasImageBasedLighting()
+{
+ return mUseIBL;
+}
+
Texture Scene3dView::GetDiffuseTexture()
{
return mDiffuseTexture;
*/\r
Texture GetSpecularTexture();\r
\r
+ /**\r
+ * @brief Get whether the scene has image based rendering or not.\r
+ */\r
+ bool HasImageBasedLighting();\r
+\r
private:\r
/**\r
* @brief Get Cropped image buffer.\r
Texture mBRDFTexture; // BRDF texture for the PBR rendering\r
Texture mSpecularTexture; // Specular cube map texture\r
Texture mDiffuseTexture; // Diffuse cube map texture\r
+ bool mUseIBL;\r
\r
private:\r
// Undefined copy constructor.\r
uniform lowp vec3 uLightColor;
uniform lowp vec4 uBaseColorFactor;
uniform lowp vec2 uMetallicRoughnessFactors;
-uniform lowp int alphaMode;
uniform lowp float alphaCutoff;
+uniform lowp float uAlphaMode;
+uniform lowp float uHasLightSource;
in lowp vec2 vUV[2];
in lowp mat3 vTBN;
in lowp vec4 vColor;
-flat in int visLight;
in highp vec3 vLightDirection;
in highp vec3 vPositionToCamera;
vec3 getNormal()
{
#ifdef TEXTURE_NORMAL
- lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;
- n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );
+ lowp vec3 n = texture(uNormalSampler, vUV[uNormalTexCoordIndex]).rgb;
+ n = normalize(vTBN * ((2.0 * n - 1.0) * vec3(uNormalScale, uNormalScale, 1.0)));
#else
lowp vec3 n = normalize( vTBN[2].xyz );
#endif
return n;
}
-vec3 specularReflection( PBRInfo pbrInputs )
+vec3 specularReflection(PBRInfo pbrInputs)
{
- return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );
+ return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
}
-float geometricOcclusion( PBRInfo pbrInputs )
+float geometricOcclusion(PBRInfo pbrInputs)
{
mediump float NdotL = pbrInputs.NdotL;
mediump float NdotV = pbrInputs.NdotV;
return roughnessSq / (M_PI * f * f);
}
-vec3 linear( vec3 color )
+vec3 linear(vec3 color)
{
return pow(color,vec3(2.2));
}
lowp vec4 baseColor = vColor * uBaseColorFactor;
#endif
- if( alphaMode == 0 )
+ if(uAlphaMode < 0.5f)
{
baseColor.w = 1.0;
}
- else if( alphaMode == 1 )
+ else if(uAlphaMode < 1.5f)
{
- if( baseColor.w >= alphaCutoff )
+ if(baseColor.w >= alphaCutoff)
{
baseColor.w = 1.0;
}
// Calculate the shading terms for the microfacet specular shading model
lowp vec3 color = vec3(0.0);
- if( visLight == 1 )
+ if( uHasLightSource > 0.5f )
{
lowp vec3 F = specularReflection( pbrInputs );
lowp float G = geometricOcclusion( pbrInputs );
uniform mediump mat4 uModelMatrix;
uniform mediump mat4 uViewMatrix;
uniform mediump mat4 uProjection;
-uniform lowp int uLightType;
uniform mediump vec3 uLightVector;
-uniform lowp int uIsColor;
+uniform lowp float uIsPointLight;
+uniform lowp float uHasVertexColor;
out lowp vec2 vUV[2];
out lowp mat3 vTBN;
out lowp vec4 vColor;
-flat out int visLight;
out highp vec3 vLightDirection;
out highp vec3 vPositionToCamera;
void main()
{
highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);
- highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );
- highp vec4 positionV = uViewMatrix * ( invY * positionW );
+ highp vec4 positionW = uModelMatrix * vec4(aPosition * uSize, 1.0);
+ highp vec4 positionV = uViewMatrix * (invY * positionW);
- vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );
+ vPositionToCamera = transpose(mat3(uViewMatrix)) * (-vec3(positionV.xyz / positionV.w));
vPositionToCamera *= invY.xyz;
lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;
- vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);
+ vTBN = mat3(uModelMatrix) * mat3(aTangent.xyz, bitangent, aNormal);
vUV[0] = aTexCoord0;
vUV[1] = aTexCoord1;
- visLight = 1;
- if( uLightType == 1 )
- {
- vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );
- }
- else if( uLightType == 2 )
- {
- vLightDirection = -( invY.xyz * uLightVector );
- }
- else
- {
- visLight = 0;
- }
-
- vColor = vec4( 1.0 );
- if( uIsColor == 1 )
- {
- vColor = aVertexColor;
- }
+ vLightDirection = mix(-(invY.xyz * uLightVector), (invY.xyz * uLightVector) - (positionW.xyz / positionW.w), uIsPointLight);
+
+ vColor = mix(vec4(1.0f), aVertexColor, uHasVertexColor);
gl_Position = uProjection * positionV; // needs w for proper perspective correction
gl_Position = gl_Position/gl_Position.w;