3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1] 2

Author Topic: Shaders - miscellaneous - (Wireframe & Point)  (Read 4708 times)

« on: December 11, 2009, 03:15:50 AM »
here are a couple of helper shaders (scripts), for viewing your meshes in wireframe or point render mode. might be useful in some cases while editing.

you can set the color of your choice.

wireframe:
Code: [Select]
//******************************************************************
//SHADERS
//******************************************************************
/*HLSLSTART WireFrame_Fx_1_1

//---------------------------------------------------------------------
//                          fillmode - Wireframe
//---------------------------------------------------------------------
float Script : STANDARDSGLOBAL <
    string UIWidget = "none";
    string ScriptClass = "object";
    string ScriptOrder = "standard";
    string ScriptOutput = "color";
    string Script = "Technique=NoSkinning;";
> = 0.8;
//---------------------------------------------------------------------
//*****************************************************************************
//MATRIX
//*****************************************************************************
#define MATRIX_PALETTE_SIZE_DEFAULT 26

const int MATRIX_PALETTE_SIZE = MATRIX_PALETTE_SIZE_DEFAULT;
float4x3 amPalette[MATRIX_PALETTE_SIZE_DEFAULT];

float4x4 mxWorld : WORLD;
float4x4 mxWorldIT : amPalette; //to transform normals (note: we can re-use bone matrices registers as this will only be set for non-skinned meshes)
float4x4 mxViewProj : VIEWPROJECTION;

//*****************************************************************************
//LIGHT PROPERTIES
//*****************************************************************************
float4 lightDir : DIRECTION = {0.0f,0.0f,-1.0f,1.0f};
float4 lightColor : DIFFUSE = {1.0f,1.0f,1.0f,1.0f};
float4 lightAmbient : AMBIENT = {0.1f,0.1f,0.1f,1.0f};
//*****************************************************************************
//MATERIAL PROPERTIES
//*****************************************************************************
float4 MaterialDiffuse : DIFFUSE = {1.0f,1.0f,1.0f,1.0f};
float4 OverlayColor = {1.0f,1.0f,1.0f,1.0f};
//*****************************************************************************
//USED IN VERTEX SHADER
//*****************************************************************************
float3 worldEyePos;
//*****************************************************************************
//TEXTURE
//*****************************************************************************
texture diffuseMap : DIFFUSE <
    string ResourceName = "default_color.dds";
    string UIName =  "Color Texture";
    string ResourceType = "2D";
>;
//*****************************************************************************
//SKINNING STUFF
//*****************************************************************************
int boneCount = 2;

struct VS_SKIN_INPUT
{
   float4 vPos;
   float3 vBlendWeights;
   float4 vBlendIndices;
   float3 vNor;
};

struct VS_SKIN_OUTPUT
{
   float4 vPos;
   float3 vNor;
};

VS_SKIN_OUTPUT VS_Skin( const VS_SKIN_INPUT vInput, int iNumBones )
{
   //This function is called by VertSkinning(), the main
   //vertex shader function for skinned meshes
   //It applies bone matrices to vertex coordinates and normal,
   //which also transforms from model-space to world space

   VS_SKIN_OUTPUT vOutput = (VS_SKIN_OUTPUT) 0;

   float fLastWeight = 1.0;
   float fWeight;
   float afBlendWeights[3] = (float[3])vInput.vBlendWeights;
   int aiIndices[4] = (int[4])D3DCOLORtoUBYTE4(vInput.vBlendIndices);

   for (int iBone=0;(iBone<3) && (iBone<(iNumBones-1));iBone++)
   {
      fWeight = afBlendWeights[iBone];
      fLastWeight -= fWeight;
      vOutput.vPos.xyz += mul(vInput.vPos,amPalette[aiIndices[iBone]])*fWeight;
      vOutput.vNor += mul(vInput.vNor,amPalette[aiIndices[iBone]])*fWeight;
   }

   vOutput.vPos.xyz += mul(vInput.vPos,amPalette[aiIndices[iNumBones-1]])*fLastWeight;
   vOutput.vNor += mul(vInput.vNor,amPalette[aiIndices[iNumBones-1]])*fLastWeight;

   return vOutput;
}

//*****************************************************************************
//TEXTURE SAMPLER
//*****************************************************************************
sampler DiffuseMapSampler = sampler_state
{
    Texture = <diffuseMap>;
MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
    AddressU  = WRAP;
    AddressV  = WRAP;
};

//*****************************************************************************
//INPUT - OUTPUT
//*****************************************************************************
struct VS_INPUT
{
   float4 Pos : POSITION;
   float3 BlendWeights : BLENDWEIGHT;
   float4 BlendIndices : BLENDINDICES;
   float3 Normal : NORMAL;
   float2 Tex0 : TEXCOORD0;
};

struct VS_INPUT_NOSKIN
{
   float4 Pos : POSITION;
   float3 Normal : NORMAL;
   float2 Tex0 : TEXCOORD0;
};

struct VS_OUTPUT
{
   float4 Pos : POSITION;
   float2 Tex0 : TEXCOORD0;
};
//*****************************************************************************
//VERTEX SHADER - SKINNED
//*****************************************************************************
VS_OUTPUT VertSkinning(VS_INPUT IN, uniform int iNumBones)
{
   //-------------------------------------------------------------------------
   //Vertex shader used for skinned meshes
   VS_OUTPUT   OUT;
   
   VS_SKIN_INPUT vsi = { IN.Pos, IN.BlendWeights, IN.BlendIndices, IN.Normal };
   VS_SKIN_OUTPUT vso = VS_Skin( vsi, iNumBones );
   //-------------------------------------------------------------------------
   //vpos
   OUT.Pos = mul(float4(vso.vPos.xyz,1.0f),mxViewProj);
   //-------------------------------------------------------------------------
   //uv coords
   OUT.Tex0  = IN.Tex0;

   return OUT;
}
//*****************************************************************************
//VERTEX SHADER - NON SKINNED
//*****************************************************************************
VS_OUTPUT VertNoSkinning(VS_INPUT_NOSKIN IN)
{
   //-------------------------------------------------------------------------
   //Vertex shader used for static meshes
   VS_OUTPUT   OUT;
   //-------------------------------------------------------------------------
   //vpos
   OUT.Pos = mul(float4(IN.Pos.xyz,1.0f),mxViewProj);
   //-------------------------------------------------------------------------
   //uv coords
   OUT.Tex0  = IN.Tex0;

   return OUT;
}
//*****************************************************************************
//PIXEL SHADER
//*****************************************************************************
float4 PixScene(VS_OUTPUT IN): COLOR
{
   //Pixel shader
   return OverlayColor;
}
//*****************************************************************************
//TECHNIQUES
//*****************************************************************************
VertexShader vsArray[4] = { compile vs_1_1 VertSkinning(1),
                              compile vs_1_1 VertSkinning(2),
                              compile vs_1_1 VertSkinning(3),
                              compile vs_1_1 VertSkinning(4) };

technique Skinning
{
   pass p0
   {
      VertexShader = (vsArray[boneCount]);
      PixelShader = compile ps_1_1 PixScene();
      FillMode = wireframe;
   }
}
technique NoSkinning
{
   pass p0
   {
      VertexShader = compile vs_1_1 VertNoSkinning();
      PixelShader = compile ps_1_1 PixScene();
      FillMode = wireframe;
   }
   
}
HLSLEND*/
//******************************************************************
//VALUES
//******************************************************************
//------------------------------------------------------------------
float[] cOverlayColor(4);
int cObjectCount = 0;
int[] cObjectIdList(100);
//******************************************************************
//MAIN
//******************************************************************
void Main()
{
   //***************************************************************
   //INITIALIZATION SECTION
   //***************************************************************
   if (iInitializing())
   {
      //------------------------------------------------------------
      //wireframe shader
      cOverlayColor[0] = 1.0f;//red
      cOverlayColor[1] = 0.0f;//green
      cOverlayColor[2] = 0.0f;//blue
      cOverlayColor[3] = 1.0f;//alpha
     
      cObjectCount = 0;
      while (iObjectHandle(cObjectCount) != -1)
      {
         cObjectIdList[cObjectCount] = iObjectHandle(cObjectCount);
         iShaderSet(cObjectIdList[cObjectCount],"WireFrame_Fx_1_1");
         cObjectCount++;
      }
      //------------------------------------------------------------
   }
   //***************************************************************
   //UPDATE SECTION
   //***************************************************************
   //---------------------------------------------------------------
   //shaders - wireframe - set color
   for(int i=0;i<cObjectCount;i++)
   {
      iShaderFloat4Set(cObjectIdList[i],"OverlayColor",cOverlayColor[0],cOverlayColor[1],cOverlayColor[2],cOverlayColor[3]);
   }
   //---------------------------------------------------------------
   //***************************************************************
   //DEINITIALIZATION SECTION
   //***************************************************************
   //if(iDeinitializing())
   //{
      //------------------------------------------------------------
      //------------------------------------------------------------
   //}
   //---------------------------------------------------------------
}
//******************************************************************END OF MAIN

