How to use Tuhopuu2. Simple sample?

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

Moderators: jesterKing, stiv

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

Post by mpan3 »

Hehe, you beat me to it. I was going to work on the shaders stuff at home after school (Yes I am still at school right now, only 1 more hour until blender time :D )

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

Post by Doc_Holiday »

I tried the Modifications on the Shader. Still looking fantastic and working fine on my NVidia Card. :D

But i have some (maybe stupid) Questions: While trying coding i see, it's very hard to find Bugs and Errors. Is there a Way to print out the Content of an Variable and other Stuff? Maybe: vec3 vv = normalize(viewvec); How can i print out the Content of vv now? Or: gl_TexCoord[0] = gl_MultiTexCoord0; What is the Content of gl_MultiTexCoord0; Does anybody now how this can be done?

Also: What can i do if i receive Messages like this in the Dos Box:

Code: Select all

098D3440098ABE40:
(22) : warning C7011: implicit cast from "float4" to "float3"
This is coming directly from the GPU, right? Anyway, there is no Line Number or an other Hint where to find the Reason. :? What can i do here.
Thanks for Help.
Doc

Edit -----------------------
Here is a Page with some cool OpenGL Demos. http://www.paulsprojects.net/opengl/projects1.html I can't wait to see such FX in Blender! :mrgreen:

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

Post by alien-xmp »

While trying coding i see, it's very hard to find Bugs and Errors. Is there a Way to print out the Content of an Variable and other Stuff? Maybe: vec3 vv = normalize(viewvec);
No. The shader is running on your graphics card. DirectX can do it when the software reference shader is running.

The way I do it, is to set gl_FragColor to the variable you are trying to debug at the end of main(): ie

Code: Select all

void main()
{
	vec3 vv = normalize(viewvec);
.
.
.

	gl_FragColor = diffuse;
	gl_FragColor.rgb = vv; // You don't need to comment out the rest
	// of the shader code above.
}
You also might need to scale and bias your debug output, since if eg vv has negative components, they will be black:

Code: Select all

	gl_FragColor.rgb = 0.5*vv + 1.0; // vv is expected to be 0.0 < vv < 1.0
Also: What can i do if i receive Messages like this in the Dos Box:

Code: Select all

098D3440098ABE40: 
(22) : warning C7011: implicit cast from "float4" to "float3"
This is coming directly from the GPU, right? Anyway, there is no Line Number or an other Hint where to find the Reason. What can i do here.
That means you are converting a 4 component vector to a 3 component vector - something like this:

Code: Select all

	vec4 foo; // float4
	vec3 bar; // float3
	
	bar = foo; // implicit cast
	bar = foo.xyz; // correct
