heh. silly me ![]()
In debug mode:-
SM 2.0 = ~125 FPS;
SM 3.0 = ~85 FPS;
In release mode:-
SM 2.0 = ~131 FPS
SM 3.0 = ~132 FPS
Not Telling
FantasyVII hasn't added any contacts yet.
13 April 2013 - 12:01 PM
heh. silly me ![]()
In debug mode:-
SM 2.0 = ~125 FPS;
SM 3.0 = ~85 FPS;
In release mode:-
SM 2.0 = ~131 FPS
SM 3.0 = ~132 FPS
13 April 2013 - 11:54 AM
Are you measuring with a Debug or Release build configuration? By default, XNA's Debug configuration compiles shaders without optimizations.
Debug. let my try release ^^'
13 April 2013 - 11:06 AM
ok so this is what I have so far. I made two types of point lights. they are perfect for what i need. What is left the cone shape light. Can someone please look at my code and see if I'm going in the right path or not.
Here are the images of both lights that workes perfectly.


and here is the image of the cone light that I have a problem with.

Clearly it looks nothing like a cone.
The function that i use to create the cone shape light is "CalculateConeLight".
struct Light
{
float2 Position;
float4 Color;
float Radius;
float Intensity;
};
float4x4 MatrixTransform;
texture ColorTexture;
int numberOfLights;
Light lights[15];
float AmbientIntensity;
float4 AmbientColor;
float ScreenWidth;
float ScreenHeight;
sampler ColorMap = sampler_state
{
Texture = <ColorTexture>;
};
float4 CalculateLight(Light light, float4 TextureMap, float3 PixelPosition)
{
float2 Direction = light.Position - PixelPosition;
float Distance = saturate(1 / length(Direction) * light.Radius);
return TextureMap * Distance * light.Color * light.Intensity;
}
float4 CalculatePointLight(Light light, float4 TextureMap, float3 PixelPosition)
{
float2 Direction = light.Position - PixelPosition;
float Distance = 1 - length(Direction) / light.Radius;
return TextureMap * Distance * light.Color * light.Intensity;
}
float4 CalculateConeLight(Light light, float4 TextureMap, float3 PixelPosition)
{
float2 Direction = light.Position - PixelPosition;
float rho = dot(normalize(light.Position), -Direction);
float phi = cos(45 * 0.5);
float coneAttenuation = saturate(1 - max(0, rho) / phi);
return TextureMap * coneAttenuation * light.Color * light.Intensity;
}
float4 Deferredlight(float2 TexCoords : TEXCOORD0) : COLOR
{
float4 TextureMap = tex2D(ColorMap, TexCoords);
float3 PixelPosition = float3(ScreenWidth * TexCoords.x, ScreenHeight * TexCoords.y, 0);
float4 FinalColor = (TextureMap * AmbientColor * AmbientIntensity);
for(int i = 0; i <= numberOfLights; i++)
FinalColor += CalculateLight(lights[i], TextureMap, PixelPosition);
return FinalColor;
}
void VertexShaderFunction(inout float4 color : COLOR0,
inout float2 texCoord : TEXCOORD0,
inout float4 position : SV_Position)
{
position = mul(position, MatrixTransform);
}
technique Deferred
{
pass Pass1
{
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 Deferredlight();
}
}
13 April 2013 - 05:14 AM
ok. thanks guys. just one last thing. Is there anything I can do to my shader to gain more FPS? Is my shader code good enough? Sorry for being a noob, but I just started learning HLSL about a week ago.
13 April 2013 - 03:28 AM
Here is my shader code. Sorry I did not post it before.
struct Light
{
float2 Position;
float4 Color;
float Radius;
float Intensity;
};
float4x4 MatrixTransform;
texture ColorTexture;
int numberOfLights;
Light lights[15];
float AmbientIntensity;
float4 AmbientColor;
float ScreenWidth;
float ScreenHeight;
sampler ColorMap = sampler_state
{
Texture = <ColorTexture>;
};
float4 CalculateLight(Light light, float4 Base, float3 PixelPosition)
{
float2 Direction = light.Position - PixelPosition;
float Distance = saturate(1 / length(Direction) * light.Radius);
float Amount = max(0, dot(Base,normalize(Distance)));
return Base * Distance * light.Color * light.Intensity;
}
float4 Deferredlight(float2 TexCoords : TEXCOORD0) : COLOR
{
float4 Base = tex2D(ColorMap, TexCoords);
float3 PixelPosition = float3(ScreenWidth * TexCoords.x, ScreenHeight * TexCoords.y, 0);
float4 FinalColor = (Base * AmbientColor * AmbientIntensity);
for(int i=0; i <= numberOfLights; i++)
FinalColor += CalculateLight(lights[i], Base, PixelPosition);
return FinalColor;
}
void VertexShaderFunction(inout float4 color : COLOR0,
inout float2 texCoord : TEXCOORD0,
inout float4 position : SV_Position)
{
position = mul(position, MatrixTransform);
}
technique Deferred
{
pass Pass1
{
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 Deferredlight();
}
}
So is there a way to make SM 3.0 run faster?
Find content