using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
« Reply #1 on: December 11, 2009, 03:17:22 AM »
Point:

Code: [Select]
//******************************************************************
//SHADERS
//******************************************************************
/*HLSLSTART Point_Only_Fx_1_1

//---------------------------------------------------------------------
//                          fillmode - point
//---------------------------------------------------------------------
float Script : STANDARDSGLOBAL <
    string UIWidget = "none";
    string ScriptClass = "object";
    string ScriptOrder = "standard";
    string ScriptOutput = "color";
    string Script = "Technique=NoSkinning;";
> = 0.8;
//---------------------------------------------------------------------
//*****************************************************************************
//MATRIX
//*****************************************************************************
#define MATRIX_PALETTE_SIZE_DEFAULT 26

const int MATRIX_PALETTE_SIZE = MATRIX_PALETTE_SIZE_DEFAULT;
float4x3 amPalette[MATRIX_PALETTE_SIZE_DEFAULT];

float4x4 mxWorld : WORLD;
float4x4 mxWorldIT : amPalette; //to transform normals (note: we can re-use bone matrices registers as this will only be set for non-skinned meshes)
float4x4 mxViewProj : VIEWPROJECTION;

//*****************************************************************************
//LIGHT PROPERTIES
//*****************************************************************************
float4 lightDir : DIRECTION = {0.0f,0.0f,-1.0f,1.0f};
float4 lightColor : DIFFUSE = {1.0f,1.0f,1.0f,1.0f};
float4 lightAmbient : AMBIENT = {0.1f,0.1f,0.1f,1.0f};
//*****************************************************************************
//MATERIAL PROPERTIES
//*****************************************************************************
float4 MaterialDiffuse : DIFFUSE = {1.0f,1.0f,1.0f,1.0f};
float4 OverlayColor = {1.0f,1.0f,1.0f,1.0f};
//*****************************************************************************
//USED IN VERTEX SHADER
//*****************************************************************************
float3 worldEyePos;
//*****************************************************************************
//TEXTURE
//*****************************************************************************
texture diffuseMap : DIFFUSE <
    string ResourceName = "default_color.dds";
    string UIName =  "Color Texture";
    string ResourceType = "2D";
>;
//*****************************************************************************
//SKINNING STUFF
//*****************************************************************************
int boneCount = 2;

struct VS_SKIN_INPUT
{
   float4 vPos;
   float3 vBlendWeights;
   float4 vBlendIndices;
   float3 vNor;
};

struct VS_SKIN_OUTPUT
{
   float4 vPos;
   float3 vNor;
};

VS_SKIN_OUTPUT VS_Skin( const VS_SKIN_INPUT vInput, int iNumBones )
{
   //This function is called by VertSkinning(), the main
   //vertex shader function for skinned meshes
   //It applies bone matrices to vertex coordinates and normal,
   //which also transforms from model-space to world space

   VS_SKIN_OUTPUT vOutput = (VS_SKIN_OUTPUT) 0;

   float fLastWeight = 1.0;
   float fWeight;
   float afBlendWeights[3] = (float[3])vInput.vBlendWeights;
   int aiIndices[4] = (int[4])D3DCOLORtoUBYTE4(vInput.vBlendIndices);

   for (int iBone=0;(iBone<3) && (iBone<(iNumBones-1));iBone++)
   {
      fWeight = afBlendWeights[iBone];
      fLastWeight -= fWeight;
      vOutput.vPos.xyz += mul(vInput.vPos,amPalette[aiIndices[iBone]])*fWeight;
      vOutput.vNor += mul(vInput.vNor,amPalette[aiIndices[iBone]])*fWeight;
   }

   vOutput.vPos.xyz += mul(vInput.vPos,amPalette[aiIndices[iNumBones-1]])*fLastWeight;
   vOutput.vNor += mul(vInput.vNor,amPalette[aiIndices[iNumBones-1]])*fLastWeight;

   return vOutput;
}

//*****************************************************************************
//TEXTURE SAMPLER
//*****************************************************************************
sampler DiffuseMapSampler = sampler_state
{
    Texture = <diffuseMap>;
MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
    AddressU  = WRAP;
    AddressV  = WRAP;
};

//*****************************************************************************
//INPUT - OUTPUT
//*****************************************************************************
struct VS_INPUT
{
   float4 Pos : POSITION;
   float3 BlendWeights : BLENDWEIGHT;
   float4 BlendIndices : BLENDINDICES;
   float3 Normal : NORMAL;
   float2 Tex0 : TEXCOORD0;
};

struct VS_INPUT_NOSKIN
{
   float4 Pos : POSITION;
   float3 Normal : NORMAL;
   float2 Tex0 : TEXCOORD0;
};

struct VS_OUTPUT
{
   float4 Pos : POSITION;
   float2 Tex0 : TEXCOORD0;
};
//*****************************************************************************
//VERTEX SHADER - SKINNED
//*****************************************************************************
VS_OUTPUT VertSkinning(VS_INPUT IN, uniform int iNumBones)
{
   //-------------------------------------------------------------------------
   //Vertex shader used for skinned meshes
   VS_OUTPUT   OUT;
   
   VS_SKIN_INPUT vsi = { IN.Pos, IN.BlendWeights, IN.BlendIndices, IN.Normal };
   VS_SKIN_OUTPUT vso = VS_Skin( vsi, iNumBones );
   //-------------------------------------------------------------------------
   //vpos
   OUT.Pos = mul(float4(vso.vPos.xyz,1.0f),mxViewProj);
   //-------------------------------------------------------------------------
   //uv coords
   OUT.Tex0  = IN.Tex0;

   return OUT;
}
//*****************************************************************************
//VERTEX SHADER - NON SKINNED
//*****************************************************************************
VS_OUTPUT VertNoSkinning(VS_INPUT_NOSKIN IN)
{
   //-------------------------------------------------------------------------
   //Vertex shader used for static meshes
   VS_OUTPUT   OUT;
   //-------------------------------------------------------------------------
   //vpos
   OUT.Pos = mul(float4(IN.Pos.xyz,1.0f),mxViewProj);
   //-------------------------------------------------------------------------
   //uv coords
   OUT.Tex0  = IN.Tex0;;

   return OUT;
}
//*****************************************************************************
//PIXEL SHADER
//*****************************************************************************
float4 PixScene(VS_OUTPUT IN): COLOR
{
   //Pixel shader
   return OverlayColor;
}
//*****************************************************************************
//TECHNIQUES
//*****************************************************************************             
VertexShader vsArray[4] = { compile vs_1_1 VertSkinning(1),
                              compile vs_1_1 VertSkinning(2),
                              compile vs_1_1 VertSkinning(3),
                              compile vs_1_1 VertSkinning(4) };

technique Skinning
{
   pass p0
   {
      VertexShader = (vsArray[boneCount]);
      PixelShader = compile ps_1_1 PixScene();
      FillMode = point;
   }
}
technique NoSkinning
{
   pass p0
   {
      VertexShader = compile vs_1_1 VertNoSkinning();
      PixelShader = compile ps_1_1 PixScene();
      FillMode = point;
   }
   
}
HLSLEND*/


