Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
This is how ID games does material checks
Topic Started: Sep 3 2010, 09:50 PM (286 Views)
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
A neat idea, which could help from some rendering performance aspects.


Posted Image


This is how it would work in Unity.

Code:
 
// Returns one of the HitType enumerations, which is created by you.
public HitType GetHitEffect ( RaycastHit in_hitInfo )
{
// This works with no null reference exceptions because of short circuiting
if (( in_hitInfo.collider != null )&&( in_hitInfo.collider.gameObject != null )&&( in_hitInfo.collider.gameObject.renderer != null ))
{
if ( in_hitInfo.collider.gameObject.renderer.material != null )
{
// Obviously, the following line requires a sort of custom shader
Texture2D t_hit_texture = (Texture2D)( in_hitInfo.collider.gameObject.renderer.material.GetTexture( "_HitMat" ) );
if ( t_hit_texture != null )
{
Color hit_color = t_hit_texture.GetPixel( in_hitInfo.textureCoord.x * t_hit_texture.width, in_hitInfo.textureCoord.y * t_hit_texture.height );
// Another function created by you
return GetHitTypeFromColor( hit_color );
}
}
}
return HitType.Generic;
}

private HitType GetHitTypeFromColor ( Color in_color )
{
// Since Color is a struct, this is totally safe
switch ( in_color )
{
case (new IntegerColor( 255, 255, 255, 255 )):
return HitType.Glass;
default:
return HitType.Generic;
}
}

// This just converts a Color (basically a struct of floats) into a comparable version
private IntegerColor ToIntegerColor ( Color in_color )
{
return new IntegerColor( (int)(in_color.r * 255), (int)(in_color.g * 255), (int)(in_color.b * 255), (int)(in_color.a * 255));
}

public struct IntegerColor
{
public int r, g, b, a;
public IntegerColor( int c1, int c2, int c3, int c4 )
{
r = c1;
g = c2;
b = c3;
a = c4;
}
}


I've tested it. It works fine. I'm not using it at the moment, however, seeing as I want to use the slower and easier to set up material system right now.
Blog|EHS
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
This could also be easily achieved in U3D by checking material ray intersection.
Offline Profile Quote Post Goto Top
 
luenardi
Member Avatar
Cofee Machines Rock
[ *  *  *  *  *  * ]
@Skarik
I'll keep this in mind.. Thanx alot dude. it's like you posted this just for me.
Edited by luenardi, Sep 4 2010, 09:27 AM.
Posted Image

For your perception no.
But my universe has no such limits.


www.recall.co.nr
Offline Profile Quote Post Goto Top
 
Eansis
Member Avatar
ghost
[ *  *  *  *  *  * ]
Am I understanding this incorrectly because this sounds like a bad idea. Since when is oil red? Using this you would have to limit yourself to whatever color's are the "typical" colors of things...or you would have to make an extra world mesh with color coding...in u3d it would be much easier to just go by material names and do a search for string eg CheckIntersectedMaterialIndex() if find_string_part(GetMaterialIndex)=water...that way you could have regular material names but just add their type at the end eg. texturename_water or texturename_dirt.
VOTE FOR BUDDY ROEMER HE'S A STRAIGHTFORWARD, DOWN TO EARTH AMERICAN GUY WHO ISN'T PART OF THE BIGBROTHER CONSPIRACY

Til'c
 
Things will not calm down Daniel Jackson. They will infact calm up.
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
It's a separate map that isn't used in rendering, but is defined in the material. Since rendering with a single material is much faster, it would be beneficial to have two or more material types in the same material. For example, an enemy might have both flesh and metal materials. Instead of using separate shaders and inducing more rendering (CPU to GPU) overhead just to get different hit particle effects and code, why not just look at the material-check map?

It's not possible to do this in Ultimate 3D, unless someone wants to make a raycast-hit-to-texture-coordinate conversion that's fast enough for real time. Then again, if you're trying to do this in Ultimate 3D, you shouldn't be using Ultimate 3D.
Blog|EHS
Offline Profile Quote Post Goto Top
 
luenardi
Member Avatar
Cofee Machines Rock
[ *  *  *  *  *  * ]
yeah.. these are way more high level toys.
This has been done for ages in a 2d style.. for menu's and so on..
There are quite a few ways to do this.. i like this one cuz a simple texture swap B4 texture & shader rendering would work very well.
You could do this materials in u3d.. but that would limit you to 8 types...
Posted Image

For your perception no.
But my universe has no such limits.


www.recall.co.nr
Offline Profile Quote Post Goto Top
 
« Previous Topic · Off-topic · Next Topic »
Add Reply