Some progress...
Here are two different shaders for water. They both appear somewhat reflective based off a light position that I'm assuming is in the shader settings themselves. At first they appear just like black blobs but when you walk around you can see one is animated for ripple and the other is flat reflecting light.
Is there some way to control the opacity of an entity? Seems like there is an issue with the alpha channels too. When brought over to GG from FPSC. I kind of expected everything from FPSC to just work in GG... this is unfortunate.
Least this seems to be a step in the right direction. However like the over 1000's assets ive been converting over... this looks like its going to require a lot of extra work to get working and looking good in GG.
//Description: Shader for dynamic entities, normal mapping,specular, reflectivity,
// and "hero" spec that always faces player. "LightSource" variable is pulled from FPSC for accurate lighting.
//
//Textures:
//"texture_D.dds" diffuse texture
//"texture_I.dd" specular texture, alpha channel is reflectivity mask
//"texture_N.dds" normal map texture
//"texture_S.dds" reflectivity texture
/************* UNTWEAKABLES **************/
float4x4 World : WORLD;
float4x4 WorldViewProj : WorldViewProjection;
float4x4 WorldIT : WorldInverseTranspose;
float4x4 ViewInv : ViewInverse;
float4 eyePos : CameraPosition;
float time: Time;
float sintime : SinTime;
/******TWEAKABLES***************************/
float SpecExpon : Power
<
string UIWidget = "slider";
float UIMin = 1.0;
float UIMax = 128.0;
float UIStep = 1.0;
string UIName = "specular power";
> = 64.0;
/******VALUES PULLED FROM FPSC - NON TWEAKABLE**********/
float4 AmbiColor : Ambient
<
string UIName = "Ambient Light Color";
> = {0.1f, 0.1f, 0.1f, 1.0f};
float4 SurfColor : Diffuse
<
string UIName = "Surface Color";
string UIType = "Color";
> = {1.0f, 1.0f, 1.0f, 1.0f};
float4 LightSource
<
string UIType = "Fixed Light Source";
> = {500000.0f,50000.0f, -0.0f, 1.0f};
/****************** TEXTURES AND SAMPLERS*********************/
texture DiffuseMap : DiffuseMap
<
string Name = "D.tga";
string type = "2D";
>;
//could be anything here - ill,spec,normal,cube
texture EffectMap : DiffuseMap
<
string Name = "I.tga";
string type = "2D";
>;
texture NormalMap : DiffuseMap
<
string Name = "N.tga";
string type = "2D";
>;
texture EnvironmentMap
<
string type = "2D";
string name = "i.tga";
>;
//Diffuse Texture _D
sampler2D DiffuseSampler = sampler_state
{
Texture = <DiffuseMap>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
//Effect Texture _I (could be anything here - ill,spec,normal,cube)
sampler2D EffectSampler = sampler_state
{
Texture = <EffectMap>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
//Effect Texture _N (could be anything here - ill,spec,normal,cube)
sampler2D NormalSampler = sampler_state
{
Texture = <NormalMap>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
//Effect Texture _S fake cubemap texture (blurred 2d image)
sampler EnvironmentSampler = sampler_state
{
Texture = (EnvironmentMap);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
;
/************* DATA STRUCTS **************/
struct appdata {
float4 Position : POSITION;
float4 UV0 : TEXCOORD0;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};
/*data passed to pixel shader*/
struct vertexOutput
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
float3 LightVec : TEXCOORD2;
float3 WorldNormal : TEXCOORD3;
float3 WorldTangent : TEXCOORD4;
float3 WorldBinorm : TEXCOORD5;
float4 WPos : TEXCOORD6;
float2 atlasUV:TEXCOORD7;
};
/*******Vertex Shader***************************/
vertexOutput mainVS(appdata IN)
{
vertexOutput OUT;
//float4 tempPos = float4(IN.Position, 1);
float4 worldSpacePos = mul(IN.Position, World);
OUT.WorldNormal = normalize(mul(IN.Normal, WorldIT).xyz);
OUT.WorldTangent = mul(IN.Tangent, WorldIT).xyz;
OUT.WorldBinorm = mul(IN.Binormal, WorldIT).xyz;
OUT.LightVec = normalize (LightSource - worldSpacePos );
OUT.Position = mul(IN.Position, WorldViewProj);
OUT.TexCoord = IN.UV0;
OUT.WPos = worldSpacePos;
/****Calculate a set of texture coordinates to perform atlas (sprite) walking*********/
float2 DimensionsXY = float2(5,5);
float2 atlasUVtemp = IN.UV0;
float framespersec = 5; //speed of animation in frames per second
float looptime = 100; //looptime in seconds
float loopcounter = floor(time/looptime); //increments by one every 50 seconds (or whatever "looptime" is)
float offset ; //initialize offset value used below
offset = looptime*loopcounter; //offset time value -increments every looptime
float speed =(time*framespersec) - (offset*framespersec) ;
float index = floor( speed); //floor of speed
float rowCount = floor( (index / DimensionsXY.y) ); //floor of (speed / Ydimension.g)
float2 offsetVector = float2(index, rowCount);
float2 atlas = (1.0 / DimensionsXY) ;
float2 move = (offsetVector + atlasUVtemp);
OUT.atlasUV = (atlas.xy *move);
/*******************************************************************************************/
return OUT;
}
/****************Framgent Shader*****************/
float4 mainPS(vertexOutput IN) : COLOR
{
float4 diffuse = tex2D(DiffuseSampler,IN.TexCoord.xy); //sample diffuse texture
float4 effectmap = tex2D(EffectSampler,IN.TexCoord.xy); //sample specular map texture
float3 normalmap = tex2D(NormalSampler,IN.atlasUV.xy) *2-1 ; //sample and expand normal map
float3 Ln = (IN.LightVec);
float3 Nn = (IN.WorldNormal);
float3 Tn = (IN.WorldTangent);
float3 Bn = (IN.WorldBinorm);
float3 Nb = (normalmap.z * Nn) + (0.02*(normalmap.x * Tn + normalmap.y * Bn));
Nb = normalize(Nb);
//normalized view vector for accurate specular highlights from LightSource
float3 ViewVector = (eyePos - IN.WPos);
float3 Vn = normalize(ViewVector);
//float3 V = ViewVector;
//reflection mapping for windows
float3 G = normalize(2 * dot(Nb, Vn) * Nb - Vn); // glance vector (view space)
float3 Reflection = float3(-G.x, G.y, -G.z);
float4 Env = tex2D(EnvironmentSampler,Reflection);
//float4 Env = texCUBE(EnvironmentSampler,Reflection); //this no longer works without an acutal cubemap
//half vectors
float3 Hn = normalize(Vn+Ln);
//calculate lighting Half Lamert scale and bias
float4 lighting = lit(pow(0.5*(dot(Ln,Nb))+0.5,1.0),dot(Hn,Nb),48);
//give a slight boost to AmbiColor and clamp, prevents diffuse lighting from getting to dark on non-lit side
AmbiColor = AmbiColor+0.13;
AmbiColor = clamp(AmbiColor,0,1);
//diffuse light contribution
//float4 diffuseContrib = diffuse * 1.0* lighting.y * (SurfColor) +(AmbiColor*diffuse);
//specular light contribution
float4 specContrib = lighting.z * effectmap*(SurfColor+0.1) ;
//Cubemap reflection contribution
float4 Reflectivity = Env*SurfColor+AmbiColor;
float4 result = (0.5*Env)+1.5*specContrib;
//float4 result = normalmap;
//float4 result = Env;
result.w = 0.4 * diffuse.w;
return result;
}
/****** technique ********************************/
technique dx9textured
{
pass P0
{
// lighting
Lighting = FALSE;
FogEnable = FALSE;
// samplers
//Sampler[0] = (LightmapSampler);
//Sampler[1] = (DiffuseSampler);
//Sampler[2] = (IllSpecSampler);
//Sampler[3] = (NormalSampler);
// shaders
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}
}