Jump to content

MaterialDrawCallback()


Flexman
 Share

Recommended Posts

I was going to use MaterialDrawCallback() to bind user skins for different vehicles. This callback is supposed to return a pointer to the entity being rendered no?

 

Any attempt to access TEntity properties results in an exception even though it's not a null pointer. Not really sure what's going on with that.

 

Function MaterialCallback(material:TMaterial, entity:TEntity)
  if (entity.material)
     // kablewie
  endif
End Function

 

Just wondered if anyone else has tried this and got it to work OK? Seemed like a reasonable way to create non-instanced player skins.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

  • 8 months later...

I also have the same problem.

I'm using this in C and actually the entity is always NULL.

However the number of times this callback is called is correct.

 

Anyone have ever used this callback?

Ali Salehi | Programmer

 

Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64

LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17

 

 

76561198023085627.png

Link to comment
Share on other sites

This code is printing

 

.............

 

Camera

Directionallight

Camera

Directionallight

Camera

Directionallight

Camera

Directionallight

Camera

Directionallight

Camera

Directionallight

Camera

Directionallight

Camera

...........

 

Framework leadwerks.engine
registerabstractpath AppDir
Graphics 800,600
createworld
cp=createpivot()
cam=createcamera()
entityparent cam,cp
moveentity cam,vec3(0,5,-5)
pointentity cam,cp
b=createbuffer(800,600,BUFFER_COLOR|BUFFER_NORMAL|BUFFER_DEPTH)
lt=createdirectionallight()
moveentity lt,vec3(1,2,3)
pointentity lt,cp
c=createcube()
mat=creatematerial()
setmaterialcolor mat,vec4(1,0,0,1)
paintentity c,mat
Function on_paint(mat:tmaterial,ee:TList)
For e:tentity=EachIn ee
 Print getentitykey(e,"class")
Next
End Function
setMaterialCallback mat,on_paint,MATERIALCALLBACK_ENABLE
Repeat

If KeyHit(27) Or AppTerminate() End

turnentity cp,vec3(0,.1,0)

setbuffer b
renderworld
setbuffer backbuffer()
renderlights b
Flip 1

Forever

 

seems like second function parameter is the list of cameras\lights

 

Want to know how to use it myself

"Better" is big enemy of "good"

Link to comment
Share on other sites

http://leadwerks.com/wiki/index.php?title=SetEntityCallback

 

 

ph34r.png it's not here

"Better" is big enemy of "good"

Link to comment
Share on other sites

I was talking about MATERIALCALLBACK_DRAW.

The wiki says:

Gets called for every instance that is drawn that has this material. Using this will disable fast instanced rendering for any entities with that material.

 

So I think if the entity is not passed to the callback, it would be useless.

So I assume it as a bug.

 

Another question: will the entity draw callback called exactly when the entity is being drawn?

For example if I change shader uniforms in this callback, will these changes be applied to each entity, or the last change to all the entities?

Ali Salehi | Programmer

 

Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64

LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17

 

 

76561198023085627.png

Link to comment
Share on other sites

I don't get how it works

It was the original question Aily.

The entity is not being passed to the material draw callback.

So any function on that entity will result in a crash.

In C, the entity is always NULL.

Ali Salehi | Programmer

 

Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64

LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17

 

 

76561198023085627.png

Link to comment
Share on other sites

It was the original question Aily.

The entity is not being passed to the material draw callback.

So any function on that entity will result in a crash.

In C, the entity is always NULL.

 

As you can see - in my function in BMax - i don't do any with entity, line inside function is commented. And error spawn on renderworld.

:) Good if it works in C.

 

P.S. Yeah, i'm some mistaked with callback names before...

"Better" is big enemy of "good"

Link to comment
Share on other sites

As you can see - in my function in BMax - i don't do any with entity, line inside function is commented. And error spawn on renderworld.

smile.png Good if it works in C.

 

P.S. Yeah, i'm some mistaked with callback names before...

Sorry. I didn't know that ' is for commenting in BMax.

 

Yeah it's working, if the NULL entity is assumed correct tongue.png

Ali Salehi | Programmer

 

Intel Core i3 2100 @ 3.0GHz | GeForce GTS 450 | 4GB DDR3 RAM | Windows 7 Ultimate x64

LE 2.50 | Visual Studio 2010 | RenderMonkey 1.82 | gDEBugger 5.8 | FX Composer 2.5 | UU3D 3 | xNormal 3.17

 

 

76561198023085627.png

Link to comment
Share on other sites

Last news

This function don't have entity, and don't be work as we supposed. Wiki is wrong, wee need always look only to

http://www.leadwerks.com/werkspace/page/Documentation/le2/_/command-reference/

 

I maked not instanced materials, but for this i creating copy of mesh on HDD, load id, delete from HDD - have not instanced model, but materials is instaced.

 

Parse all it surfaces, and same write copyes of materials to HDD, load it, assign, delete from HDD.

 

Same with shaders...

 

Looks like there is no another way.

"Better" is big enemy of "good"

Link to comment
Share on other sites

At the point materials and shaders are enabled in the rendering pipeline, the code has no idea what entities are being drawn. All it has is a 4x4 matrix. Materials are not enabled per-entity. They are enabled once for each batch of surfaces drawn.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

It easy to hack your engine for you Josh

Just add funtion LoadUniqueMesh that will be add system time value to mesh,materials and shaders filenames before loading it.

And engine will think - that it's absolute separate mesh with separate materials.

And all will be happy biggrin.pngrolleyes.gif

"Better" is big enemy of "good"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...