Ported CellShading Demo

grizzley90

24-11-2006 02:16:32

I ported the cell shading demo because i had nothing better to do tonight... here it is:

CellShading.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Mogre;

namespace CelShading
{
class CelShading : Mogre.Demo.ExampleApplication.Example
{
uint CUSTOM_SHININESS = 1;
uint CUSTOM_DIFFUSE = 2;
uint CUSTOM_SPECULAR = 3;
Mogre.SceneNode rootNode;
public override void CreateScene()
{
// Check capabilities
RenderSystemCapabilities caps = Root.Singleton.RenderSystem.Capabilities;
if (!caps.HasCapability(Mogre.Capabilities.RSC_VERTEX_PROGRAM) || !(caps.HasCapability(Mogre.Capabilities.RSC_FRAGMENT_PROGRAM)))
{
MessageBox.Show("Your card does not support vertex and fragment programs, so cannot run this demo. Sorry! CelShading::createScene");
}

// Create a point light
Light l = sceneMgr.CreateLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// Add light to the scene node
rootNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
rootNode.CreateChildSceneNode(new Vector3(20,40,50)).AttachObject(l);

Entity ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");

camera.Position = new Vector3(20, 0, 100);
camera.LookAt( new Vector3(0,0,0));


// Set common material, but define custom parameters to change colours
// See Example-Advanced.material for how these are finally bound to GPU parameters
SubEntity sub;
// eyes
sub = ent.GetSubEntity(0);
sub.MaterialName = ("Examples/CelShading");
sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(35.0f, 0.0f, 0.0f, 0.0f));
sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 0.3f, 0.3f, 1.0f));
sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 0.6f, 0.6f, 1.0f));
// skin
sub = ent.GetSubEntity(1);
sub.MaterialName = ("Examples/CelShading");
sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(10.0f, 0.0f, 0.0f, 0.0f));
sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(0.0f, 0.5f, 0.0f, 1.0f));
sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(0.3f, 0.5f, 0.3f, 1.0f));
// earring
sub = ent.GetSubEntity(2);
sub.MaterialName = ("Examples/CelShading");
sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(25.0f, 0.0f, 0.0f, 0.0f));
sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 1.0f, 0.0f, 1.0f));
sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 1.0f, 0.7f, 1.0f));
// teeth
sub = ent.GetSubEntity(3);
sub.MaterialName = ("Examples/CelShading");
sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(20.0f, 0.0f, 0.0f, 0.0f));
sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 1.0f, 0.7f, 1.0f));
sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));

// Add entity to the root scene node
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

window.GetViewport(0).BackgroundColour = (Mogre.ColourValue.White);

}
bool CellShading_FrameStarted(FrameEvent evt)
{
rootNode.Yaw(new Degree(evt.timeSinceLastFrame * 30));
// Call superclass
return true;
}
public override void CreateFrameListener()
{
base.CreateFrameListener();
root.FrameStarted += new FrameListener.FrameStartedHandler(CellShading_FrameStarted);
}
}
}



Program.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace CelShading
{
class Program
{
static void Main(string[] args)
{
try
{
CelShading app = new CelShading();
app.Go();
}
catch
{
// Check if it's an Ogre Exception
if (Mogre.OgreException.IsThrown)
Mogre.Demo.ExampleApplication.Example.ShowOgreException();
else
throw;
}
}
}
}

It works perfectly fine... however can someone test it out to make sure it works fine everywhere else...

LuRenJia

24-11-2006 04:40:43

Good. so I hope you always have nothing better to do at every night. 8)

Bekas

24-11-2006 09:34:45

Thanks, I added it to SVN.
I agree with LuRenJia :)