Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    creating instance of procedural texture, write it

    SDK Help
    0
    15
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 08/08/2014 at 15:54, xxxxxxxx wrote:

      seems good, but can I extract an output texture from that procedural texture? for example 1K resolution of that procedural surface texture?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 09/08/2014 at 01:20, xxxxxxxx wrote:

        You can sample a procedural shader with BaseShader.Sample(cd).

        « shader » is your BaseShader.

        from c4d.modules.render import ChannelData, InitRenderStruct  
          
        irs = InitRenderStruct()  
        init = shader.InitRender(irs)  
        if init != c4d.INITRENDERRESULT_OK : return  
        cd = ChannelData()  
          
        cd.p = Vector() # The point to render  
        color = shader.Sample(cd) # The output color  
          
        shader.FreeRender()
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 09/08/2014 at 12:28, xxxxxxxx wrote:

          I totally understand sampling, but this is kinda a bad approach ( I got my own samplers, so I just need the texture of the procedural texture)

          isn't there a direct approach of just extracting the result of procedural texture without using the whole shader system?

          I see in the worst case I would create an invisible plane with 1024 * 1024 polygons, assign a shader with luminance channel with the required procedural texture, then sample this, but this is an ugly slow approach 😞

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 09/08/2014 at 14:26, xxxxxxxx wrote:

            There is the problem (but no easy programmatic solution presented).  Sampling out an image texture from a procedural texture requires some parameters such as size.  The choice of size will affect how the texture renders because of its parameters (it gets even worse for 3D procedurals).  For the most part, procedural textures are applied at the point of render in the realm of texture space (UVW or whatever projection is in use).  One way to achieve what you want without sample per pixel is to define a scene with a rectangular polygon containing the texture, pointing directly at the camera with the simplest lighting scheme and rendering that out as an image.  No need to sample but your results will depend upon the render settings, lighting, render size vs. procedural parameters and so forth.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 09/08/2014 at 15:00, xxxxxxxx wrote:

              @Robert I thought of this too 🙂 "similar to what I said in the previous reply", but it is kinda a huge work around "if the user has 20 different procedural textures of size 2k this may lead to a long pre-process?"

              now rises 2 questions:
              1- what about baking?
              2- I thought that the procedural texture is just a function which takes an input point (x,y,z) "z is optional for 3d textures", and the values (x,y,z) are [0,1] , this makes sampling much easier you know what I mean

              may be this is how it is done in displacement deformer?

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 10/08/2014 at 05:26, xxxxxxxx wrote:

                There should be a way, in my mind, to do what you are asking..  When i was looking at using noise in a displacement recently, i was literally searching the entire API for any instance of noise - and there are a lot of instances.  It`s a bit of a maze tbh, there are various references to noise in the API as well as Modules folders but i did eventually find what i was looking for..

                I think my point is, maybe try digging deeper into all of those references to noise in the API, and find out what the differences are.  Not all of them are just used for shaders..

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 10/08/2014 at 08:49, xxxxxxxx wrote:

                  Baking might be an option.

                  There are more parameters than procedurally creating a sample at some x,y in the texture space. There might be tilings in both or either the texture itself and possibly the Texture tag.  What if other shaders or material channels are being applied that may affect the procedural shader in question?

                  Because of these factors, not even considering lighting, shading, and other contributions to the rendering process, sampling the C4D shader as a passthrough to your render engine may be the only option.

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 10/08/2014 at 10:36, xxxxxxxx wrote:

                    well, it is just about "luxury" option in my rendering engine, wanted to give the artist more procedural textures which they are used to in Cinema4D, and material applying, Tiling, ... all can be done the same with a known texture instead of procedural texture "same concept"

                    so now I guess the only solution "possibly the fastest" is to create a template plane with its camera, and apply this texture to luminance channel and render this plane alone, any example in the SDK for rendering in the background? so I can catch the result internally

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 10/08/2014 at 11:14, xxxxxxxx wrote:

                      what about catching the texture preview slot!! ? I tested it in Cinema4D and it produces exactly what I want, any help here?

                      I want to size the texture preview slot , then catch whatever is there

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 10/08/2014 at 14:30, xxxxxxxx wrote:

                        You can set the Texture Preview Size in the Editor tab of the Material.  Don't see a similar option for Shaders though.  Use Material::GetPreview() to get a bitmap (BaseBitmap) of the texture preview. There is also a BaseShader::GetBitmap() (see docs).

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          On 10/08/2014 at 14:44, xxxxxxxx wrote:

                          @Robert thanks a lot!!, seems like what I need,but there is something that confuses me, what is the base class of procedural textures? (noise and others), I think it should be possible to create an instance of these procedural textures anywhere in Cinema4D "like xpresso, displacement deformer, ..."

                          so it would be like: //pseudo code

                          BaseTextureClass *MyTexture = new ....;
                          MyTexture->setPreviewSize(size);
                          MyTexture->getPreview(bitmap);

                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            On 10/08/2014 at 15:12, xxxxxxxx wrote:

                            Not sure if it helps but this is how i create my noise shader:

                            //// NOISE BASE ////
                            BaseShader *noiseBase = BaseShader::Alloc(Xnoise);
                            BaseContainer *noiseData_BASE = noiseBase->GetDataInstance();
                            noiseData_BASE->SetLong(SLA_NOISE_NOISE, 2007); //Noise Type - DISP_TURB
                            noiseData_BASE->SetReal(SLA_NOISE_OCTAVES, 20);
                            noiseData_BASE->SetReal(SLA_NOISE_GLOBAL_SCALE, 35);
                            noiseData_BASE->SetReal(SLA_NOISE_LOW_CLIP, 0);
                            noiseData_BASE->SetReal(SLA_NOISE_HIGH_CLIP, 1);
                            noiseData_BASE->SetReal(SLA_NOISE_BRIGHTNESS, -0.04);
                            noiseData_BASE->SetReal(SLA_NOISE_CONTRAST, 0.81);
                            noiseData_BASE->SetLong(SLA_NOISE_SEED, (rand() % 1000));
                            op->InsertShader((BaseShader* )noiseBase, NULL);
                            

                            And here`s how i drop it into a Fusion shader and apply to a Displace object:

                            //// FUSION MAP ////
                            BaseShader *fusion1 = BaseShader::Alloc(Xfusion);
                            BaseContainer *fusionData = fusion1->GetDataInstance();
                            fusionData->SetBool(SLA_FUSION_USE_MASK, TRUE);
                            fusionData->SetReal(SLA_FUSION_BLEND, 0.79);
                            fusionData->SetLink(SLA_FUSION_BASE_CHANNEL, noiseBase);
                            fusionData->SetLink(SLA_FUSION_MASK_CHANNEL, noiseMask);
                            fusionData->SetLink(SLA_FUSION_BLEND_CHANNEL, noiseBlend);
                            op->InsertShader(fusion1, NULL);
                              
                            //// DISPLACER OBJECT ////
                            BaseObject *dP1 = BaseObject::Alloc(1018685);
                            BaseContainer *dispData = dP1->GetDataInstance();
                            dispData->SetReal(MGDISPLACER_DISPLACEMENT_HEIGHT, 65);
                            dispData->SetReal(MGDISPLACER_DISPLACEMENT_STRENGTH, 0.6);
                            dispData->SetLong(MGDISPLACER_DISPLACEMENTMODE, MGDISPLACER_DISPLACEMENTMODE_INTENSITY);
                            dispData->SetLong(MGDISPLACER_POLYNORMALMODE, MGDISPLACER_PLANARNORMAL);
                            dispData->SetLong(PRIM_AXIS, PRIM_AXIS_XP);
                            dispData->SetLink(ID_MG_SHADER_SHADER, fusion1);
                            
                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              On 10/08/2014 at 15:31, xxxxxxxx wrote:

                              @Eclectrik excellent!! Shift+R improves the quality of this image. Shift+A improves the quality of all images on this page., I think this is exactly what I need, thanks a lot,and this definitely helped me already

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post