コード例 #1
0
ファイル: GraphicsClass.cpp プロジェクト: kvlar/Haeigan
bool GraphicsClass::AddCube(D3DXVECTOR3 position, D3DXVECTOR3 rotation, float scale)
{
	bool result;
	ModelClass* m = new ModelClass;
	m_Models.push_back(m);
	result = m->Initialize(m_D3D->GetDevice(), "../Haeigan/data/cube.obj", L"../Haeigan/data/white_plastic.dds");
	result = AddPhysXCube(position, rotation, scale);
	return result;
}
コード例 #2
0
ファイル: LightShaderClass.cpp プロジェクト: dastyk/Engine
bool LightShaderClass::SetConstantBufferParameters(ID3D11DeviceContext* pDeviceContext, PointLightClass** ppLights, UINT NrOfLights, ObjectClass* pObject, FogClass* pDrawDistFog, CameraClass* pCamera)
{
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	LightConstantBuffer* dataPtr;
	unsigned int bufferNumber;

	// Lock the constant buffer so it can be written to.
	result = pDeviceContext->Map(mLightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(result))
	{
		return false;
	}

	// Get a pointer to the data in the constant buffer.
	dataPtr = (LightConstantBuffer*)mappedResource.pData;

	ModelClass* pModel = pObject->GetModel();
	MatrialDesc *pMaterials = pModel->GetMaterials();
	UINT oCount = pModel->GetObjectCount();

	dataPtr->LightCount_FogRange_ObjectCount_Unused = XMFLOAT4((float)NrOfLights, pDrawDistFog->GetRange(), (float)oCount, 0);
	dataPtr->fogColor = pDrawDistFog->GetColor();
	dataPtr->CamPos = pCamera->GetPosition();

	for (UINT i = 0; i < NrOfLights; i++)
	{
		dataPtr->lights[i].Pos = ppLights[i]->GetLightPos();
		XMFLOAT3 color = ppLights[i]->GetLightColor();
		dataPtr->lights[i].Color_LightRange = XMFLOAT4(color.x, color.y, color.z, ppLights[i]->GetRadius());
	}
	
	for (UINT i = 0; i < oCount; i++)
	{
		dataPtr->materials[i].Ambient = pMaterials[i].Ambient;
		dataPtr->materials[i].Diffuse = pMaterials[i].Diffuse;
		dataPtr->materials[i].Specular = pMaterials[i].Specular;
		dataPtr->materials[i].Reflectivity = pMaterials[i].Reflectivity;

		dataPtr->materials[i].SpecPower_AlphaClip_Unused_Unused = XMFLOAT4(pMaterials[i].SpecPower, pMaterials[i].AlphaClip, 0, 0);
	}

	// Unlock the constant buffer.
	pDeviceContext->Unmap(mLightBuffer, 0);

	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	// Set the constant buffer in the shader with the updated values.
	pDeviceContext->PSSetConstantBuffers(bufferNumber, 1, &mLightBuffer);

	return true;
}
コード例 #3
0
ファイル: GraphicsClass.cpp プロジェクト: kvlar/Haeigan
void GraphicsClass::AddCubeFromEye()
{
	D3DXVECTOR3 position = m_Camera->GetPosition();
	D3DXVECTOR3 rotation(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 velocity = m_Camera->GetForward();
	D3DXVec3Normalize(&velocity, &velocity);
	velocity *= 100.0f;
	bool result;
	ModelClass* m = new ModelClass;
	m_Models.push_back(m);
	result = m->Initialize(m_D3D->GetDevice(), "../Haeigan/data/cube.obj", L"../Haeigan/data/white_plastic.dds");
	result = AddPhysXCube(position, rotation, 1.0f, velocity);
}
コード例 #4
0
ファイル: TabSetup.cpp プロジェクト: kgustafson/nutcracker_c
void xLightsFrame::SetChannelNamesForRgbModel(wxArrayString& ChNames, wxXmlNode* ModelNode)
{
    ModelClass model;
    model.SetFromXml(ModelNode);
    size_t ChannelNum=model.StartChannel-1;
    size_t NodeCount=model.GetNodeCount();
    wxString FormatSpec = wxT("Ch %d: ")+model.name+wxT(" node %d %c");
    for(size_t i=0; i < NodeCount && ChannelNum+2 < ChNames.Count(); i++)
    {
        for(size_t j=0; j < 3; j++)
        {
            ChNames[ChannelNum] = wxString::Format(FormatSpec,ChannelNum+1,i+1,model.RGBorder[j]);
            ChannelNum++;
        }
    }
}
コード例 #5
0
void ModelListDialog::OnButton_LayoutClick(wxCommandEvent& event)
{
    int sel=ListBox1->GetSelection();
    if (sel == wxNOT_FOUND)
    {
        wxMessageBox(_("Select an item before clicking the Channel Layout button"));
        return;
    }
    wxXmlNode* ModelNode=(wxXmlNode*)ListBox1->GetClientData(sel);
    ModelClass model;
    model.SetFromXml(ModelNode);
    wxString html=model.ChannelLayoutHtml();

    ChannelLayoutDialog dialog(this);
    dialog.HtmlEasyPrint=HtmlEasyPrint;
    dialog.SetHtmlSource(html);
    dialog.ShowModal();
}
コード例 #6
0
ファイル: graphicsclass.cpp プロジェクト: Jiyambi/Portfolio
// |----------------------------------------------------------------------------|
// |						    SunRender										|
// |----------------------------------------------------------------------------|
bool GraphicsClass::SunRender(ModelClass& to_render, D3DXMATRIX scale, 
	D3DXMATRIX translate, D3DXMATRIX rotate)
{
	D3DXMATRIX scaleMatrix, translationMatrix, rotationMatrix;
	bool result = true;

	// Modify the world matrix as needed.
	D3DXMatrixIdentity(&worldMatrix);
	worldMatrix = scale * rotate * translate;
	
	// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
	to_render.Render(m_D3D->GetDeviceContext());
	
	// Render the model using the light shader.
	result = m_LightShader->Render(m_D3D->GetDeviceContext(), to_render.GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, 
								    m_Light->GetPosition(), D3DXVECTOR4(0.99f,0.99f,0.99f,1.0f), m_Light->GetDiffuseColor(), m_Camera->GetPosition(), 
									m_Light->GetSpecularColor(), m_Light->GetSpecularPower(), to_render.GetTexture());

	return result;
}
コード例 #7
0
ファイル: GraphicsClass.cpp プロジェクト: kvlar/Haeigan
void GraphicsClass::Shutdown()
{
	// Release the color shader object.
	if(m_baseShader)
	{
		m_baseShader->Shutdown();
		delete m_baseShader;
		m_baseShader = 0;
	}

	if(m_light)
	{
		delete m_light;
		m_light = 0;
	}

	// Release the model object.
	while(!m_Models.empty())
	{
		ModelClass* m = m_Models.back();
		m_Models.pop_back();
		m->Shutdown();
		delete m;
		m = 0;
	}
	

	// Release the camera object.
	if(m_Camera)
	{
		delete m_Camera;
		m_Camera = 0;
	}
	if(m_D3D)
	{
		m_D3D->Shutdown();
		delete m_D3D;
		m_D3D = 0;
	}
	return;
}
コード例 #8
0
bool ThreeDGraphicsClass::addNewModel(string meshFilename, string textureFilename, string bumpmapFilename)
{
	bool result;

	ModelClass* newModel = new ModelClass();
	if(!newModel)
	{
		return false;
	}

	result = newModel->Initialize(meshFilename, textureFilename, bumpmapFilename, mLightSource);
	if(!result)
	{
#ifdef _WIN32
		MessageBoxA( NULL, "Model Init Failure", "Error", MB_OK );
#endif
		return false;
	}

	mAllModels->push_back(newModel);

	return true;
}
コード例 #9
0
void ModelListDialog::OnButton_ExportCsvClick(wxCommandEvent& event)
{
#if 0
    model name
    display as
    type of strings
#strings
#nodes
    start channel
    start node = (channel+2)/3;
    my display
    brightness
#endif // 0
    wxLogNull logNo; //kludge: avoid "error 0" message from wxWidgets after new file is written
    wxString filename = wxFileSelector(_("Choose output file"), wxEmptyString, wxEmptyString, wxEmptyString, "Export files (*.csv)|*.csv", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
//    if (filename.IsEmpty()) retmsg(wxString("Please choose an output file name."));
    if (filename.IsEmpty()) return;

    wxFile f(filename);
//    bool isnew = !wxFile::Exists(filename);
    if (!f.Create(filename, true) || !f.IsOpened()) retmsg(wxString::Format("Unable to create file %s. Error %d\n", filename, f.GetLastError()));
    f.Write(_("Model_name, Display_as, String_type, String_count, Node_count, Start_channel, Start_node, My_display, Brightness+-\n"));

    int first = 0, last = ListBox1->GetCount();
    if (ListBox1->GetSelection() != wxNOT_FOUND) last = 1 + (first = ListBox1->GetSelection());
    for (int i = first; i < last; ++i)
    {
        wxXmlNode* node = (wxXmlNode*)ListBox1->GetClientData(i);
        ModelClass model;
        model.SetFromXml(node);
        wxString stch = node->GetAttribute("StartChannel", wxString::Format("%d?", model.NodeStartChannel(0) + 1)); //NOTE: value coming from model is probably not what is wanted, so show the base ch# instead
        f.Write(wxString::Format("\"%s\", \"%s\", \"%s\", %d, %d, %s, %d, %d, %d\n", model.name, model.GetDisplayAs(), model.GetStringType(), model.GetNodeCount() / model.NodesPerString(), model.GetNodeCount(), stch, /*WRONG:*/ model.NodeStartChannel(0) / model.NodesPerString() + 1, model.MyDisplay, model.ModelBrightness));
//no worky        f.Flush(); //paranoid: write out data in case model loop crashes
    }
    f.Close();
    retmsg(wxString::Format(_("Models exported: %d of %d"), last - first, ListBox1->GetCount()));
}
コード例 #10
0
ファイル: TerrainShaderClass.cpp プロジェクト: dastyk/Engine
bool TerrainShaderClass::RenderShadowsDeferred(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera, PointLightClass* pLights, ID3D11ShaderResourceView* pShadowmap, UINT indexCount, UINT indexStart)
{
	bool result;
	unsigned int bufferNumber;



	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	result = SetShadowConstantBufferParamters(pDeviceContext, pObject, pCamera, pLights);
	if (!result)
	{
		return false;
	}

	ModelClass* pModel = pObject->GetModel();

	pDeviceContext->PSSetShaderResources(0, 1, &pShadowmap);



	TextureClass* pTexture = pModel->GetDetailMap();

	ID3D11ShaderResourceView** tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(1, 1, tex);

	pTexture = pModel->GetNormalMap();

	tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(2, 1, tex);


	pTexture = pModel->GetTexture();

	tex = pTexture->GetShaderResourceView();

	// Set shader texture resource in the pixel shader.
	pDeviceContext->PSSetShaderResources(3, pTexture->GetTextureCount(), tex);



	pDeviceContext->PSSetSamplers(1, 1, &mPointSampleState);
	// Now render the prepared buffers with the shader.
	pDeviceContext->PSSetSamplers(0, 1, &mSampleState);

	// Set the vertex input layout.
	pDeviceContext->IASetInputLayout(mLayout);

	// Set the vertex and pixel shaders that will be used to render this triangle.
	pDeviceContext->VSSetShader(mShadowDeferredVS, nullptr, 0);
	pDeviceContext->HSSetShader(mHullShader, nullptr, 0);
	pDeviceContext->DSSetShader(mDomainShader, nullptr, 0);
	pDeviceContext->GSSetShader(mShadowDeferredGS, nullptr, 0);
	pDeviceContext->PSSetShader(mShadowDeferredPS, nullptr, 0);

	// Render mesh stored in active buffers
	pDeviceContext->DrawIndexed(indexCount, indexStart, 0);

	return true;
}
コード例 #11
0
ファイル: RayTracer.cpp プロジェクト: stryder199/GameDev
RayTracer::Pixel RayTracer::TracePixel(Ray* ray, ModelClass* reflectedObject, int depth)
{
	Pixel finalColor = {0.0f, 0.0f, 0.0f};
	ModelClass* intersectObject = NULL;
	Vector3 normal, viewDirection, hitPoint;

	if(depth == MAX_RAY_BOUNCE)
	{
		//You hit the max amount of reflections
		finalColor.r = 0.0f;
		finalColor.g = 0.0f;
		finalColor.b = 0.0f;
		return finalColor;
	}

	intersectObject = mThreeDGraphics->computeIntersection(*ray, mCamera, reflectedObject, &hitPoint, &normal, &viewDirection);

	if(intersectObject == NULL)
	{
		//Didnt intersect anything
		finalColor.r = 0.0f;
		finalColor.g = 0.0f;
		finalColor.b = 0.0f;
	}
	else{
		if(depth == 1)
		{
			int i = 0;
		}

		//Compute illum
		Ray shadowRay;
		bool inShadow = false;
		shadowRay.origin = hitPoint;
		shadowRay.direction = *mLight->getPosition() - hitPoint;
		inShadow = mThreeDGraphics->computeShadowIntersection(shadowRay, mCamera, intersectObject);
		
		if(!inShadow)
		{
			//Do lighting calc
			float diffuseCoefficient;
			Vector3 intersectObjectColor, lightDir, reflection;
			Vector4 specularColor, finalLightColor, outputColor;

			intersectObjectColor = intersectObject->getColor();

			//Init the specular color
			specularColor = Vector4();
		
			//Minimum brightness that the pixel must be set to
			outputColor = *(mLight->getAmbientLight());

			//Invert the light direction
			lightDir = (*mLight->getDirection())*-1;

			//Calc the amount of light on this pixel
			diffuseCoefficient = normal.dot(lightDir);
			diffuseCoefficient = clamp(diffuseCoefficient);

			if(diffuseCoefficient > 0.0f)
			{
				//Find the final diffuse light color if the object isnt pointing away from the light source
				outputColor += (*mLight->getDiffuseColor() * diffuseCoefficient);
				outputColor.clamp();

				//Calculate the reflection vector vased on the light intensity, normal vector and light direction
				reflection = normal*(2*diffuseCoefficient);
				reflection = reflection - lightDir;
				reflection.normalize();

				//Determine the amount of specular light based on the reflection vector, viewing direction and specular power
				float specularCoefficient = reflection.dot(viewDirection);
				specularCoefficient = clamp(specularCoefficient);
				specularCoefficient = pow(specularCoefficient, mLight->getSpecularPower());
				specularColor = *(mLight->getSpecularColor())*specularCoefficient;
			}
			//Find the final color by multing the lightColor with the texture color
			outputColor = outputColor*vec4(intersectObjectColor);

			//Add the specular component to the final color
			outputColor = outputColor + specularColor;

			Pixel reflectionColor = {0.0f, 0.0f, 0.0f};
			if(depth < MAX_RAY_BOUNCE)
			{
				//Compute reflection
				Ray reflectionRay;
				float c1 = -1*normal.dot(ray->direction);
				reflectionRay.direction = ray->direction + ((normal*2)*c1);
				reflectionRay.origin = hitPoint;
				reflectionColor = TracePixel(&reflectionRay, intersectObject, depth+1);
			}

			outputColor = outputColor + Vector4(reflectionColor.r/mLight->getSpecularPower(), reflectionColor.g/mLight->getSpecularPower(), reflectionColor.b/mLight->getSpecularPower(), 1.0f);
			outputColor.clamp();

			//Convert to pixel format
			finalColor.r = outputColor.x;
			finalColor.g = outputColor.y;
			finalColor.b = outputColor.z;
		}
		else{
			//In shadow
			finalColor.r = 0.0f;
			finalColor.g = 0.0f;
			finalColor.b = 0.0f;
		}
	}

	return finalColor;
}
コード例 #12
0
bool ThreeDGraphicsClass::Initialize()
{
	bool result;

	mAllModels = new vector<ModelClass*>;
	if(!mAllModels)
	{
#ifdef _WIN32
		MessageBoxA( NULL, "Model Vector Obj Creation Failure", "Error", MB_OK );
#endif
		return false;
	}

	mShaderProgram = new ShaderProgram();
	if(!mShaderProgram)
	{
#ifdef _WIN32
		MessageBoxA( NULL, "Shader Program Obj Creation Failure", "Error", MB_OK );
#endif
		return false;
	}

	result = mShaderProgram->Initialize("./shaders/VertexShader.glsl", "./shaders/FragmentShader.glsl");
	if(!result)
	{
#ifdef _WIN32
		MessageBoxA( NULL, "Shader Program Init Failure", "Error", MB_OK );
#endif
		return false;
	}

	mLightSource = new LightClass();
	if(!mLightSource)
		return false;

	mLightSource->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
	mLightSource->SetAmbientLight(0.15f, 0.15f, 0.15f, 1.0f);
	mLightSource->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
	mLightSource->SetSpecularPower(32.0f);
	mLightSource->SetDirection(0.0f, -1.0f, 0.0f);
	mLightSource->SetPosition(0.0f, 5.0f, 0.0f);

	//Add the floor
	addNewModel("data/smallsquare.obj", "data/red.tga", "data/stone.tga");
	ModelClass* floor = (*mAllModels)[0];
	floor->setScaleFactor(Vector3(10.0f, 1.0f, 1.0f));
	floor->translate(Vector3(0.0f, -0.9f, 0.0f));
	floor->rotate(Vector3(1.0f, 0.0f, 0.0f));
	floor->setColor(Vector3(0.8039215686f, 0.78823529f, 0.78823529f));

	//Add the sphere1
	addNewModel("data/sphere.obj", "data/red.tga", "data/stone.tga");
	ModelClass* sphere1 = (*mAllModels)[1];
	sphere1->setScaleFactor(Vector3(0.5f, 0.5f, 0.5f));
	sphere1->translate(Vector3(-1.0f, 0.0f, 0.0f));

	//Add the sphere2
	addNewModel("data/sphere.obj", "data/red.tga", "data/stone.tga");
	ModelClass* sphere2 = (*mAllModels)[2];
	sphere2->setScaleFactor(Vector3(0.5f, 0.5f, 0.5f));
	sphere2->translate(Vector3(1.0f, 0.0f, 0.0f));
	sphere2->setColor(Vector3(0.0f, 0.0f, 1.0f));
	return true;
}