]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
Commit simple .vbs for automatic generation of shader from a textureset
authorJakob MG <jakob_mg@hotmail.com>
Sun, 26 Sep 2010 00:32:58 +0000 (02:32 +0200)
committerJakob MG <jakob_mg@hotmail.com>
Sun, 26 Sep 2010 00:32:58 +0000 (02:32 +0200)
misc/tools/shadescript/howto.txt [new file with mode: 0644]
misc/tools/shadescript/shade.vbs [new file with mode: 0644]
misc/tools/shadescript/template.shader [new file with mode: 0644]

diff --git a/misc/tools/shadescript/howto.txt b/misc/tools/shadescript/howto.txt
new file mode 100644 (file)
index 0000000..891b114
--- /dev/null
@@ -0,0 +1,9 @@
+First make sure your textures are in the correct paths, eg
+Correct: textures/yourset/wall/bricks.tga
+Wrong: textures/yourset/bricks.tga
+
+Copy shade.vbs and template.shader to textures/yourset/
+
+Edit the template.shader if you need non standard stuff
+
+Run the shade.vbs, copy textures/yourset/yourset.shader to scripts/yourset.shader, add yourset to scripts/shaderlist.txt
\ No newline at end of file
diff --git a/misc/tools/shadescript/shade.vbs b/misc/tools/shadescript/shade.vbs
new file mode 100644 (file)
index 0000000..e5dc4be
--- /dev/null
@@ -0,0 +1,172 @@
+option explicit 
+
+
+Const ForReading = 1\r
+Const ForWriting = 2\r
+Const ForAppending = 8\r
+
+dim CRLF 
+
+CRLF = Chr(13) & Chr(10)\r
+
+dim scriptFullName, scriptPath \r
+scriptFullName = WScript.ScriptFullName\r
+scriptPath = Left ( scriptFullName, InStrRev ( scriptFullName, WScript.ScriptName) - 1 )
+\r
+dim objFSO, setfolder, re, shader, objShaderTemplate, shaderTemplate
+Set objFSO = CreateObject("Scripting.FileSystemObject")\r
+Set setfolder = objFSO.GetFolder(scriptPath)\r
+Set re = New RegExp
+
+re.IgnoreCase = True
+re.Global = True
+re.Pattern = ""\r
+\r
+Set shader = objFSO.OpenTextFile (scriptPath & "\" & setfolder.name & ".shader", ForWriting, True)\r
+
+Set objShaderTemplate = objFSO.OpenTextFile(scriptPath & "\template.shader", ForReading)
+shaderTemplate = objShaderTemplate.ReadAll()
+
+function filetitle(sfilename)
+       filetitle = Left(sfilename, len(sfilename) - 4)
+end function 
+\r
+dim noLightmap, isLiquid, isTransparent, bounceScale, shaderString
+dim shaderHead, shaderTail, shaderQUI, shaderDiffuse, diffuseExtra
+dim subfold, texfile, fn
+
+For Each subfold in setfolder.Subfolders\r
+       ' shader.write "Folder: " & subfold.Name & CRLF\r
+       For Each texfile In subfold.Files
+               'Defaults               
+               noLightmap              = false
+               isLiquid                = false
+               isTransparent   = false
+               bounceScale     = 1
+               shaderString    = shaderTemplate
+               
+               shaderHead              = ""
+               shaderTail              = ""
+               shaderQUI               = ""
+               shaderDiffuse   = ""
+               diffuseExtra    = ""
+               
+               ' First ignore any extra map or Thumbs.db
+               re.Pattern = "_bump.|_gloss.|_norm.|_glow.|Thumbs.db"
+               if not re.test(texfile.name) then                       \r
+                       re.pattern = "decal"
+                       if re.test(texfile.name) then
+                               noLightmap = true
+                       end if
+                       
+                       re.pattern = "water"
+                       if re.test(texfile.name) then
+                               noLightmap = true
+                               isLiquid = true
+                               shaderHead = shaderHead & "     surfaceparm trans" & CRLF
+                               shaderHead = shaderHead & "     surfaceparm water" & CRLF
+                               shaderHead = shaderHead & "     qer_trans 20" & CRLF
+                               diffuseExtra = "blendfunc blend"
+                       end if
+                       
+                       re.pattern = "slime"
+                       if re.test(texfile.name) then
+                               noLightmap = true
+                               isLiquid = true
+                               shaderHead = shaderHead & "     surfaceparm trans" & CRLF
+                               shaderHead = shaderHead & "     surfaceparm slime" & CRLF
+                               shaderHead = shaderHead & "     qer_trans 20" & CRLF
+                       end if
+                       
+                       re.pattern = "lava"
+                       if re.test(texfile.name) then
+                               noLightmap = true
+                               isLiquid = true
+                               shaderHead = shaderHead & "     surfaceparm trans" & CRLF
+                               shaderHead = shaderHead & "     surfaceparm lava" & CRLF
+                               shaderHead = shaderHead & "     qer_trans 20" & CRLF
+                               diffuseExtra = "                blendfunc add"
+                       end if
+                       
+                       re.pattern = "glass"
+                       if re.test(texfile.name) then
+                               noLightmap = true
+                               shaderHead = shaderHead & "     surfaceparm trans" & CRLF
+                               diffuseExtra = "                blendfunc add"
+                       end if
+                       
+                       re.pattern = "metal"
+                       if re.test(texfile.name) then
+                               bounceScale = bounceScale + 0.25
+                               shaderHead = shaderHead & "     surfaceparm metalsteps" & CRLF
+                       end if
+                       
+                       re.pattern = "grate"
+                       if re.test(texfile.name) then
+                               bounceScale = bounceScale + 0.25
+                               shaderHead = shaderHead & "     surfaceparm trans" & CRLF
+                               diffuseExtra = "                blendfunc blend"
+                       end if
+                       
+                       re.pattern = "shiny"
+                       if re.test(texfile.name) then
+                               bounceScale = bounceScale + 0.25
+                       end if
+                       
+                       re.pattern = "dirt|terrain|old"
+                       if re.test(texfile.name) then
+                               bounceScale = bounceScale - 0.25
+                               shaderHead = shaderHead & "     surfaceparm dust" & CRLF
+                       end if
+                       
+                       shaderDiffuse = "textures/" & setfolder.name & "/" & subfold.name & "/" & texfile.name
+                       
+                       fn = scriptPath & "/" & subfold.name & "/" & filetitle(texfile.name) & "_gloss.tga" 
+                       if objFSO.FileExists(fn) Then
+                               bounceScale = bounceScale + 0.25
+                       end if
+                       
+                       fn = scriptPath & "/" & subfold.name & "/" & filetitle(texfile.name) & "_qei.tga" 
+                       if objFSO.FileExists(fn) Then
+                               shaderQUI = "textures/" & setfolder.name & "/" & subfold.name & "/" & filetitle(texfile.name) & "_qei.tga" 
+                       else
+                               shaderQUI = shaderDiffuse
+                       end if
+
+                       if not noLightmap then 
+                               shaderTail = "  {" & CRLF & "           map $lightmap" & CRLF & "               rgbGen identity" & CRLF & "             tcGen lightmap" & CRLF & "              blendfunc filter" & CRLF & "    }"
+                       end if
+                       
+                       if not bounceScale = 1 then 
+                               re.pattern = ","
+                               shaderHead = shaderHead & "     q3map_bounceScale " & re.Replace(bounceScale, ".") & CRLF
+                       end if
+                               
+                       re.Pattern = "%shader_name%"
+                       shaderString = re.Replace(shaderTemplate, "textures/" & setfolder.name & "/" & subfold.name & "-" & filetitle(texfile.name))
+
+                       re.Pattern = "%qei_name%"
+                       shaderString = re.Replace(shaderString, shaderQUI)
+
+                       re.Pattern = "%shader_head%"
+                       shaderString = re.Replace(shaderString, shaderHead)
+                       
+                       re.Pattern = "%diffuse_map%"
+                       shaderString = re.Replace(shaderString, shaderDiffuse)
+                       
+                       re.Pattern = "%diffuse_map_extra%"
+                       shaderString = re.Replace(shaderString, diffuseExtra)
+
+                       re.Pattern = "%shader_tail%"
+                       shaderString = re.Replace(shaderString, shaderTail)
+                       
+
+                       
+                       shader.write shaderString & CRLF & CRLF
+               end if\r
+       Next\r
+Next\r
+shader.Close\r
+\r
+\r
+\r
diff --git a/misc/tools/shadescript/template.shader b/misc/tools/shadescript/template.shader
new file mode 100644 (file)
index 0000000..b9d4787
--- /dev/null
@@ -0,0 +1,15 @@
+%shader_name%
+{
+       qer_editorimage %qei_name%
+       dpoffsetmapping - 2
+       dpglossintensitymod  3
+       dpglossexponentmod  4
+%shader_head%
+
+       {
+               map %diffuse_map%
+               %diffuse_map_extra%             
+       }
+
+%shader_tail%
+}
\ No newline at end of file