Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Advanced game related topics
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Rings »

anyone know if that is possible
with Purebasic and the ogre-engine ?
(examples perhaps )

http://en.wikipedia.org/wiki/Cel-shaded_animation

still found nothing ....
SPAMINATOR NR.1
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

Sure it's possible, you just have to write (or find) a shader. I've given some samples a long time ago, but not with cell shading. There should be on ogre website.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Rings »

i'm totaly lost on the ogre site.....
i tried your example at
http://www.purebasic.fr/english/viewtop ... er#p265755

thx for that, seems a first step in the right direction.

but with same results as Mistrel.
For writing the hlsl stuff my own,
any hints where to read about it ?
means any tutorials how to write / compile a shader ....
maybe i'm just to dumb for that stuff...
SPAMINATOR NR.1
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

I don't think so ;)
The ogre website is a complete mess. Anyway, shaders are sort of a standard, so any tool can be used to create them; you just have to link some parameters from ogre to the shaders to get the desired effect. Anyway, PB's implementation is far from complete : Ogre is an open source engine that should be modified to suit your needs.

Badly, I love to hack on misc subjects, and I haven't done any Ogre work for a long time, so I'd have to search a lot to be able to help you!
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

Anyway, I'm not sure these examples could work anymore, but I can't test by now. If Fred is there, maybe he can answer if the shaders are supported in the current engine.dll? In the past, I've done tests with NVidia cg.dll with good results.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

Based on my Ogre log, it seems that the engine3d.dll doesn't support Fragment Programs nor Vertex Programs. Moreover, I was using OpenGL subsystem and by now, Ogre is only using DirectX9. So I don't think it's possible anymore to do shaders.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by citystate »

perhaps have a look at HLSL (High Level Shader Language) - I believe there is some info Here on how DirectX9+ uses shaders
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Rings »

citystate wrote:perhaps have a look at HLSL (High Level Shader Language) - I believe there is some info Here on how DirectX9+ uses shaders
thx for that link.
i got some more info ,

-some shaders:
http://www.ogre3d.org/wiki/index.php/Co ... ts#Shaders

expierence did a cell shader for OpenGL here:
http://www.purebasic.fr/german/viewtopic.php?f=4&t=9179
djes wrote:Based on my Ogre log, it seems that the engine3d.dll doesn't support Fragment Programs nor Vertex Programs. Moreover, I was using OpenGL subsystem and by now, Ogre is only using DirectX9. So I don't think it's possible anymore to do shaders.
Fred, can you do a comment on this ?

support of shaders is defintly a must,
some predefinied made shader as Cell,Metallic,glass should be there.

i also noticed that DarkBASICPro has build in this shaders as 'effects' .
simple to use.......
SPAMINATOR NR.1
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Kuron »

support of shaders is defintly a must,
What type of shaders? Vertex shaders, pixel shaders or geometry shaders?

The problems with shaders is, unlike DBP, PB is multi-platform.

HLSL is DX based and GLSL is OpenGL based. These shader models are not "necessarily" compatible.

If PB stopped supporting proprietary APIs like DirectX and concentrated on only supporting cross-platform APIs like OpenGL, implementing something like shaders in the Ogre3D implementation would be much easier. Trying to get it working properly for DX and OpenGL would likely be a major headache.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Fred »

To be compiled, the shaders needs an nvidia based library. I didn't want to ship another dll (which is not available as source) so for now it is disabled. I could take another look to see if things evolved.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Kuron »

