fixed 2 shaders..
This commit is contained in:
@@ -16,6 +16,7 @@ namespace OpenRa.GlRenderer
|
|||||||
Graphics g;
|
Graphics g;
|
||||||
public IntPtr dc;
|
public IntPtr dc;
|
||||||
public IntPtr rc;
|
public IntPtr rc;
|
||||||
|
public IntPtr cgContext;
|
||||||
|
|
||||||
public static void CheckGlError()
|
public static void CheckGlError()
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,18 @@ namespace OpenRa.GlRenderer
|
|||||||
if (rc == IntPtr.Zero)
|
if (rc == IntPtr.Zero)
|
||||||
throw new InvalidOperationException("can't create wglcontext");
|
throw new InvalidOperationException("can't create wglcontext");
|
||||||
Wgl.wglMakeCurrent(dc, rc);
|
Wgl.wglMakeCurrent(dc, rc);
|
||||||
|
|
||||||
|
cgContext = Cg.cgCreateContext();
|
||||||
|
//Cg.cgSetErrorCallback(CgErrorCallback);
|
||||||
|
CgGl.cgGLRegisterStates(cgContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CgErrorCallback()
|
||||||
|
{
|
||||||
|
var err = Cg.cgGetError();
|
||||||
|
var str = Cg.cgGetErrorString(err);
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
string.Format("CG Error: {0}: {1}", err, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableScissor(int left, int top, int width, int height)
|
public void EnableScissor(int left, int top, int width, int height)
|
||||||
@@ -168,13 +181,40 @@ namespace OpenRa.GlRenderer
|
|||||||
|
|
||||||
public class Shader
|
public class Shader
|
||||||
{
|
{
|
||||||
public Shader(GraphicsDevice dev, Stream s) { }
|
IntPtr effect;
|
||||||
|
IntPtr highTechnique;
|
||||||
|
IntPtr lowTechnique;
|
||||||
|
|
||||||
|
public Shader(GraphicsDevice dev, Stream s)
|
||||||
|
{
|
||||||
|
var code = new StreamReader(s).ReadToEnd();
|
||||||
|
effect = Cg.cgCreateEffect(dev.cgContext, code, null);
|
||||||
|
|
||||||
|
if (effect == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
var err = Cg.cgGetErrorString(Cg.cgGetError());
|
||||||
|
var results = Cg.cgGetLastListing(dev.cgContext);
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
string.Format("Cg compile failed ({0}):\n{1}", err, results));
|
||||||
|
}
|
||||||
|
|
||||||
|
lowTechnique = Cg.cgGetNamedTechnique(effect, "low_quality");
|
||||||
|
highTechnique = Cg.cgGetNamedTechnique(effect, "high_quality");
|
||||||
|
|
||||||
|
if (lowTechnique != IntPtr.Zero && 0 == Cg.cgValidateTechnique(lowTechnique))
|
||||||
|
lowTechnique = IntPtr.Zero;
|
||||||
|
if (highTechnique != IntPtr.Zero && 0 == Cg.cgValidateTechnique(highTechnique))
|
||||||
|
highTechnique = IntPtr.Zero;
|
||||||
|
|
||||||
|
if (highTechnique == IntPtr.Zero && lowTechnique == IntPtr.Zero)
|
||||||
|
throw new InvalidOperationException("No valid techniques");
|
||||||
|
}
|
||||||
|
|
||||||
public ShaderQuality Quality { get; set; }
|
public ShaderQuality Quality { get; set; }
|
||||||
public void Render(Action a) { }
|
public void Render(Action a) { }
|
||||||
public void SetValue(string param, Texture texture) { }
|
public void SetValue(string param, Texture texture) { }
|
||||||
public void SetValue<T>(string param, T t) where T : struct { }
|
public void SetValue<T>(string param, T t) where T : struct { }
|
||||||
public void Commit() { }
|
public void Commit() { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Texture
|
public class Texture
|
||||||
@@ -210,6 +250,11 @@ namespace OpenRa.GlRenderer
|
|||||||
[Flags]
|
[Flags]
|
||||||
public enum VertexFormat { Position, Texture2 }
|
public enum VertexFormat { Position, Texture2 }
|
||||||
|
|
||||||
public enum ShaderQuality { Low, Medium, High }
|
public enum ShaderQuality { Low, High }
|
||||||
public enum PrimitiveType { PointList, LineList, TriangleList }
|
public enum PrimitiveType
|
||||||
|
{
|
||||||
|
PointList = Gl.GL_POINTS,
|
||||||
|
LineList = Gl.GL_LINES,
|
||||||
|
TriangleList = Gl.GL_TRIANGLES
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
line.fx
36
line.fx
@@ -2,14 +2,13 @@
|
|||||||
// Author: C. Forbes
|
// Author: C. Forbes
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
|
|
||||||
shared float2 Scroll;
|
float2 Scroll;
|
||||||
|
|
||||||
shared float2 r1, r2; // matrix elements
|
float2 r1, r2; // matrix elements
|
||||||
|
|
||||||
struct VertexIn {
|
struct VertexIn {
|
||||||
float4 Position: POSITION;
|
float4 Position: POSITION;
|
||||||
float2 RG: TEXCOORD0;
|
float4 Color: TEXCOORD0;
|
||||||
float2 BA: TEXCOORD1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexOut {
|
struct VertexOut {
|
||||||
@@ -17,37 +16,28 @@ struct VertexOut {
|
|||||||
float4 Color: COLOR0;
|
float4 Color: COLOR0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FragmentIn {
|
|
||||||
float4 Color: COLOR0;
|
|
||||||
};
|
|
||||||
|
|
||||||
VertexOut Simple_vp(VertexIn v) {
|
VertexOut Simple_vp(VertexIn v) {
|
||||||
VertexOut o;
|
VertexOut o;
|
||||||
float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
|
float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
|
||||||
o.Position = float4(p.x,p.y,0,1);
|
o.Position = float4(p.x,p.y,0,1);
|
||||||
o.Color.rg = v.RG.xy;
|
o.Color = v.Color;
|
||||||
o.Color.ba = v.BA.xy;
|
|
||||||
// o.Color.a = 1.0f;
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
float4 Simple_fp(VertexOut f) : COLOR0 {
|
||||||
|
|
||||||
float4 Simple_fp(FragmentIn f) : COLOR0 {
|
|
||||||
return f.Color;
|
return f.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
technique high_quality {
|
technique high_quality {
|
||||||
pass p0 {
|
pass p0 {
|
||||||
AlphaBlendEnable = true;
|
BlendEnable = true;
|
||||||
ZWriteEnable = false;
|
DepthTestEnable = false;
|
||||||
ZEnable = false;
|
//CullMode = None;
|
||||||
CullMode = None;
|
//FillMode = Wireframe;
|
||||||
FillMode = Wireframe;
|
VertexProgram = compile arbvp1 Simple_vp();
|
||||||
VertexShader = compile vs_2_0 Simple_vp();
|
FragmentProgram = compile arbfp1 Simple_fp();
|
||||||
PixelShader = compile ps_2_0 Simple_fp();
|
|
||||||
|
|
||||||
SrcBlend = SrcAlpha;
|
//SrcBlend = SrcAlpha;
|
||||||
DestBlend = InvSrcAlpha;
|
//DestBlend = InvSrcAlpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
79
world-shp.fx
79
world-shp.fx
@@ -2,36 +2,26 @@
|
|||||||
// Author: C. Forbes
|
// Author: C. Forbes
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
|
|
||||||
shared texture DiffuseTexture, Palette;
|
float2 Scroll;
|
||||||
shared float2 Scroll;
|
float2 r1, r2; // matrix elements
|
||||||
|
|
||||||
shared float2 r1, r2; // matrix elements
|
sampler2D DiffuseTexture = sampler_state {
|
||||||
|
MinFilter = Nearest;
|
||||||
sampler s_DiffuseTexture = sampler_state {
|
MagFilter = Nearest;
|
||||||
Texture = <DiffuseTexture>;
|
WrapS = Repeat;
|
||||||
MinFilter = None;
|
WrapT = Repeat;
|
||||||
MagFilter = None;
|
|
||||||
MipFilter = None;
|
|
||||||
|
|
||||||
AddressU = Wrap;
|
|
||||||
AddressV = Wrap;
|
|
||||||
AddressW = Wrap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sampler s_PaletteTexture = sampler_state {
|
sampler2D Palette = sampler_state {
|
||||||
Texture = <Palette>;
|
MinFilter = Nearest;
|
||||||
MinFilter = None;
|
MagFilter = Nearest;
|
||||||
MagFilter = None;
|
WrapS = Repeat;
|
||||||
MipFilter = None;
|
WrapT = Repeat;
|
||||||
|
|
||||||
AddressU = Clamp;
|
|
||||||
AddressV = Clamp;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexIn {
|
struct VertexIn {
|
||||||
float4 Position: POSITION;
|
float4 Position: POSITION;
|
||||||
float2 Tex0: TEXCOORD0;
|
float4 Tex0: TEXCOORD0;
|
||||||
float2 Tex1: TEXCOORD1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexOut {
|
struct VertexOut {
|
||||||
@@ -40,11 +30,6 @@ struct VertexOut {
|
|||||||
float4 ChannelMask: TEXCOORD1;
|
float4 ChannelMask: TEXCOORD1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FragmentIn {
|
|
||||||
float3 Tex0: TEXCOORD0;
|
|
||||||
float4 ChannelMask: TEXCOORD1;
|
|
||||||
};
|
|
||||||
|
|
||||||
float4 DecodeChannelMask( float x )
|
float4 DecodeChannelMask( float x )
|
||||||
{
|
{
|
||||||
if (x > 0)
|
if (x > 0)
|
||||||
@@ -55,45 +40,27 @@ float4 DecodeChannelMask( float x )
|
|||||||
|
|
||||||
VertexOut Simple_vp(VertexIn v) {
|
VertexOut Simple_vp(VertexIn v) {
|
||||||
VertexOut o;
|
VertexOut o;
|
||||||
|
|
||||||
float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
|
float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
|
||||||
o.Position = float4(p.x,p.y,0,1);
|
o.Position = float4(p.x,p.y,0,1);
|
||||||
o.Tex0 = float3(v.Tex0.x, v.Tex0.y, v.Tex1.x);
|
o.Tex0 = float3(v.Tex0.x, v.Tex0.y, v.Tex0.z);
|
||||||
o.ChannelMask = DecodeChannelMask( v.Tex1.y );
|
o.ChannelMask = DecodeChannelMask( v.Tex0.w );
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
||||||
|
|
||||||
float4 Palette_fp(FragmentIn f) : COLOR0 {
|
float4 Palette_fp(VertexOut f) : COLOR0 {
|
||||||
float4 x = tex2D(s_DiffuseTexture, f.Tex0.xy);
|
float4 x = tex2D(DiffuseTexture, f.Tex0.xy);
|
||||||
float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z );
|
float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z );
|
||||||
return tex2D(s_PaletteTexture, p + texelOffset);
|
return tex2D(Palette, p + texelOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
technique low_quality {
|
technique low_quality {
|
||||||
pass p0 {
|
pass p0 {
|
||||||
AlphaBlendEnable = false;
|
BlendEnable = false;
|
||||||
ZWriteEnable = false;
|
DepthTestEnable = false;
|
||||||
ZEnable = false;
|
CullFaceEnable = false;
|
||||||
CullMode = None;
|
VertexProgram = compile arbvp1 Simple_vp();
|
||||||
FillMode = Solid;
|
FragmentProgram = compile arbfp1 Palette_fp();
|
||||||
VertexShader = compile vs_2_0 Simple_vp();
|
|
||||||
PixelShader = compile ps_2_0 Palette_fp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
technique high_quality {
|
|
||||||
pass p0 {
|
|
||||||
AlphaBlendEnable = true;
|
|
||||||
ZWriteEnable = false;
|
|
||||||
ZEnable = false;
|
|
||||||
CullMode = None;
|
|
||||||
FillMode = Solid;
|
|
||||||
VertexShader = compile vs_2_0 Simple_vp();
|
|
||||||
PixelShader = compile ps_2_0 Palette_fp();
|
|
||||||
|
|
||||||
SrcBlend = SrcAlpha;
|
|
||||||
DestBlend = InvSrcAlpha;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user