Mercurial > LightClone
changeset 65:41980ff0607d
Added shader and textures for bot
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Wed, 05 Oct 2011 12:55:46 -0700 |
parents | 3507bd831c7f |
children | f7095bce01cf |
files | Assets/UI/Bot.PSD Assets/UI/BotMask.PSD Data/Shaders/Bot.fx Data/Textures/Bot.tga Data/Textures/BotMask.tga LightClone/LightClone.vcproj LightClone/Source/Bot.cpp LightClone/Source/Bot.h LightClone/ToDo.txt |
diffstat | 9 files changed, 126 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Data/Shaders/Bot.fx Wed Oct 05 12:55:46 2011 -0700 @@ -0,0 +1,102 @@ +extern uniform float4x4 kWorld; +extern uniform float4x4 kView; +extern uniform float4x4 kProjection; +extern uniform float4 kColor; +extern uniform texture kTexture; +extern uniform texture kTextureMask; + +sampler TextureSampler = sampler_state +{ + Texture = <kTexture>; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; +}; + +sampler MaskSampler = sampler_state +{ + Texture = <kTextureMask>; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; +}; + +struct VertexOutput +{ + /* + * kPosition + */ + float4 kPosition : POSITION0; + + /* + * kTextureCoords + */ + float2 kTextureCoords : TEXCOORD0; + + /* + * kNormal + */ + float3 kColor : COLOR0; +}; + +VertexOutput BotVS(float3 kVertexPosition : POSITION0, float3 kVertexNormal : NORMAL, float2 kTextureCoords : TEXCOORD0) +{ + float4x4 kWorldViewProjection = mul(mul(kWorld, kView), kProjection); + + float4 kDiffuse = float4(0.8f, 0.8f, 0.8f, 1.0f); + float4 kAmbient = float4(0.4f, 0.4f, 0.4f, 1.0f); + float3 kDirection = normalize(float3(-1.0f, -0.60f, -0.3f)); + + float3 kNormal = normalize(mul(kVertexNormal, (float3x3)kWorld)); + + VertexOutput kOutput; + kOutput.kPosition = mul(float4(kVertexPosition, 1.0f), kWorldViewProjection); + kOutput.kTextureCoords = kTextureCoords; + kOutput.kColor = kAmbient + kDiffuse * saturate(dot(-kDirection, kNormal)); + + return kOutput; +} + +float4 BotPS(float4 kDiffuseColor : COLOR0, float2 kTextureCoords : TEXCOORD0) : COLOR0 +{ + float4 kTexture = tex2D(TextureSampler, kTextureCoords); + float4 kMask = tex2D(MaskSampler, kTextureCoords); + + float fMaskScale = kMask.r; + float fTextureScale = 1.0f - fMaskScale; + + float4 kBaseColor = kTexture;// * fTextureScale; + float4 kMaskColor = kColor;// * fMaskScale; + + /* + if(mask == 0) + { + (1 - mask) * kBaseColor.rgb * kDiffuseColor.rgb + mask * kMaskColor.rgb + } + else + { + 0 * kBaseColor.rgb * kDiffuseColor.rgb + 1 * kMaskColor.rgb + } + */ + + return float4(kDiffuseColor.rgb * (fTextureScale * kBaseColor.rgb + fMaskScale * kMaskColor.rgb), kTexture.a); + + //return float4(kBaseColor.rgb * kDiffuseColor.rgb + kMaskColor, kTexture.a); + //return float4(kTexture.rgb * kDiffuseColor.rgb + kMask.r * kColor.rgb, kTexture.a); + //return float4(kTexture.rgb * kDiffuseColor.rgb * kColor.rgb, kTexture.a); +} + +technique Default +{ + pass Pass0 + { + vertexShader = compile vs_2_0 BotVS(); + pixelShader = compile ps_2_0 BotPS(); + + ZEnable = true; + ZWriteEnable = true; + ZFunc = LessEqual; + } +}
--- a/LightClone/LightClone.vcproj Tue Oct 04 13:02:45 2011 -0700 +++ b/LightClone/LightClone.vcproj Wed Oct 05 12:55:46 2011 -0700 @@ -524,6 +524,10 @@ Name="Shaders" > <File + RelativePath="..\Data\Shaders\Bot.fx" + > + </File> + <File RelativePath="..\Data\Shaders\Environment.fx" > </File>
--- a/LightClone/Source/Bot.cpp Tue Oct 04 13:02:45 2011 -0700 +++ b/LightClone/Source/Bot.cpp Wed Oct 05 12:55:46 2011 -0700 @@ -36,16 +36,20 @@ ErrorCode eCode = pServiceProvider->GetService("ResourceManager", &pResourceManager); if(eCode == Error_Success) { - eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\Environment.fx", &pEffect); + eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\Bot.fx", &pEffect); if(eCode == Error_Success) { eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\Bot.tga", &pTexture); if(eCode == Error_Success) { - eCode = pResourceManager->CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer); + eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\BotMask.tga", &pMask); if(eCode == Error_Success) { - eCode = SetupVertexBuffer(); + eCode = pResourceManager->CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer); + if(eCode == Error_Success) + { + eCode = SetupVertexBuffer(); + } } } } @@ -73,7 +77,7 @@ { pEnvironment = pInstance; nState = BotState_Idle; - nColor = D3DCOLOR_XRGB(255, 255, 255); + nColor = D3DCOLOR_XRGB(192, 0, 0); } /* @@ -82,7 +86,7 @@ void Bot::Reset() { nState = BotState_Idle; - nColor = D3DCOLOR_XRGB(0, 255, 0); + nColor = D3DCOLOR_XRGB(192, 0, 0); kMachine.Reset(); } @@ -255,7 +259,7 @@ if(nAction == Action_Light) { nState = BotState_Animate; - nColor = D3DCOLOR_XRGB(0, 0, 255); + nColor = D3DCOLOR_XRGB(0, 0, 192); kSequencer.nSequence = BotSequence_Light; kSequencer.fTimer = 0.0f; kSequencer.fSpeed = 3.0f; @@ -309,7 +313,7 @@ pEnvironment->NotifyAction(kPosition.X, kPosition.Y); nState = BotState_Pause; - nColor = D3DCOLOR_XRGB(0, 255, 0); + nColor = D3DCOLOR_XRGB(192, 0, 0); kSequencer.fTimer = 0.4f; } } @@ -371,6 +375,7 @@ pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTextureMask"), pMask); pEffect->CommitChanges(); kContext.DrawTriangles(Vertex::Block::Declaration, pVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);