This topic uses a Three Kingdoms-themed tower defense game, Arrow Tower Defense, as an example to show how to use the Hologres AI Function with SQL to automatically generate themed character images, a storyboard, and a 10-second ad video from raw game assets.
Background
In the gaming industry, producing ad creatives is a core part of user acquisition and version release campaigns. Especially in performance marketing, teams often need to generate large batches of video and image ad creatives with different styles, themes, and selling points in a short period. This helps them test click-through rates, conversion rates, and user preferences.
Traditional ad production relies on manual work for asset collection, creative planning, poster design, storyboard writing, and video editing. This approach has several pain points:
Scattered raw assets: Character art, backgrounds, item icons, game descriptions, and marketing copy are often stored in different systems, making them difficult to manage centrally.
Low creative production efficiency: Each ad requires brainstorming a theme, selecting assets, writing a script, and producing a video from scratch.
High cost of multi-version testing: Performance marketing requires extensive A/B testing, and manual methods cannot support frequent iterations.
Disconnect between ad delivery and creatives: There is often no unified system to track ad creatives, script versions, and performance data, preventing an effective optimization loop.
Using the Hologres AI Function, you can connect raw game asset management, creative generation, marketing content creation, and ad performance analysis, forming a complete, AI-powered workflow for ad video production.
Benefits
The core value of this solution is using Hologres as an AI asset production hub that integrates multi-model capabilities to automate intelligent ad creative generation.
All-SQL pipeline: Data engineers can call AI models, integrate assets, and generate intelligent marketing content entirely within Hologres using only SQL. This significantly lowers the technical barrier to entry.
Unified management of game assets: You can use Hologres tables to manage various game assets, including multimodal data such as images, videos, and audio. This data can be easily combined with ad performance data for analysis.
End-to-end automation: The entire process is automated, from generating character variations and storyboards to producing the final video. This allows you to produce content in minutes.
High scalability: The solution supports batch generation of marketing content for multiple scenarios, greatly improving content production and delivery efficiency.
Workflow
The following steps describe the end-to-end workflow for generating game ad videos using the AI Function:
Store raw game information and assets in Hologres.
Use the qwen-image model to generate a library of themed images from the raw assets.
Use a prompt to retrieve themed images and generate a storyboard using the qwen-max large model.
Use the themed images, storyboard, and wan model to generate the game ad video.
Select the most suitable ad video for your campaign.
Prerequisites
You have created a Hologres instance of V3.2 or later.
You have deployed the required AI models in Hologres. These include an image generation model (such as the qwen-image series), a text generation model (such as the qwen series), and a video generation model (such as the wan series). For deployment instructions, see AI models and deployment.
You have prepared an OSS bucket to store the generated images and videos, and you have configured the necessary RAM role and permissions.
Step 1: Prepare the game asset table
Create a table in Hologres to store basic game information and the paths to raw assets.
-- Create a table for game information
CREATE TABLE game_info(
name TEXT,
intro TEXT,
motivation TEXT,
art_style TEXT,
material_list TEXT[]
);
-- Insert game information
INSERT INTO game_info (name, intro, motivation, art_style, material_list)
VALUES (
'Arrow Tower Defense',
'Arrow Tower Defense is a lighthearted and casual Three Kingdoms tower defense game. In the turbulent Three Kingdoms era, you will become a commander responsible for defending your territory!
Gameplay:
1. Drag and drop various defense towers onto preset paths.
2. Click to upgrade existing towers and increase their power.
3. At critical moments, click to unleash hero skills and turn the tide of battle.',
'Strategy tower defense',
'Flat, Chinese-style, minimalist chibi characters',
ARRAY[
'oss://<BucketName>/images/liubei.png',
'oss://<BucketName>/images/lvbu.png'
]
);The material_list column stores the OSS paths to the original character images.
Asset examples: In-game images such as characters and backgrounds.
oss://ai-demo-dataset/images/liubei.png | oss://ai-demo-dataset/images/lvbu.png |
|
|
Liu Bei | Lu Bu |
Step 2: Create a themed prompt table
To generate a variety of ad creatives, you can derive different theme styles from the original character images.
-- Create a table for theme style prompts
CREATE TABLE video_style(
name TEXT PRIMARY KEY,
prompt TEXT
);
-- Insert prompts for different themes
INSERT INTO video_style VALUES
('Warlord of the North', 'Keep the character portrait unchanged. Generate a chibi character wearing heavy, black, fur-collared metal armor covered in frost and battle scars. Use cool blue lighting for an epic, cinematic feel with stunning detail.'),
('Sword Saint of the Cloud Sea', 'Keep the character portrait unchanged. Generate a chibi character of an elegant Three Kingdoms strategist transformed into a Taoist Sword Saint. He wears a moon-white, wide-sleeved robe with faint ink wash landscape patterns.'),
('Netherworld Nightwalker', 'Keep the character portrait unchanged. Generate a chibi character as a mysterious shadow assassin. The character wears matte black, close-fitting night gear with a mask covering half of the face.'),
('Golden Armor', 'Keep the character portrait unchanged. Generate a chibi character wearing an extremely ornate golden armor decorated with dragon patterns and jewels, with a scarlet silk cloak.');Step 3: Generate a themed image library
Generate an image for each character and theme. In this example, you generate four themed images for each of the two characters by calling the qwen-image-2.0-pro model.
-- Create a table to store the results of the image generation
CREATE TABLE generated_images(
game_name TEXT,
style_name TEXT,
style_desc TEXT,
character1 TEXT,
character2 TEXT
);
-- Batch generate themed images and store the results
WITH person_prompt AS (
SELECT game_info.name AS game_name,
video_style.name AS style_name,
material_list[1] AS character1,
material_list[2] AS character2,
prompt
FROM game_info, video_style
WHERE game_info.name = 'Arrow Tower Defense'
),
gen_image AS (
SELECT game_name, style_name, prompt AS style_desc,
ai_gen('qwen_image', json_build_object(
'prompt', prompt,
'reference_urls', array[character1],
'parameters', json_build_object(
'size', '1280*720',
'n', 1,
'watermark', false
),
'output_dir', 'oss://<BucketName>/images/'
)::text, to_file(character1, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')) AS obj1,
ai_gen('qwen_image', json_build_object(
'prompt', prompt,
'reference_urls', array[character2],
'parameters', json_build_object(
'size', '1280*720',
'n', 1,
'watermark', false
),
'output_dir', 'oss://<BucketName>/images/'
)::text, to_file(character2, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')) AS obj2
FROM person_prompt
),
image_urls AS (
SELECT game_name, style_name, style_desc,
obj1::json->'image_oss_paths' ->> 0 AS character1,
obj2::json->'image_oss_paths' ->> 0 AS character2
FROM gen_image
)
INSERT INTO generated_images SELECT * FROM image_urls;When the query finishes, the generated_images table contains the OSS paths of the generated images for each character and theme.

Liu Bei | Lu Bu |
|
|
|
|
|
|
|
|
Step 4: Generate a storyboard
Use the themed images as video assets and call a large language model to generate a storyboard for the ad.
-- Create a prompt template table
CREATE TABLE prompts (
id BIGINT,
prompt TEXT
);
-- Insert a prompt template for storyboard generation
INSERT INTO prompts VALUES (10,
'Your task is to generate a 10-second video script for a mobile game ad creative.
<GameName>{0}</GameName>
<GameIntro>{1}</GameIntro>
<PlayerMotivation>{2}</PlayerMotivation>
<ArtStyle>{3}</ArtStyle>
<ImageAssets>{4} {5}</ImageAssets>
Video Structure:
1. Opening (2 seconds): Select one image, display the game name, and show exaggerated special effects.
2. Middle (6 seconds): Showcase one core gameplay mechanic. Select two images and describe character actions and effects.
3. Ending (2 seconds): All characters appear on screen. Use a call to action.
Requirements: The script must focus on player motivation, be no longer than 10 seconds, and use the full image paths.');Use the template to generate a storyboard by calling the qwen3.5-plus model:
-- Generate the storyboard
WITH game_material AS (
SELECT * FROM game_info
LEFT JOIN generated_images ON name = game_name
WHERE game_name = 'Arrow Tower Defense' AND style_name = 'Sword Saint of the Cloud Sea'
),
tmp_prompt AS (
SELECT json_build_object(
'prompt', prompt,
'args', json_build_array(
name, intro, motivation, art_style,
to_file(character1, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>'),
to_file(character2, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')
)
) AS prompt, character1, character2
FROM game_material, prompts WHERE id = 10
),
story_script AS (
SELECT ai_gen('qwen3_5_plus', prompt::text,
to_file('oss://<BucketName>/images/placeholder.png',
'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')) AS script,
character1, character2
FROM tmp_prompt
)
SELECT script FROM story_script;Example of a generated storyboard:

Step 5: Generate the video
After generating the storyboard, use the script and themed images with the video generation model to create the ad video. This example uses the wan2.6-r2v-flash model.
-- Generate the ad video (combines script and video generation in one step)
WITH game_material AS (
SELECT * FROM game_info
LEFT JOIN generated_images ON name = game_name
WHERE game_name = 'Arrow Tower Defense' AND style_name = 'Sword Saint of the Cloud Sea'
),
tmp_prompt AS (
SELECT json_build_object(
'prompt', prompt,
'args', json_build_array(
name, intro, motivation, art_style,
to_file(character1, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>'),
to_file(character2, 'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')
)
) AS prompt, character1, character2
FROM game_material, prompts WHERE id = 10
),
story_script AS (
SELECT ai_gen('qwen3_5_plus', prompt::text,
to_file('oss://<BucketName>/images/placeholder.png',
'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')) AS script,
character1, character2
FROM tmp_prompt
)
SELECT character1, character2,
ai_gen('wan_26_r2v_flash', json_build_object(
'prompt', script,
'reference_urls', array[character1, character2],
'parameters', json_build_object(
'size', '1280*720',
'duration', 10,
'shot_type', 'multi',
'audio', true,
'watermark', true
),
'output_dir', 'oss://<BucketName>/videos/'
)::text,
to_file('oss://<BucketName>/images/placeholder.png',
'oss-cn-hangzhou-internal.aliyuncs.com',
'acs:ram::<AccountId>:role/<RoleName>')) AS video_result,
script
FROM story_script;When the query finishes, the video_url field in the result contains the URL of the generated ad video. The video is also saved to the specified OSS directory.
Step 6: Preview the generated videos
Generated videos:
Warlord of the North
Sword Saint of the Cloud Sea