(NVidia will compile this, ATI won't.)

22 in the error you posted is allegedly the line number - Alt-J in the text window will jump to it.

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

Post by Doc_Holiday »

Thank's alien-xmp. That is a huge Help. :D
I tried to visit Your Website, but it won't open. Is it down?

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

Post by rstralberg »

Hi

I have written a 'newbie' tutorial on how to apply a shader in T2
and placed it on my website. I'm self a newbie :).

Could any of you experts check it and tell me if there are
any errors of faults. Dont want to misslead others by publishing
any errors.

The address is http://www.rstralberg.com/t2.html

/roland
Last edited by rstralberg on Thu Aug 11, 2005 2:46 pm, edited 3 times in total.

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

Post by alien-xmp »

Looks good:

1. You don't need to copy tuhopuu2\source\gameengine\PyDoc to .blender/scripts. tuhopuu2\source\gameengine\PyDoc contains the source for the game engine python reference. If you have epydoc installed, you can generate the html documentation as seen in the documentation section. (You can also generate the rest of the Blender Python documentation in tuhopuu2/source/blender/python/api2_2x/doc)

2. In "applying the shader" you should disable pulse mode for the always sensor, so you don't compile the shader every frame. This should give you better performance.

3. It's just a stylistic thing, but you can put the vertex & fragment shaders in their own text spaces, and mat.loadShader(shaderType, name_of_text_space, name_of_shader)

4. In tuhopuu2\source\gameengine\Ketsji\Shaders, there are utility functions that you can copy and paste into your own shaders - tangent space functions, lighting, shading etc. Some of these are still quite buggy, so patches are gratefully accepted.

5. In "Adding a shader" gl_TexCoord[0] should be gl_TexCoord[0].st
6. Use the new tangent transform. tangent[0..2].w is not written in the old one, which causes weird triangle flickering on ATIs.

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

Post by rstralberg »

@alien-xmp:
Many thank's. You are realy helpful in every way.
I will fix those things tomorrow ( it's 02:14 past midnight now ).

/roland

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

Post by Doc_Holiday »

Here is a little Python Code to load the Shaders from external Files. You just have to insert the Shader Name into the Script. Maybe "BumpMap". In that Case, You need a "BumpMap.vert" and a "BumpMap.frag" File, containing the Vertex and the Fragment Shaders. It seems, that the "running blend-File Path" can't get from Tuhopuu2. So You has to insert the Path where these Files are located manually. But that's a temporary Solution an will be change in Future. It's also possible to store the ShaderName and Path in Properties. Maybe You find it useful. :D
Doc

Code: Select all

import GameLogic
import sys

ShaderName = "BumpMap"	# <---------------------- Enter Shader here!
Path = "c:\\blender\\tuhopuu2\\shaders\\"

try:
	# Try loading Shader Files
	# ~~~~~~~~~~~~~~~~~~~~~~~~
	FragFile = open(Path+ShaderName+".frag","r")
	VertFile = open(Path+ShaderName+".vert","r")

	FragShader = FragFile.read()
	VertShader = VertFile.read()

	FragFile.close()
	VertFile.close()

except:
	# Loading failed
	# ~~~~~~~~~~~~~~
	print "\n **** Problem while loading Shader Files! ****\n"

else:
	# All fine, go Ahead!
	# ~~~~~~~~~~~~~~~~~~
	mats = GameLogic.getCurrentController().getOwner().getMesh().materials
	shaders = [(mats[0].VERTEX_SHADER, VertShader, "vertex.vs"),
				(mats[0].FRAGMENT_SHADER, FragShader, "fragment.fs")]

	for mat in mats:
		for shader in shaders:
			mat.loadShader(shader[0], shader[1], shader[2])

		# more Code here ...

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

Post by rstralberg »

@alien-xmp:
@Doc_Holiday:

Many thanks for your help.
I have updated the tutorial according
to your good advices.

And 'Doc_Holidays' code snippet
on loading from external files was
just awesome. Thanks.

The tut is still out there http://www.rstralberg.com/t2.html

/roland
Last edited by rstralberg on Thu Aug 11, 2005 2:48 pm, edited 1 time in total.

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

Post by Doc_Holiday »

I like Your Tutorial, very nice. And thanks for naming me. :D But please use smaller and higher compressed Textures for the Demo File. That will keep the Filesize low. :wink:
Doc

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

Post by rstralberg »

@Doc_Holiday:

Thanks :)

I will fix compressed textures this evening
(it's morning here now ).


/roland

Sutabi
Posts: 53
Joined: Fri Oct 18, 2002 1:35 am
Location: Oceanside, California
Contact:

Post by Sutabi »

Hm... I tried it but I guess my g-card does work with it =_=

Code: Select all

'import site' failed; use -v for traceback
GLEW: 1.2.3
RAS_OpenGLRasterizer:
   GL Vendor  : NVIDIA Corporation
   GL Renderer: GeForce2 MX/PCI/SSE2
   GL Version : 1.5.1
   Colour     : 24 bits (8/8/8/0)
   Accum      : 64 bits (16/16/16/16)
   Depth      : 16 bits
   Stencil    : 0 bits
   Multisample: Not supported
   Stereo     : Disabled
   Shadow maps: Not supported
   GLSL       : Supported
      Vertex uniforms   : 256
             varyings   : 32
             attribs    : 16
      Fragment uniforms : 256
   Programs   : Vertex programs supported
      Vertex Instructions (native): 128 (128)
             TEMPs (native)       : 12 (12)
             PARAMs (native)      : 96 (96)
             ATTRIBs (native)     : 16 (16)
   Texunits   : 2
WARNING: Light "Spot" ShadowBufferSize is evil.
         Forcing to good value: 2048
Compiling Shader: vertex.vs:
(28) : warning C7011: implicit cast from "float4" to "float3"
(28) : warning C7011: implicit cast from "float4" to "float3"
(28) : warning C7011: implicit cast from "float4" to "float3"
(28) : warning C7011: implicit cast from "float4" to "float3"
39 lines, 8 warnings, 0 errors.

SM_Scene::~SM_Scene: There are still objects in the Sumo scene!
sys_init:warning - no sitedirs added from site module.

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

Post by rstralberg »

@sutabi

I also think your card is not supporting it

Here is my card

Code: Select all

GLEW: 1.2.3
RAS_OpenGLRasterizer:
   GL Vendor  : NVIDIA Corporation
   GL Renderer: GeForce FX 5200/AGP/SSE2
   GL Version : 1.5.1
   Colour     : 24 bits (8/8/8/0)
   Accum      : 64 bits (16/16/16/16)
   Depth      : 24 bits
   Stencil    : 0 bits
   Multisample: Disabled
   Stereo     : Disabled
   Shadow maps: Supported
   GLSL       : Supported
      Vertex uniforms   : 256
             varyings   : 32
             attribs    : 16
      Fragment uniforms : 128
   Programs   : Vertex & Fragment programs supported
      Vertex Instructions (native): 256 (256)
             TEMPs (native)       : 16 (16)
             PARAMs (native)      : 256 (256)
             ATTRIBs (native)     : 16 (16)
      Fragment Instructions (native): 1024 (1024)
           ALU Instructions (native): 1024 (1024)
           TEX Instructions (native): 1024 (1024)
           TEX Indirections (native): 1024 (1024)
               TEMPs (native)       : 32 (32)
               PARAMs (native)      : 1024 (1024)
               ATTRIBs (native)     : 16 (16)
   Texunits   : 16
I notice that your card does only support vertex programs
and not fragment program. So that may be the problem.

/roland

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

Post by alien-xmp »

Yeah the Geforce 2 doesn't support fragment programs (and will be emulating vertex programs in software)

Strange that it says it supports GLSL though...

NB: the Programs: line is for ARB_vertex_program and ARB_fragment_program, not GLSL.

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

Post by Doc_Holiday »

I found a nice, small and free OpenGL Analysis-Tool for Win and Mac. If You want to know what Your Card can do? Check this out: *here*.
Doc

Post Reply