About Store Forum Documentation Contact
Donations:
227$/mo



Post Reply 
Custom shader in editor
Author Message
mystara Offline
Member

Post: #1
Custom shader in editor
Hi,

I've made a custom shader that I want to display in the editor. My shader can be applied to any material and any object type. It makes use of RM_BLEND mode.

The shader works, and is correctly loaded by the editor. However, it doesn't render. Obviously I need to specify that rendering in RM_BLEND mode is required.

But how do I do this for all object types that use my shader? I don't want to have to create a special MUT.
07-23-2012 01:34 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #2
RE: Custom shader in editor
Okay, I think what I want to do is apply the shader to all objects with that particular shader. So I would need to iterate through all world objects in Render().

Is that the best way to do it? Or is there a way to make all objects using a particular material to use the shader?
07-23-2012 10:32 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Custom shader in editor
Hi,

Did you check the shader tutorials?

Code:
ShaderTech* GetShader(RENDER_MODE mode, Material *material[4], UInt mesh_base_flag, Int lod_index, Bool allow_tesselation) // this is the function which will manually choose shaders for the meshes when needed
{
   if(material[0])switch(material[0]->user_shader) // test if the first material has 'user_shader' specified
   {
      case MUS_CUSTOM: // if it's set to custom
      {
         // set shader only for RM_BLEND mode, because this is the simplest mode to make shaders for
         if(mode==RM_BLEND)
         {
            return Shaders("User/Custom Shader")->firstTech(); // load the custom shader from shaders cache
         }else
         {
            return NULL; // return NULL so the mesh won't be displayed in any other rendering mode
         }
      }break;
   }

   // in other case
   return GetDefaultShader(mode, material, mesh_base_flag, lod_index, allow_tesselation); // return the default shader
}
instead of switch(material[0]->user_shader) you can do if(material[0]==..)
07-24-2012 03:24 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #4
RE: Custom shader in editor
Yes, I am already using that code. But although the shader works in my test application, it does not work in the editor.

After loading the texture, I think I need to do something to actually make the shader "run" on a mesh. In the tutorials, this seems to be accomplished by using a Render() function or overriding the drawBlend function for the object class.

Is that right so far?

Assuming it is, the tutorials show two ways to do this.

The first way is by using a Render() function. But this does not seem good for adding to the editor because I do not have access to all objects.

The second way is to override DrawBlend() for an object class. But this does not work well for me because I want my shader to work for all object classes that use my material.

I hope that makes sense. Sorry, I probably have the terminology wrong smile
07-24-2012 04:48 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #5
RE: Custom shader in editor
Ugh. Been playing around with this for a few more hours now and still no luck.

I've tried using a GetShader() function that always returns NULL and another one that always returns my shader. Either way, everything is rendered in exactly the same way - the shader does nothing.

And the function is definitely getting called. I ran it through gdb.
(This post was last modified: 07-24-2012 09:45 PM by mystara.)
07-24-2012 09:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Custom shader in editor
This code works correctly (modified the editor sources)

Code:
ShaderTech* GetShader(RENDER_MODE mode, Material *material[4], UInt mesh_base_flag, Int lod_index, Bool allow_tesselation)
{
   if(mode==RM_BLEND)return Shaders("..")->getTech("..");
   return NULL;
}
void InitPre()
{
   D.setGetShaderFunc(GetShader);
..
Note that you cannot modify shaders of the heightmaps (only of the objects)
07-29-2012 05:07 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #7
RE: Custom shader in editor
Ah, that works. Thanks
07-29-2012 05:24 PM
Find all posts by this user Quote this message in a reply
Post Reply