How to use Tuhopuu2. Simple sample?

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

rstralberg
Posts: 0
Joined: Wed Jul 21, 2004 4:48 pm
Location: Sweden

How to use Tuhopuu2. Simple sample?

Post by rstralberg »

I realize that you who are developing tuhopuu2 are very busy with
Important stuff but would be very thankful for some 'newbie' guidance.

I would like to get started with a very simple project.
Apply a pixel shader to a simple cube and render it.

It's not of any importance what the pixel shader actual do. I just want to know how to make it work.

I know that it has to be applied by Python-script, but how? I know how to write
very simple Python scripts.

Could any one be kind enough to show an example?

/roland

alien-xmp
Posts: 0
Joined: Sun Apr 06, 2003 2:22 pm
Location: Wellington, New Zealand
Contact:

Post by alien-xmp »

A Simple Example:

Code: Select all

import GameLogic
                
mats = GameLogic.getCurrentController().getOwner().getMesh().materials
vs = """
// Vertex Shader:
void main ()
{
	gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;
}
// End Vertex Shader
"""

fs = """
// Fragment Shader:
void main()
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
// End Fragment Shader
"""
for mat in mats:
    mat.loadShader(mat.VERTEX_SHADER, vs, "simple vertex shader")
    mat.loadShader(mat.FRAGMENT_SHADER, fs, "simple fragment shader")


That is pretty much the simplest shader program you can do - it will turn every pixel in the attached object red.

You should set up the script to run once on game startup.

Also, check the console after game startup. It will print if your graphics card supports GLSL.

A more complex example is here:
http://projects.blender.org/viewcvs/vie ... &view=auto

rstralberg
Posts: 0
Joined: Wed Jul 21, 2004 4:48 pm
Location: Sweden

Post by rstralberg »

Many thank's 'alien-xmp'

This was just what I was looking for.
Something simple enough so even I could understand it :)

This will get me started. And of course my GForce FX 5200 doesnt
support GLSL. So ... time to get a new card

rstralberg
Posts: 0
Joined: Wed Jul 21, 2004 4:48 pm
Location: Sweden

Post by rstralberg »

Oh how wrong I was about the FX 5200 card. I supports GLSL using
nVidia ForceWare drivers from http://www.3dchipset.com.

mpan3
Posts: 0
Joined: Wed Mar 24, 2004 7:16 pm

Post by mpan3 »

Yeah FX5200 support everything under the sun EXCEPT for the new DX9c features, which is only found on the newest 6800 families. Despite its slowness, 5200 is a good card for developers. :wink:

Doc_Holiday
Posts: 2
Joined: Sat Jul 05, 2003 1:03 am
Contact:

Post by Doc_Holiday »

Thanx a lot alien-xmp! :D That are cool Examples for start learning GLSL. Now im on the Way.
But it seems i stuck! I try to realize a simple Texture Animation. (A linear moving in a Direction.) Is there a Way to use Timer Functions ore someting to do such Things? Thanks for a Hint.
Doc

alien-xmp
Posts: 0
Joined: Sun Apr 06, 2003 2:22 pm
Location: Wellington, New Zealand
Contact:

Post by alien-xmp »

Animating is fairly easy - do it like this:

Code: Select all

own = GameLogic.getCurrentController().getOwner()
mats = own.getMesh().materials
for mat in mats:
	mat.setUniform("time", own.time)
own.time = own.time + 0.2
And in the vertex shader:

Code: Select all

uniform float time;

// Texture animation velocity:
const vec4 tv = vec4(1.0, 0.0, 0.0, 0.0);

.
.
.

gl_TexCoord[0] = gl_MultiTexCoord0 + time*tv
Also, you've probably already found it, but The OpenGL Shading Language Reference is invaluable (especially the reference chapters 7 & 8)

ATI's RenderMonkey 1.5 supports GLSL, and has a ton of examples to get you going.

dmao
Posts: 5
Joined: Wed Apr 07, 2004 3:12 am
Location: New Orleans, LA

Post by dmao »

Does T2 also support PS 1.1 shaders for my poor, elderly geforce 3? :wink:

edit: I think I found it

Code: Select all