Fred wrote:To be compiled, the shaders needs an nvidia based library. I didn't want to ship another dll (which is not available as source) so for now it is disabled. I could take another look to see if things evolved.
Fred, the GLSL compiler is supplied as part of the driver by the graphics card manufacturer. There is no DLL to ship. I am not 100% sure, but I think with HLSL/Cg you still have to ship the compiler :( MS has talked about shipping it as part of the DX runtimes, but I think they are still only shipping it as part of the DX SDK :(
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

If you talk about cg.dll, you don't have to supply it. Ogre is able to handle a lot of misc shaders without. For those who want to use this dll, they just have to download and join it to their project, but it's not up to you to do it, like a font or another 3rd party dll.
Here's the ogre manual topic about it : http://www.ogre3d.org/docs/manual/manual_18.html#SEC108
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by Fred »

So it should work with current DLL then, if cg.dll isn't needed.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

Yes, I've been able to compile a shader with cgc and make it work. I'll try a bit further now.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Cel Shading (Cartoon like) with Purebasic & Ogre, How ?

Post by djes »

I'm able to do the shaders, but the necessary parameters, like the light position are not sent.
Here's the modified ogre-v1-6-0RC1\ogre\Samples Cellshader script (modify my second example with the textured cube as I can't send files by now).

shadercube.material file :

Code: Select all

// -------------------------------
// Cel Shading Section
// -------------------------------
vertex_program Ogre/CelShadingVP asm
{
	source Example_CelShading.vs_2_0
	syntax vs_2_0

	default_params
	{
		param_named_auto lightPosition light_position_object_space 0
		param_named_auto eyePosition camera_position_object_space
		param_named_auto worldViewProj worldviewproj_matrix
		param_named shininess float 10 
	}
}

fragment_program Ogre/CelShadingFP asm
{
	source Example_CelShading.ps_2_0
	syntax ps_2_0
}


material shader
{
	technique
	{
		pass
		{
			vertex_program_ref Ogre/CelShadingVP
			{
				// map shininess from custom renderable param 1
				param_named_auto shininess custom 1
			}
			fragment_program_ref Ogre/CelShadingFP
			{
				// map diffuse from custom renderable param 2
				param_named_auto diffuse custom 2
				// map specular from custom renderable param 2
				param_named_auto specular custom 3
			}
			texture_unit
			{
				texture cel_shading_diffuse.png 1d
				tex_address_mode clamp
				filtering none
			}
			texture_unit
			{
				texture cel_shading_specular.png 1d
				tex_address_mode clamp
				filtering none
				tex_coord_set 1
			}
			texture_unit
			{
				texture cel_shading_edge.png 1d
				tex_address_mode clamp
				filtering none
				tex_coord_set 2
			}
		}
	}
	
}
Example_CelShading.ps_2_0 file :

Code: Select all

ps_2_0
// cgc version 2.1.0012, build date Oct 15 2008
// command line args: -profile ps_2_0
// source file: Example_CelShading.cg
//vendor NVIDIA Corporation
//version 2.1.0.12
//profile ps_2_0
//program main_fp
//semantic main_fp.diffuse
//semantic main_fp.specular
//semantic main_fp.diffuseRamp
//semantic main_fp.specularRamp
//semantic main_fp.edgeRamp
//var float diffuseIn : $vin.TEXCOORD0 : TEX0 : 0 : 1
//var float specularIn : $vin.TEXCOORD1 : TEX1 : 1 : 1
//var float edge : $vin.TEXCOORD2 : TEX2 : 2 : 1
//var float4 colour : $vout.COLOR : COL : 3 : 1
//var float4 diffuse :  : c[0] : 4 : 1
//var float4 specular :  : c[1] : 5 : 1
//var sampler1D diffuseRamp :  : texunit 0 : 6 : 1
//var sampler1D specularRamp :  : texunit 1 : 7 : 1
//var sampler1D edgeRamp :  : texunit 2 : 8 : 1
//const c[2] = 0.5
dcl_2d s0
dcl_2d s1
dcl_2d s2
def c2, 0.50000000, 0, 0, 0
dcl t0.x
dcl t1.x
dcl t2.x
mov r1.x, t0
mov r1.y, c2.x
mov r2.x, t1
mov r2.y, c2.x
mov r0.y, c2.x
mov r0.x, t2
texld r0, r0, s2
texld r2, r2, s1
texld r1, r1, s0
mul r2, r2.x, c1
mad r1, r1.x, c0, r2
mul r0, r0.x, r1
mov oC0, r0
Example_CelShading.vs_2_0 file :

Code: Select all

vs_2_0
// cgc version 2.1.0012, build date Oct 15 2008
// command line args: -profile vs_2_0
// source file: Example_CelShading.cg
//vendor NVIDIA Corporation
//version 2.1.0.12
//profile vs_2_0
//program main_vp
//semantic main_vp.lightPosition
//semantic main_vp.eyePosition
//semantic main_vp.shininess
//semantic main_vp.worldViewProj
//var float4 position : $vin.POSITION : ATTR0 : 0 : 1
//var float3 normal : $vin.NORMAL : ATTR1 : 1 : 1
//var float4 oPosition : $vout.POSITION : HPOS : 2 : 1
//var float diffuse : $vout.TEXCOORD0 : TEX0 : 3 : 1
//var float specular : $vout.TEXCOORD1 : TEX1 : 4 : 1
//var float edge : $vout.TEXCOORD2 : TEX2 : 5 : 1
//var float3 lightPosition :  : c[4] : 6 : 1
//var float3 eyePosition :  : c[5] : 7 : 1
//var float4 shininess :  : c[6] : 8 : 1
//var float4x4 worldViewProj :  : c[0], 4 : 9 : 1
//const c[7] = 0 1
def c7, 0.00000000, 1.00000000, 0, 0
dcl_position v0
dcl_normal v1
add r1.xyz, -v0, c5
dp3 r1.w, r1, r1
add r0.xyz, -v0, c4
dp3 r0.w, r0, r0
rsq r1.w, r1.w
rsq r0.w, r0.w
mul r0.xyz, r0.w, r0
mul r2.xyz, r1.w, r1
add r3.xyz, r0, r2
dp3 r1.x, r3, r3
rsq r1.w, r1.x
dp3 r0.w, v1, v1
rsq r0.w, r0.w
mul r1.xyz, r0.w, v1
dp3 r0.x, r1, r0
mul r3.xyz, r1.w, r3
max r1.w, r0.x, c7.x
dp3 r0.y, r1, r3
max r3.x, r0.y, c7
sge r0.y, c7.x, r1.w
sge r0.x, r1.w, c7
mul r2.w, r0.x, r0.y
pow r0, r3.x, c6.x
max r0.y, -r2.w, r2.w
mov r0.z, r0.x
slt r0.y, c7.x, r0
add r0.x, -r0.y, c7.y
mul oT1.x, r0, r0.z
dp3 r0.x, r1, r2
mov oT0.x, r1.w
max oT2.x, r0, c7
dp4 oPos.w, v0, c3
dp4 oPos.z, v0, c2
dp4 oPos.y, v0, c1
dp4 oPos.x, v0, c0
Post Reply