//******************************************************************
//VALUES
//******************************************************************
//------------------------------------------------------------------
float[] cOverlayColor(4);
int cObjectCount = 0;
int[] cObjectIdList(100);
//******************************************************************
//MAIN
//******************************************************************
void Main()
{
   //***************************************************************
   //INITIALIZATION SECTION
   //***************************************************************
   if (iInitializing())
   {
      //------------------------------------------------------------
      //point shader
      cOverlayColor[0] = 1.0f;//red
      cOverlayColor[1] = 1.0f;//green
      cOverlayColor[2] = 1.0f;//blue
      cOverlayColor[3] = 1.0f;//alpha
     
      cObjectCount = 0;
      while (iObjectHandle(cObjectCount) != -1)
      {
         cObjectIdList[cObjectCount] = iObjectHandle(cObjectCount);
         iShaderSet(cObjectIdList[cObjectCount],"Point_Only_Fx_1_1");
         cObjectCount++;
      }
      //------------------------------------------------------------
   }
   //***************************************************************
   //UPDATE SECTION
   //***************************************************************
   //---------------------------------------------------------------
   //shaders - wireframe - set color
   for(int i=0;i<cObjectCount;i++)
   {
      iShaderFloat4Set(cObjectIdList[i],"OverlayColor",cOverlayColor[0],cOverlayColor[1],cOverlayColor[2],cOverlayColor[3]);
   }
   //---------------------------------------------------------------
   //***************************************************************
   //DEINITIALIZATION SECTION
   //***************************************************************
   //if(iDeinitializing())
   //{
      //------------------------------------------------------------
      //------------------------------------------------------------
   //}
   //---------------------------------------------------------------
}
//******************************************************************END OF MAIN