def loadProgram(source, name):
"""
Loads an assembly program into the material.

The type of program will be deduced from the source header:
1. !!ARBvp1.0Vertex Program (GL_ARB_vertex_program)
2. !!ARBfp1.0Fragment Program (GL_ARB_fragment_program)

@param source: The program to load.  Can be either the source itself, or the name
of a text space.
@type source: string
@param name: (Optional) The name of the program.  The name is printed to the console for debugging.
@type name: st
Still trying to get it to do something useful tho :)

rstralberg
Posts: 0
Joined: Wed Jul 21, 2004 4:48 pm
Location: Sweden

Post by rstralberg »

I must be a real dummy but I can't get any shader
output using the sample provided in KX_PolygonMaterial.

I have described what I have done at http://www.rstralberg.com/t2start.htm.

Please! Could anyone give some advise or a hint of what
I'm doing wrong.

If I can make this work I could make a 'real nobody tutotial' of
how to do it and leave it on my website, so other 'dummies' can
learn also :)

Many thanks
/roland

alien-xmp
Posts: 0
Joined: Sun Apr 06, 2003 2:22 pm
Location: Wellington, New Zealand
Contact:

Post by alien-xmp »

@dmao:
I think OpenGL vertex & fragment programs v1.0 are roughly the same as DirectX shaders 2.0. According to the hardware support list at delphi3d.net, it is GeforceFX and Radeon 9500 and up. Sorry.

@rstralberg:
Does your card support GLSL? (Check the console) You've said you have a Geforce FX, so you need drivers > 60.00
Have you loaded rfNormalMapping.frag and rfNormalMapping.vert into text spaces?
Have you UV mapped the object? Tangent space is in part derived from UV coordinates.
Is the lighting set up properly? (Looks to be correct)
That tangent space is a bit ugly... I should update the example.

rstralberg
Posts: 0
Joined: Wed Jul 21, 2004 4:48 pm
Location: Sweden

Post by rstralberg »

@alien-xmp:
Yes I have the latest drivers.
The error was that I had not UV mapped the object
Now it works just fine. I get the expected result :)

I'll set up a short tutorial within next day or two.

Many thanks
/roland

Doc_Holiday
Posts: 2
Joined: Sat Jul 05, 2003 1:03 am
Contact:

Post by Doc_Holiday »

alien-xmp wrote:Animating is fairly easy
... for You! :lol: I took a while to get this to work. Sometimes i thought im to stupid for this. I thought i just need one single Script and not two. But i have it now. The first Script includes the Shaders, is able to receive the "timer" property and run's olny once. The second Script is always updating this "timer" Property to the Material. Got it! :D
Next Steps are Testings with Alpha Textures. But Blender crashes each Time i try this. Also i fail to animate only the Second (Material) Texture. But i think i get this too!
I found the GLSlang Reference. Really cool, but hard to read for an english Zero like me. :wink: I try to find some Startup-Hints in german and i try to read tis Document later when i nearly know what they are talking about.

Thanx a lot for this really cool hot spicy Feature! Please keep up this fantastic Work.
Doc

Oh, the Render Monkey Hint was useful too. I have an NVidia Card, so i've never thought about that. I found an other cool Tool for GLSL. The Shader Designer from http://www.typhoonlabs.com/ (It needs MS Dot Net to run.) I don't know how to use these Tools, but the Demos are realy cool!

mpan3
Posts: 0
Joined: Wed Mar 24, 2004 7:16 pm

Post by mpan3 »

i am playing around with the shaders, too, once I got it, I'll post an example. Mean while, any one made a working bump map shader?

Doc_Holiday
Posts: 2
Joined: Sat Jul 05, 2003 1:03 am
Contact:

Post by Doc_Holiday »

I have uploadet the Example from the Tuhopuu Docu to my Webspace. You can download it here: *click me*

mpan3
Posts: 0
Joined: Wed Mar 24, 2004 7:16 pm

Post by mpan3 »

hmm...I thought bump mapping (no matter what kind) is a per-pixel fx that takes into account the direction of the light. However, in your example, the cube is not bump-mapped no matter how hard I sqink, the normal map only made the box purple-ish.

[edit] yeah i checked the console, errors, errors and more errors... I need some time to figure this out. :?

Post Reply