Thread: [Maya2osg-users] Customized GLSL shaders
Status: Alpha
Brought to you by:
jtaibo
From: Javier T. <jav...@gm...> - 2011-05-21 22:32:18
|
Hi, I have added four new options to the exporter that allow to append custom GLSL code to the shaders exported. -additionalVertexDeclarations <file> -additionalVertexCode <file> -additionalFragmentDeclarations <file> -additionalFragmentCode <file> This way custom declarations can be appended at the end of the shader (vertex or fragment) declarations (i.e. uniforms, varyings, etc.) and custom computations can be added at the end of the shader main() function. It is important to note that they are at the end because this way users can override computations of the default shader, i.e. the custom code has higher precedence. What the user specifies in these command line parameters is the path of a file containing the GLSL code (not the code itself). If any of these options is not supplied, no custom code in this part of this shader is added (unlike most of the other parameters, these don't keep the value of the last invocation). There is an UI option to enable the custom code feature and four corresponding to the four code blocks above mentioned. And here, Peter, I'm going to ask for your skills on Maya UI creation. I created 5 new optionVars and the UI for them (basically copy & paste of your code :). Please, review it when you have time, just in case I have done some nonsens. I also put "Browse" buttons after the text boxes, but I don't know what is the most adequate way to make it work and the script is growing dangerously, so I don't want to complicate it further. Can you take a look at it, please? It would be nice also to enable/disable the four text box / browse buttons depending on the checkbox "Custom GLSL code". Also, the fragment shaders are now writing to gl_FragData[0] instead of gl_FragColor, to allow the use of multiple render targets. In fact, the additional code is especially useful to add the code that computes the value of output in these other render targets (e.g. motion vectors in my case). Btw, Peter, the "reloading" bug of the plug-in is fixed. The new command was not unregistered when unloading the plug-in and this was the reason it failed to load the plug-in again. My mistake! Regards, -- Javier Taibo |
From: Peter W. <pp...@cg...> - 2011-05-24 07:06:31
|
Hi Javie, > > > There is an UI option to enable the custom code feature and four > corresponding to the four code blocks above mentioned. And here, > Peter, I'm going to ask for your skills on Maya UI creation. I created > 5 new optionVars and the UI for them (basically copy& paste of your > code :). Please, review it when you have time, just in case I have > done some nonsens. I also put "Browse" buttons after the text boxes, > but I don't know what is the most adequate way to make it work and the > script is growing dangerously, so I don't want to complicate it > further. Can you take a look at it, please? It would be nice also to > enable/disable the four text box / browse buttons depending on the > checkbox "Custom GLSL code". > Working on that. Would be nice, if you could provide me some test scene and shader. You're right with the growing, thing should split it up somehow, but then there are lot of local functions which are needed almost everywhere. Will look into this. > Also, the fragment shaders are now writing to gl_FragData[0] instead > of gl_FragColor, to allow the use of multiple render targets. In fact, > the additional code is especially useful to add the code that computes > the value of output in these other render targets (e.g. motion vectors > in my case). I would require motionvectors too, could you tell me how you are approaching this within one shader ? Thought one needs the same mesh from two different time stamps to get the position differences, but have not figured out the most efficient way store position mesh mesh data in a additional array. I tried to get Transfor Feedback to work, but I don't understand osgs extension mechanism well enough. So, how do you do it ? Cheers, PP |
From: Javier T. <jav...@gm...> - 2011-05-24 14:38:04
|
Hi, On Tue, May 24, 2011 at 9:06 AM, Peter Wrobel <pp...@cg...> wrote: >> There is an UI option to enable the custom code feature and four >> corresponding to the four code blocks above mentioned. And here, >> Peter, I'm going to ask for your skills on Maya UI creation. I created >> 5 new optionVars and the UI for them (basically copy& paste of your >> code :). Please, review it when you have time, just in case I have >> done some nonsens. I also put "Browse" buttons after the text boxes, >> but I don't know what is the most adequate way to make it work and the >> script is growing dangerously, so I don't want to complicate it >> further. Can you take a look at it, please? It would be nice also to >> enable/disable the four text box / browse buttons depending on the >> checkbox "Custom GLSL code". > > Working on that. Would be nice, if you could provide me some test scene > and shader. The test shaders I am using do not work in a standard OSG viewer, unless you load it in the proper 3D engine you won't see anything. But for testing purposes any scene can do. Just add a fragment code like this: gl_FragData[0] = vec4(0.0, 1.0, 0.0, 1.0); And you'll test if it is working. Anyway, if you modify the UI let me know and I will test it also. > You're right with the growing, thing should split it up somehow, but > then there are lot of local functions which are needed almost > everywhere. Will look into this. I am OK with it, I let you its organization, I just didn't want to add more complexity nor to change the way to organize things. It is on your hands. > I would require motionvectors too, could you tell me how you are > approaching this within one shader ? > Thought one needs the same mesh from two different time stamps to get > the position differences, but have not figured out the most efficient > way store position mesh mesh data in a additional array. I tried to get > Transfor Feedback to work, but I don't understand osgs extension > mechanism well enough. So, how do you do it ? It is explained in the paper I am presenting next month in Vancouver. I'll send you the information. Regards, -- Javier Taibo |
From: Peter W. <pp...@cg...> - 2011-05-26 22:16:54
|
Hi Javier, I added the required functionality to the textfields. > > The test shaders I am using do not work in a standard OSG viewer, > unless you load it in the proper 3D engine you won't see anything. But > for testing purposes any scene can do. Just add a fragment code like > this: > > gl_FragData[0] = vec4(0.0, 1.0, 0.0, 1.0); > > And you'll test if it is working. > > Anyway, if you modify the UI let me know and I will test it also. The shader code does not end up in the osg file. Don't know what I'm doing wrong. I also shortened the envVars a little, and the lables of Textfields, they did not fit into the UI, but they are still self explanatory. I'm also suggesting different names for the maya2osg option Flags, to keep it all consistent. -glslVertDeclare instead of -additionalVertexdeclare -glslVertCompute instead of -additionalVertexCode -glslFragDeclare instead of -additionalFragmentdeclare -glslFragCompute instead of -additionalFragmentCode Cheers, PP |
From: Javier T. <jav...@gm...> - 2011-05-26 23:21:53
|
Hi Peter, On Fri, May 27, 2011 at 12:16 AM, Peter Wrobel <pp...@cg...> wrote: > > I added the required functionality to the textfields. Nice! > The shader code does not end up in the osg file. Don't know what I'm > doing wrong. You're passing the wrong options to the plug-in. Unless you have renamed them in osgwrite.cpp and not committed the changes. > I also shortened the envVars a little, and the lables of Textfields, > they did not fit into the UI, but they are still self explanatory. > > I'm also suggesting different names for the maya2osg option Flags, to > keep it all consistent. > > -glslVertDeclare instead of -additionalVertexdeclare > -glslVertCompute instead of -additionalVertexCode > > -glslFragDeclare instead of -additionalFragmentdeclare > > -glslFragCompute instead of -additionalFragmentCode I'm OK with it. You're right in that I left these names inconsistent (in some places I said "compute" and others "code"). I think compute is more adequate, as the declarations are also code, after all. One other thing, Apart from the options being wrong, I tried it and the scripts are not loading the plug-in as always. I had to manually load it to be able to export a scene. I saw you changed a lot of code but I didn't take a deep look at it. I think I wouldn't have too much time these days. Regards, -- Javier Taibo |
From: Peter W. <pp...@cg...> - 2011-05-27 07:08:01
|
Hi Javier, >> The shader code does not end up in the osg file. Don't know what I'm >> doing wrong. > You're passing the wrong options to the plug-in. Unless you have > renamed them in osgwrite.cpp and not committed the changes. Till now I only changed UI element names and envVars, but I kept the flags that are send to the plug-in untouched, so this shouldn't be the issue. > I'm OK with it. You're right in that I left these names inconsistent > (in some places I said "compute" and others "code"). I think compute > is more adequate, as the declarations are also code, after all. > O.K., I will change the flags in the plugin to the suggested ones > One other thing, Apart from the options being wrong, I tried it and > the scripts are not loading the plug-in as always. I had to manually > load it to be able to export a scene. I saw you changed a lot of code > but I didn't take a deep look at it. I think I wouldn't have too much > time these days. > > Will look into this, should be fixed today. Some more stuff from my side, I will start editing the cmake files as well, but need some assitance in the begining. The maya2osg_utility.mel needs to be installed properly. I found 2 files to edit and 2 deprecated VS files: configure_installer.cmake maya2osg-maininstaller.iss maya2osg.vcxproject maya2osg.vcxproject.filters I will edit all 4 files ( with allmighty copy and paste tool :-) ), please to confirm. For my understanding, about the new textfields, and to be able to test functionality: Vertex / Fragment Declare are injected into GLSL code after the existing declaration block and before any procedure definition. Vertex / Fragment Compute are injected at the end of the GLSL code, so in the main procedure befor the closing braces. Is this right ? In an earlier mail you mentioned that the injection happens if ALL the textfields do specify a file, is this correct ? Is there in no case, where one wants to just overwrite the Fragment color, without the need for any other ( Declare / Compute ) requirement ? Cheers, PP |
From: Javier T. <jav...@gm...> - 2011-05-27 07:54:24
|
Hi Peter On Fri, May 27, 2011 at 9:07 AM, Peter Wrobel <pp...@cg...> wrote: >>> The shader code does not end up in the osg file. Don't know what I'm >>> doing wrong. >> You're passing the wrong options to the plug-in. Unless you have >> renamed them in osgwrite.cpp and not committed the changes. > > > Till now I only changed UI element names and envVars, but I kept the > flags that are send to the plug-in untouched, so this shouldn't be the > issue. See this code snippet: if ( `optionVar -query "maya2osg_custom_shader_code"` ) { if ( `optionVar -query "maya2osg_glsl_vert_declare"` != "" ) { $command += " -additionalVertexdeclare \"" + `optionVar -query "maya2osg_glsl_vert_declare"` + "\"\n"; } if ( `optionVar -query "maya2osg_glsl_vert_compute"` != "" ) { $command += " -additionalVertexCode \"" + `optionVar -query "maya2osg_glsl_vert_compute"` + "\"\n"; } if ( `optionVar -query "maya2osg_glsl_frag_declare"` != "" ) { $command += " -additionalFragmentdeclare \"" + `optionVar -query "maya2osg_glsl_frag_declare"` + "\"\n"; } if ( `optionVar -query "maya2osg_glsl_frag_compute"` != "" ) { $command += " -additionalFragmentCode \"" + `optionVar -query "maya2osg_glsl_frag_compute"` + "\"\n"; } } The parameters -additionalVertexCode and -additionalFragmentCode are right (in fact they are working), but -additionalVertexdeclare and -additionalFragmentdeclare are wrong. This is the reason for this code not appearing in the shaders. If you didn't change it in revision 202, then svn is lying :) >> I'm OK with it. You're right in that I left these names inconsistent >> (in some places I said "compute" and others "code"). I think compute >> is more adequate, as the declarations are also code, after all. >> > > O.K., I will change the flags in the plugin to the suggested ones >> One other thing, Apart from the options being wrong, I tried it and >> the scripts are not loading the plug-in as always. I had to manually >> load it to be able to export a scene. I saw you changed a lot of code >> but I didn't take a deep look at it. I think I wouldn't have too much >> time these days. >> >> > Will look into this, should be fixed today. > > Some more stuff from my side, I will start editing the cmake files as > well, but need some assitance in the begining. What are you editing CMake for? > The maya2osg_utility.mel needs to be installed properly. I found 2 files > to edit and 2 deprecated VS files: > configure_installer.cmake > maya2osg-maininstaller.iss > maya2osg.vcxproject > maya2osg.vcxproject.filters Careful! Some of these are CMake scripts and others are generated by CMake (you can delete it without problem, and they are not in svn). Probably you only would need to edit the CMakeLists.txt file in the Maya2OSG root directory. Some of these files are for the Windows installer contributed by Ryan Pavlik in the osg-users mailing list. See this page: https://sourceforge.net/apps/mediawiki/maya2osg/index.php?title=Windows_installer > I will edit all 4 files ( with allmighty copy and paste tool :-) ), > please to confirm. Just be careful to know exactly what you are doing. > For my understanding, about the new textfields, and to be able to test > functionality: > Vertex / Fragment Declare are injected into GLSL code after the existing > declaration block and before any procedure definition. > Vertex / Fragment Compute are injected at the end of the GLSL code, so > in the main procedure befor the closing braces. > Is this right ? Right, I tried to explain it in this page: https://sourceforge.net/apps/mediawiki/maya2osg/index.php?title=Shading_Networks#Custom_GLSL_code If you don't find it clear or want to add something, feel free to edit it. > In an earlier mail you mentioned that the injection happens if ALL the > textfields do specify a file, is this correct ? > Is there in no case, where one wants to just overwrite the Fragment > color, without the need for any other ( Declare / Compute ) requirement ? No, no, no... I didn't say anything like that. Once you enable the "custom code" check box, then the fields that have any valid content will be used, the others will be simply ignored. If you don't pass any of these options to Maya2OSG, it just ignores the corresponding piece of code (doesn't remember the last value as other options). Regards, -- Javier Taibo |
From: Peter W. <pp...@cg...> - 2011-05-27 19:25:49
|
Hi Javier, > If you didn't change it in revision 202, then svn is lying :) Yeeees, caught in the act, I was lying big time :-) nope, sorry, serach and replace was my doom ! Will fix it right away. > > What are you editing CMake for? > I added a mel script called maya2osg_utility mel, and want to make sure that it gets installed like the other scripts. But if CMake is so sensitive it might be better to ask you for these things. > Careful! Some of these are CMake scripts and others are generated by > CMake (you can delete it without problem, and they are not in svn). > Probably you only would need to edit the CMakeLists.txt file in the > Maya2OSG root directory. Some of these files are for the Windows > installer contributed by Ryan Pavlik in the osg-users mailing list. > See this page: > > https://sourceforge.net/apps/mediawiki/maya2osg/index.php?title=Windows_installer Hm, for that purpose I downloaded the svn in a new folder and searched all the files for entry of the maya2osg_scripts. I read the wiki but still not sure what I need to edit. Could you tell me once so I know for feature please ? > Right, I tried to explain it in this page: > > https://sourceforge.net/apps/mediawiki/maya2osg/index.php?title=Shading_Networks#Custom_GLSL_code > > If you don't find it clear or want to add something, feel free to edit it. Cool, fist thing I will do in my holidays is learning the wiki, there is a lot of information that I am still not aware of. Its well enoght explained, and a cool concept. Do you still plan to give the option of completetly overwriting a shader ? I really should write something about the polygon export too ... >> In an earlier mail you mentioned that the injection happens if ALL the >> textfields do specify a file, is this correct ? >> Is there in no case, where one wants to just overwrite the Fragment >> color, without the need for any other ( Declare / Compute ) requirement ? > No, no, no... I didn't say anything like that. Once you enable the > "custom code" check box, then the fields that have any valid content > will be used, the others will be simply ignored. If you don't pass any > of these options to Maya2OSG, it just ignores the corresponding piece > of code (doesn't remember the last value as other options). > Missunderstood you here, but this is the behaviour I would expect. Cheers, PP |
From: Javier T. <jav...@gm...> - 2011-05-28 19:08:01
|
Hi Peter, On Fri, May 27, 2011 at 9:25 PM, Peter Wrobel <pp...@cg...> wrote: >> What are you editing CMake for? >> > > I added a mel script called maya2osg_utility mel, and want to make sure > that it gets installed like the other scripts. Don't worry then. Just throw it in the "scripts· directory where the other mel scripts lie and as long as it has ".mel" extension it will be installed. > Cool, fist thing I will do in my holidays is learning the wiki, there is > a lot of information that I am still not aware of. Its well enoght > explained, and a cool concept. Do you still plan to give the option of > completetly overwriting a shader ? I never said that. If you want to completely replace the shader, then you should follow the J-S approach. What I said was to override parts of the shader because the new code is added after the default one. That means that if you assign a value to a variable that is already assigned, this last value is what will remain. > I really should write something about the polygon export too ... Nice. It's first on my to-do list to take a look at it and begin with blend shapes export, but I didn't have time yet. Maybe next week, but I don't know, it's going to be a bit intense. Regards, -- Javier Taibo |