using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
« Reply #2 on: December 11, 2009, 08:01:44 AM »
Very nice Gene :) Me likee
« Reply #3 on: December 11, 2009, 08:18:36 AM »
This is really awesome.
Thanks again Gene :)
« Reply #4 on: December 12, 2009, 10:40:46 PM »
Great! ;)
Roll out!
http://www.youtube.com/watch?v=VD8MvMaPNO4

Do you have kids between the ages of 3 and 9?

http://www.amazon.com/dp/B007K1EFC6
« Reply #5 on: December 13, 2009, 12:15:58 AM »
awesome
i can see this being useful for some cool effects (dynamic starry night anyone?)

Currently using 7.22
« Reply #6 on: December 26, 2009, 07:10:43 AM »
great
but
where is the download ?
ALGERIA is my Heart and GAZZA his Pulse
Dz Forever ( www.3drad.com )
« Reply #7 on: December 26, 2009, 04:54:50 PM »
just copy the code and paste in a script.
« Last Edit: December 26, 2009, 04:56:26 PM by genetransfer »
using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
« Reply #8 on: December 28, 2009, 01:31:48 PM »
genetransfer,
I created a project, and link the script (with pasted text from the code above) to a skinmesh.  Tried with both versions.

On the script, I have an object handle OBJ_0 corresponding to the skinmesh,  However, upon run, the skinmesh looks as solid as before.
Is there any other action to take for this to work?  Using rad 6.41.

 
« Reply #9 on: December 28, 2009, 03:46:05 PM »
Did you check the 'Use custom shader' in the skins dialog ?
« Reply #10 on: December 29, 2009, 12:45:33 AM »
These are amazing shaders! I tried the wireframe in one of my levels and made it look like cyberspace :o  :D
« Reply #11 on: December 29, 2009, 02:32:03 AM »
glad you like them! :)
using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
« Reply #12 on: December 29, 2009, 05:08:38 AM »
Genetransfer, my bad. I did not set the custom shader check. Thanks, it works great.
« Reply #13 on: July 28, 2011, 03:13:03 PM »
Love the wireframe shader..

Question..

Is it possible to adjust the wireframe thickness ?

If so how ?
« Reply #14 on: July 28, 2011, 03:17:16 PM »
Love the wireframe shader..

Question..

Is it possible to adjust the wireframe thickness ?

If so how ?
Pages: [1] 2