Create Stunning Tileable Textures with Material Stable Diffusion Cognitive Actions

24 Apr 2025
Create Stunning Tileable Textures with Material Stable Diffusion Cognitive Actions

In the world of digital art and game design, generating seamless and tileable textures is crucial for creating immersive environments. The Material Stable Diffusion Cognitive Actions provide developers with a powerful way to create these textures using a modified Stable Diffusion model. By leveraging circular convolution, this API allows you to generate high-quality, tileable images with ease. In this article, we will explore how to use the Generate Tileable Textures Using Stable Diffusion action, detailing its capabilities and integration into your applications.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with JSON structure, as you'll be sending and receiving JSON payloads.

Authentication typically involves passing your API key in the request headers, which we'll demonstrate in the examples.

Cognitive Actions Overview

Generate Tileable Textures Using Stable Diffusion

The Generate Tileable Textures Using Stable Diffusion action enables you to create seamless, tileable images by defining a prompt and image dimensions. This action is particularly useful for artists and developers looking to produce textures for backgrounds, game assets, or other creative projects.

Input

The input for this action consists of several fields defined in the schema:

  • mask (string, optional): URI of a black and white image used as a mask for inpainting. Black pixels are modified, while white pixels remain unchanged. Best combined with a prompt strength between 0.5 and 0.7.
  • seed (integer, optional): A random seed for image generation. If left blank, a randomized seed will be used.
  • width (integer): The output image width, with permitted sizes of 128, 256, 512, 768, or 1024 pixels. Default is 512.
  • height (integer): The output image height, with the same size limitations as width. Default is 512.
  • prompt (string): A description of the imagery to generate, forming the basis of the output.
  • initialImage (string, optional): URI of the initial image to modify. This image will be resized according to specified dimensions.
  • guidanceScale (number): A scale factor for classifier-free guidance, controlling how closely the image adheres to the prompt. Valid range is 1 to 20, with a default of 7.5.
  • promptStrength (number): The strength of the prompt's effect when using an initial image. Ranges from 0 to 1, default is 0.8.
  • numberOfOutputs (integer): Specifies how many images to generate (1 or 4). Default is 1.
  • numberOfInferenceSteps (integer): Number of denoising steps during generation, affecting detail and quality. Valid range is 1 to 500, default is 50.

Here’s an example JSON payload that illustrates how to structure the input:

{
  "width": 512,
  "height": 512,
  "prompt": "Mossy Runic Bricks seamless texture, trending on artstation, stone, moss, base color, albedo, 4k",
  "guidanceScale": 7.5,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

The output of this action will typically return a URL pointing to the generated tileable texture. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/c0e517b5-899f-467e-ae79-f6fe7ac64877/8ef4c579-cb79-4532-9188-e352eeaed8b0.jpg"
]

Conceptual Usage Example (Python)

Here's how you might call this action using Python. This example illustrates how to structure the input JSON and handle the API request:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "6a2e4637-73ad-4e89-8fb6-f9c0fce63f81" # Action ID for Generate Tileable Textures

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "Mossy Runic Bricks seamless texture, trending on artstation, stone, moss, base color, albedo, 4k",
    "guidanceScale": 7.5,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 50
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet:

  • You replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The payload variable is structured according to the input requirements.
  • The response is processed to handle any potential errors gracefully.

Conclusion

The Generate Tileable Textures Using Stable Diffusion action offers a powerful tool for developers and artists seeking to create high-quality, seamless textures. By following the steps outlined above, you can easily integrate this functionality into your applications, enhancing the visual quality of your projects. Explore the possibilities of generating unique textures and elevate your creative work with the capabilities of Cognitive Actions!