Пример #1
0
GLuint createAtmosphereDisplayList()
{
	GLuint dispList= glGenLists(1);
	const int ResoV = 12, ResoH = 12;
	glNewList(dispList, GL_COMPILE);
		for(int j=-ResoV; j<ResoV-1; j++){
			float y1 = float(j) / float(ResoV-1);
			float y2 = float(j+1) / float(ResoV-1);
			float r1 = 1.f - y1 * y1;
			float r2 = 1.f - y2 * y2;
			Vector c1 = skyColor(y1);
			Vector c2 = skyColor(y2);
			glBegin(GL_QUAD_STRIP);
			for(int i=0; i<ResoH; i++){
				float x = cosf(i * 2 * Pi / (ResoH-1));
				float z = sinf(i * 2 * Pi / (ResoH-1));
				glColor(c1);
				glVertex3f(x*r1, y1, z*r1);
				glColor(c2);
				glVertex3f(x*r2, y2, z*r2);
			}
			glEnd();
		}
	glEndList();
	return dispList;
}
Пример #2
0
skyResult skyGfxDebugTriangleObject::Spawn (sGfxVector4& a_sPosition, sGfxColor& a_sColor
										, skyIGfxShader* a_pShader, skyGfxDebugTriangleObject** a_pTriangle )
{
	if(!a_pShader)
		return SKY_INVALID_POINTER;

	skyResult hr;
	skyIGfxVertexBuffer* pVBuffer = nullptr;

	sGfxVertexDesc VertexDesc;
	SKY_ZERO_MEM(&VertexDesc, sizeof(sGfxVertexDesc));
	VertexDesc.m_uiCount = 3;
	VertexDesc.m_uiSize = sizeof(sGfxDebugVertex);
	VertexDesc.m_eUsage = eGfxUsage_Dynamic;
	VertexDesc.m_eCPUAccess = eGfxCpuAccessFlags_Write;
	
	sGfxDrawDesc DrawDesc;
	SKY_ZERO_MEM(&DrawDesc, sizeof(sGfxDrawDesc));
	DrawDesc.m_bInstanced = SKY_FALSE;
	DrawDesc.m_ePrimitiveType = eGfxPrimitiveType_TriangleList;
	DrawDesc.m_uiIndexCount = 0;
	DrawDesc.m_uiInstanceCount = 0;
	DrawDesc.m_uiVertexCount = 3;
	DrawDesc.m_uiVertexLocation = 0;

	sGfxDebugVertex arrVertices[] = {
		{skyVector3(0.0f, 0.5f, 0.0f), skyColor(1.0f, 0.0f, 0.0f, 1.0f).ToVector4()},
		{skyVector3(0.45f, -0.5, 0.0f), skyColor(1.0f, 0.0f, 0.0f, 1.0f).ToVector4()},
		{skyVector3(-0.45f, -0.5f, 0.0f), skyColor(1.0f, 0.0f, 0.0f, 1.0f).ToVector4()}
	};

	SKY_VR(skyGfxManager::CreateVertexBuffer(&pVBuffer, VertexDesc));
	
	sGfxLockedBuffer LockedBuffer;
	SKY_ZERO_MEM(&LockedBuffer, sizeof(sGfxLockedBuffer));

	SKY_VR(pVBuffer->Lock(eGfxMapType_WriteDiscard, eGfxMapFlag_DoNotWait, &LockedBuffer));
	memcpy(LockedBuffer.m_pData, arrVertices, sizeof(sGfxDebugVertex) * 3); 
	pVBuffer->Unlock(LockedBuffer.m_uiSubresource);
	pVBuffer->SetStride(sizeof(sGfxDebugVertex));

	skyGfxDebugTriangleObject* pTriangle = SKY_NEW skyGfxDebugTriangleObject(a_pShader, pVBuffer, DrawDesc);
	if(!pTriangle)
		return SKY_OUT_OF_MEMORY;

	// submit the renderobject!
	SKY_SUBMIT_RENDEROBJ((skyUInt)eGfxRenderSortId_Debug, (skyUInt)0, &skyGfxDebugTriangleObject::skyDebugCallDrawMethod, (skyVoid*)pTriangle);

	*a_pTriangle = pTriangle;



	return SKY_OK;
}
Пример #3
0
void setLightsBasedOnDayTime(void)
{
	//On active la light 0
	glEnable(GL_LIGHT0);

	//On recup la direciton du soleil
	bool nuit = getSunDirection(g_sun_dir, g_mn_lever, g_mn_coucher);

	//On définit une lumière directionelle (un soleil)
	float position[4] = { g_sun_dir.X,g_sun_dir.Y,g_sun_dir.Z,0 }; ///w = 0 donc c'est une position a l'infini
	glLightfv(GL_LIGHT0, GL_POSITION, position);

	//Pendant la journée
	if (!nuit)
	{
		//On definit la couleur
		NYColor sunColor(1, 1, 0.8, 1);
		NYColor skyColor(0, 181.f / 255.f, 221.f / 255.f, 1);
		NYColor downColor(0.9, 0.5, 0.1, 1);
		sunColor = sunColor.interpolate(downColor, (abs(g_sun_dir.X)));
		skyColor = skyColor.interpolate(downColor, (abs(g_sun_dir.X)));

		g_renderer->setBackgroundColor(skyColor);

		float color[4] = { sunColor.R,sunColor.V,sunColor.B,1 };
		glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
		float color2[4] = { sunColor.R,sunColor.V,sunColor.B,1 };
		glLightfv(GL_LIGHT0, GL_AMBIENT, color2);
		g_sun_color = sunColor;
	}
	else
	{
		//La nuit : lune blanche et ciel noir
		NYColor sunColor(1, 1, 1, 1);
		NYColor skyColor(0, 0, 0, 1);
		g_renderer->setBackgroundColor(skyColor);

		float color[4] = { sunColor.R / 3.f,sunColor.V / 3.f,sunColor.B / 3.f,1 };
		glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
		float color2[4] = { sunColor.R / 7.f,sunColor.V / 7.f,sunColor.B / 7.f,1 };
		glLightfv(GL_LIGHT0, GL_AMBIENT, color2);
		g_sun_color = sunColor;
	}
}
Пример #4
0
skyVoid skyGfxDefaultTechnique::Begin() 
{ 
	m_sTask.m_uiPassCount = 0;
	
	// final rendering!
	_ADD_PASS(skySetRenderTargetPass(0, skyGfxManager::BackBufferRT()));
	_ADD_PASS(skyClearRenderTargetPass(0, skyColor(0.0f, 0.2f, 0.4f, 1.0f)));
	_ADD_PASS(skyUpdatePerspectiveCamPass());
	_ADD_PASS(skyRenderDynStaticPass());

	__super::Begin();
}
Пример #5
0
skyResult skyMaterialResource::OnRequestRawData(sIOMemBlob& a_rMemBlob)
{
	OnCacheOut ();
	skyAnsiStr pContent = skyGetDataFromBlob<skyAnsiStr>(a_rMemBlob);
	if(!pContent)
		return SKY_ERROR;

	rapidjson::Document mDocument;
    mDocument.Parse<0>(pContent);

	if(mDocument.HasParseError())
	{
		SKY_PRINT_CONSOLE("skyMaterialResource", "Couldn't load material file [ " + this->m_strFileName + " ].", 0x0F);
		SKY_WARNING(0, "skyMaterialResource: Couldn't load material file [ " + this->m_strFileName + " ].");

		return SKY_ERROR;
	}

	if(!mDocument["Name"].IsString())
	{
		SKY_PRINT_CONSOLE("skyMaterialResource", "Material[ " + this->m_strFileName + " ] has no name tag.", 0x0F);
		SKY_WARNING(0, "skyMaterialResource: Material[ " + this->m_strFileName + " ] has no name tag.");

		return SKY_ERROR;
	}

	const rapidjson::Value& mParameter = mDocument["Parameters"];
	if(!mParameter.IsObject())
	{
		SKY_PRINT_CONSOLE("skyMaterialResource", "Material[ " + this->m_strFileName + " ] has no parameter tag.", 0x0F);
		SKY_WARNING(0, "skyMaterialResource: Material[ " + this->m_strFileName + " ] has no parameter tag.");

		return SKY_ERROR;
	}

	skyUInt i = 0;
	// ------------------------------------------------
	// Set Diffuse
	// ------------------------------------------------
	if(!mParameter["Diffuse"].IsObject())
	{
		SKY_PRINT_CONSOLE("skyMaterialResource", "Material[ " + this->m_strFileName + " ] has no diffuse tag.", 0x0F);
		SKY_WARNING(0, "skyMaterialResource: Material[ " + this->m_strFileName + " ] has no diffuse tag.");

		return SKY_ERROR;
	}

	
	// SET COLOR!
	if(!mParameter["Diffuse"]["Color"].IsArray()) 
	{
		SKY_PRINT_CONSOLE("skyMaterialResource", "Material[ " + this->m_strFileName + " ] has no diffuse color tag.", 0x0F);
		SKY_WARNING(0, "skyMaterialResource: Material[ " + this->m_strFileName + " ] has no diffuse  color tag.");
		return SKY_ERROR;
	}

	const rapidjson::Value& diffuseColorNode = mParameter["Diffuse"]["Color"];
	if(diffuseColorNode.Size() < 4)
		return SKY_ERROR;

	i = 0;
	this->m_sDiffuseColor = skyColor((float)diffuseColorNode[i].GetDouble(), (float)diffuseColorNode[++i].GetDouble(), 
										(float)diffuseColorNode[++i].GetDouble(), (float)diffuseColorNode[++i].GetDouble());

	// SET DIFFUSE MAP!
	if(!mParameter["Diffuse"]["Texture"].IsObject())
		return SKY_ERROR;

	if(!mParameter["Diffuse"]["Texture"]["File"].IsString())
		return SKY_ERROR;

	const rapidjson::Value& diffuseTextureNode = mParameter["Diffuse"]["Texture"]["File"];

	// Set Intensity
	if(!mParameter["Diffuse"]["Intensity"].IsDouble())
		return SKY_ERROR;

	this->m_fDiffuseIntensity = (float)mParameter["Diffuse"]["Intensity"].GetDouble();


	// ------------------------------------------------
	// Set Specular
	// ------------------------------------------------
	if(!mParameter["Specular"].IsObject())
		return SKY_ERROR;

	// SET COLOR!
	if(!mParameter["Specular"]["Color"].IsArray())
		return SKY_ERROR;

	const rapidjson::Value& specularColorNode = mParameter["Specular"]["Color"];
	if(specularColorNode.Size() < 4)
		return SKY_ERROR;

	i = 0;
	this->m_sSpecularColor = skyColor((float)specularColorNode[i].GetDouble(), (float)specularColorNode[++i].GetDouble(), 
							(float)specularColorNode[++i].GetDouble(), (float)specularColorNode[++i].GetDouble());

	// Set Intensity
	if(!mParameter["Specular"]["Intensity"].IsDouble())
		return SKY_ERROR;

	this->m_fSpecularIntensity = (float)mParameter["Specular"]["Intensity"].GetDouble();

	// ------------------------------------------------
	// Set Ambient
	// ------------------------------------------------
	if(!mParameter["Ambient"].IsObject())
		return SKY_ERROR;

	// Set Intensity
	if(!mParameter["Ambient"]["Intensity"].IsDouble())
		return SKY_ERROR;

	this->m_fAmbientIntensity = (float)mParameter["Ambient"]["Intensity"].GetDouble();

	// load constant buffer
	skyResult hr;
	sGfxConstantDesc sDesc;
	SKY_ZERO_MEM(&sDesc, sizeof(sGfxConstantDesc));
	sDesc.m_eUsage = eGfxUsage_Dynamic;
	sDesc.m_eBindFlags = eGfxBindFlags_ConstantBuffer;
	sDesc.m_eCPUAccess = eGfxCpuAccessFlags_Write;
	sDesc.m_uiCount = 1;
	sDesc.m_uiSize = sizeof(sGfxMaterialBuffer);

	SKY_VR(skyGfxManager::CreateConstantBuffer(&m_pPerObject, sDesc));

	sGfxLockedBuffer mLockedBuffer;
	SKY_ZERO_MEM(&mLockedBuffer, sizeof(sGfxLockedBuffer));
	SKY_VR_FAIL(m_pPerObject->Lock(eGfxMapType_WriteDiscard, eGfxMapFlag_None, &mLockedBuffer));

	sGfxMaterialBuffer* pMaterialBuffer = (sGfxMaterialBuffer*)mLockedBuffer.m_pData;
	pMaterialBuffer->m_fAmbientIntensity = m_fAmbientIntensity;
	pMaterialBuffer->m_fDiffuseIntensity = m_fDiffuseIntensity;
	pMaterialBuffer->m_fSpecularIntensity = m_fSpecularIntensity;
	pMaterialBuffer->m_sAmbientColor = m_sAmbientColor;
	pMaterialBuffer->m_sDiffuseColor = m_sDiffuseColor;
	pMaterialBuffer->m_sSpecularColor = m_sSpecularColor;
	pMaterialBuffer->m_u32Shinieness = m_u32Shinieness;

	m_pPerObject->Unlock(mLockedBuffer.m_uiSubresource);

	// load the texture
	SKY_VR_FAIL(skyImageUtils::Load(diffuseTextureNode.GetString(), &m_pDiffuseTexture));
	SKY_VR_FAIL(skyImageUtils::Request(m_pDiffuseTexture, eResourceRequestMode_Immediate));

	return SKY_OK;
FAILED:
	SKY_SAFE_DELETE(m_pPerObject);
	return SKY_ERROR;
}
Пример #6
0
skyVoid skyMaterialResource::Modify ( const rapidjson::Value& a_Data )
{
	const rapidjson::Value& data = a_Data;
	if(!data["Parameters"].IsObject())
		return;

	skyUInt i = 0;
	skyImageResource* pImageResource = nullptr;
	// ------------------------------------------------
	// Set Diffuse
	// ------------------------------------------------
	if(data["Parameters"]["Diffuse"].IsObject())
	{
		// SET COLOR!
		if(data["Parameters"]["Diffuse"]["Color"].IsArray())
		{
			i = 0;
			const rapidjson::Value& diffuseColorNode = data["Parameters"]["Diffuse"]["Color"];
			if(diffuseColorNode.Size() == 4) {
				this->m_sDiffuseColor = skyColor((float)diffuseColorNode[i].GetDouble(), (float)diffuseColorNode[++i].GetDouble(), 
									(float)diffuseColorNode[++i].GetDouble(), (float)diffuseColorNode[++i].GetDouble());
			}
		}
		
		// SET TEXTURE
		if(data["Parameters"]["Diffuse"]["Texture"].IsObject()) 
		{
			if(data["Parameters"]["Diffuse"]["Texture"]["File"].IsString())
			{
				const rapidjson::Value&  diffuseTextureNode = data["Parameters"]["Diffuse"]["Texture"]["File"];
				skyResult hr;

				SKY_VR_FAIL(skyImageUtils::Load(diffuseTextureNode.GetString(), &pImageResource));
				SKY_VR_FAIL(skyImageUtils::Request(pImageResource, eResourceRequestMode_Immediate));

				SKY_RELEASE(m_pDiffuseTexture);
				m_pDiffuseTexture = pImageResource;
			}
		}

		// Set Intensity
		if(data["Parameters"]["Diffuse"]["Intensity"].IsDouble())
		{
			this->m_fDiffuseIntensity = (float)data["Parameters"]["Diffuse"]["Intensity"].GetDouble();
		}
	}


	// ------------------------------------------------
	// Set Specular
	// ------------------------------------------------
	if(data["Parameters"]["Specular"].IsObject())
	{
		// SET COLOR!
		if(data["Parameters"]["Specular"]["Color"].IsArray())
		{
			i = 0;
			const rapidjson::Value&  specularColorNode = data["Parameters"]["Specular"]["Color"];
			if(specularColorNode.Size() == 4) {
				this->m_sSpecularColor = skyColor((float)specularColorNode[i].GetDouble(), (float)specularColorNode[++i].GetDouble(), 
									(float)specularColorNode[++i].GetDouble(), (float)specularColorNode[++i].GetDouble());
			}
		}

		// Set Intensity
		if(data["Parameters"]["Specular"]["Intensity"].IsDouble()) 
		{
			this->m_fSpecularIntensity = (float)data["Parameters"]["Specular"]["Intensity"].GetDouble();
		}
	}

	// ------------------------------------------------
	// Set Ambient
	// ------------------------------------------------
	if(data["Parameters"]["Ambient"].IsObject())
	{
		// Set Intensity
		if(data["Parameters"]["Ambient"]["Intensity"].IsDouble())
		{
			this->m_fAmbientIntensity = (float)data["Parameters"]["Ambient"]["Intensity"].GetDouble();
		}
	}

	skyResult hr;
	sGfxLockedBuffer mLockedBuffer;
	SKY_ZERO_MEM(&mLockedBuffer, sizeof(sGfxLockedBuffer));
	SKY_VR_FAIL(m_pPerObject->Lock(eGfxMapType_WriteDiscard, eGfxMapFlag_None, &mLockedBuffer));

	sGfxMaterialBuffer* pMaterialBuffer = (sGfxMaterialBuffer*)mLockedBuffer.m_pData;
	pMaterialBuffer->m_fAmbientIntensity = m_fAmbientIntensity;
	pMaterialBuffer->m_fDiffuseIntensity = m_fDiffuseIntensity;
	pMaterialBuffer->m_fSpecularIntensity = m_fSpecularIntensity;
	pMaterialBuffer->m_sAmbientColor = m_sAmbientColor;
	pMaterialBuffer->m_sDiffuseColor = m_sDiffuseColor;
	pMaterialBuffer->m_sSpecularColor = m_sSpecularColor;
	pMaterialBuffer->m_u32Shinieness = m_u32Shinieness;

	m_pPerObject->Unlock(mLockedBuffer.m_uiSubresource);

	return;
FAILED:
	SKY_SAFE_DELETE(m_pPerObject);
	SKY_RELEASE(pImageResource);
	return;
}