offset texture rendering
parent
ef948cf7fb
commit
b1395babfe
|
@ -16,6 +16,9 @@ namespace Kav
|
||||||
EffectParameter metallicParam;
|
EffectParameter metallicParam;
|
||||||
EffectParameter roughnessParam;
|
EffectParameter roughnessParam;
|
||||||
|
|
||||||
|
EffectParameter numTextureRowsParam;
|
||||||
|
EffectParameter numTextureColumnsParam;
|
||||||
|
|
||||||
EffectParameter vertexShaderIndexParam;
|
EffectParameter vertexShaderIndexParam;
|
||||||
EffectParameter shaderIndexParam;
|
EffectParameter shaderIndexParam;
|
||||||
|
|
||||||
|
@ -27,6 +30,9 @@ namespace Kav
|
||||||
float metallic;
|
float metallic;
|
||||||
float roughness;
|
float roughness;
|
||||||
|
|
||||||
|
int numTextureRows = 1;
|
||||||
|
int numTextureColumns = 1;
|
||||||
|
|
||||||
bool albedoTextureEnabled = false;
|
bool albedoTextureEnabled = false;
|
||||||
bool metallicRoughnessMapEnabled = false;
|
bool metallicRoughnessMapEnabled = false;
|
||||||
bool normalMapEnabled = false;
|
bool normalMapEnabled = false;
|
||||||
|
@ -127,6 +133,26 @@ namespace Kav
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int NumTextureRows
|
||||||
|
{
|
||||||
|
get { return numTextureRows; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
numTextureRows = value;
|
||||||
|
numTextureRowsParam.SetValue(numTextureRows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int NumTextureColumns
|
||||||
|
{
|
||||||
|
get { return numTextureColumns; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
numTextureColumns = value;
|
||||||
|
numTextureColumnsParam.SetValue(numTextureColumns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool HardwareInstancingEnabled
|
public bool HardwareInstancingEnabled
|
||||||
{
|
{
|
||||||
get { return hardwareInstancingEnabled; }
|
get { return hardwareInstancingEnabled; }
|
||||||
|
@ -248,6 +274,9 @@ namespace Kav
|
||||||
metallicParam = Parameters["MetallicValue"];
|
metallicParam = Parameters["MetallicValue"];
|
||||||
roughnessParam = Parameters["RoughnessValue"];
|
roughnessParam = Parameters["RoughnessValue"];
|
||||||
|
|
||||||
|
numTextureRowsParam = Parameters["NumTextureRows"];
|
||||||
|
numTextureColumnsParam = Parameters["NumTextureColumns"];
|
||||||
|
|
||||||
shaderIndexParam = Parameters["PixelShaderIndex"];
|
shaderIndexParam = Parameters["PixelShaderIndex"];
|
||||||
vertexShaderIndexParam = Parameters["VertexShaderIndex"];
|
vertexShaderIndexParam = Parameters["VertexShaderIndex"];
|
||||||
}
|
}
|
||||||
|
|
BIN
Effects/FXB/DeferredPBR_GBufferEffect.fxb (Stored with Git LFS)
BIN
Effects/FXB/DeferredPBR_GBufferEffect.fxb (Stored with Git LFS)
Binary file not shown.
|
@ -10,6 +10,9 @@ BEGIN_CONSTANTS
|
||||||
float MetallicValue _ps(c1) _cb(c1);
|
float MetallicValue _ps(c1) _cb(c1);
|
||||||
float RoughnessValue _ps(c2) _cb(c2);
|
float RoughnessValue _ps(c2) _cb(c2);
|
||||||
|
|
||||||
|
int NumTextureRows _vs(c9) _cb(c3);
|
||||||
|
int NumTextureColumns _vs(c10) _cb(c4);
|
||||||
|
|
||||||
MATRIX_CONSTANTS
|
MATRIX_CONSTANTS
|
||||||
|
|
||||||
float4x4 World _vs(c0) _cb(c7);
|
float4x4 World _vs(c0) _cb(c7);
|
||||||
|
@ -56,8 +59,11 @@ PixelInput main_vs(VertexInput input)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
PixelInput instanced_vs(VertexInput input, float3 Translation : TEXCOORD2)
|
PixelInput instanced_vs(
|
||||||
{
|
VertexInput input,
|
||||||
|
float3 Translation : TEXCOORD2,
|
||||||
|
float2 UVOffset : TEXCOORD5
|
||||||
|
) {
|
||||||
PixelInput output;
|
PixelInput output;
|
||||||
|
|
||||||
float4x4 world = float4x4(
|
float4x4 world = float4x4(
|
||||||
|
@ -65,13 +71,17 @@ PixelInput instanced_vs(VertexInput input, float3 Translation : TEXCOORD2)
|
||||||
float4(0, 1, 0, 0),
|
float4(0, 1, 0, 0),
|
||||||
float4(0, 0, 1, 0),
|
float4(0, 0, 1, 0),
|
||||||
float4(Translation.x, Translation.y, Translation.z, 1)
|
float4(Translation.x, Translation.y, Translation.z, 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
float4x4 worldViewProjection = mul(world, ViewProjection);
|
float4x4 worldViewProjection = mul(world, ViewProjection);
|
||||||
|
|
||||||
output.PositionWorld = mul(input.Position, world);
|
output.PositionWorld = mul(input.Position, world);
|
||||||
output.NormalWorld = mul(input.Normal, world);
|
output.NormalWorld = mul(input.Normal, world);
|
||||||
output.TexCoord = input.TexCoord;
|
|
||||||
|
float2 texCoord;
|
||||||
|
texCoord.x = (input.TexCoord.x / NumTextureColumns + UVOffset.x);
|
||||||
|
texCoord.y = (input.TexCoord.y / NumTextureRows + UVOffset.y);
|
||||||
|
output.TexCoord = texCoord;
|
||||||
|
|
||||||
output.Position = mul(input.Position, worldViewProjection);
|
output.Position = mul(input.Position, worldViewProjection);
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,8 @@ namespace Kav
|
||||||
Texture2D AlbedoTexture { get; }
|
Texture2D AlbedoTexture { get; }
|
||||||
Texture2D NormalTexture { get; }
|
Texture2D NormalTexture { get; }
|
||||||
Texture2D MetallicRoughnessTexture { get; }
|
Texture2D MetallicRoughnessTexture { get; }
|
||||||
|
|
||||||
|
int NumTextureRows { get; }
|
||||||
|
int NumTextureColumns { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ namespace Kav
|
||||||
public float Metallic { get; set; } = 0.5f;
|
public float Metallic { get; set; } = 0.5f;
|
||||||
public float Roughness { get; set; } = 0.5f;
|
public float Roughness { get; set; } = 0.5f;
|
||||||
|
|
||||||
|
public int NumTextureRows { get; set; } = 1;
|
||||||
|
public int NumTextureColumns { get; set; } = 1;
|
||||||
|
|
||||||
public bool DisableAlbedoMap { get; set; } = false;
|
public bool DisableAlbedoMap { get; set; } = false;
|
||||||
public bool DisableNormalMap { get; set; } = false;
|
public bool DisableNormalMap { get; set; } = false;
|
||||||
public bool DisableMetallicRoughnessMap { get; set; } = false;
|
public bool DisableMetallicRoughnessMap { get; set; } = false;
|
||||||
|
|
37
Renderer.cs
37
Renderer.cs
|
@ -63,14 +63,15 @@ namespace Kav
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (PositionInstanceVertex[], DynamicVertexBuffer) CreatePositionVertexBuffer(
|
public static (T[], DynamicVertexBuffer) CreateInstanceVertexBuffer<T>(
|
||||||
GraphicsDevice graphicsDevice,
|
GraphicsDevice graphicsDevice,
|
||||||
int instanceVertexCount
|
int instanceVertexCount
|
||||||
) {
|
) where T : IVertexType {
|
||||||
var positionData = new PositionInstanceVertex[instanceVertexCount];
|
var positionData = new T[instanceVertexCount];
|
||||||
|
|
||||||
var vertexBuffer = new DynamicVertexBuffer(
|
var vertexBuffer = new DynamicVertexBuffer(
|
||||||
graphicsDevice,
|
graphicsDevice,
|
||||||
VertexDeclarations.PositionInstanceDeclaration,
|
typeof(T),
|
||||||
instanceVertexCount,
|
instanceVertexCount,
|
||||||
BufferUsage.WriteOnly
|
BufferUsage.WriteOnly
|
||||||
);
|
);
|
||||||
|
@ -257,31 +258,6 @@ namespace Kav
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int FillInstanceVertexBuffer<V>(
|
|
||||||
IEnumerable<Matrix> transforms,
|
|
||||||
V[] vertexData,
|
|
||||||
DynamicVertexBuffer dynamicVertexBuffer
|
|
||||||
) where V : struct, IVertexType, IHasTranslation
|
|
||||||
{
|
|
||||||
int numInstances = 0;
|
|
||||||
foreach (var transform in transforms)
|
|
||||||
{
|
|
||||||
vertexData[numInstances].Translation = transform.Translation;
|
|
||||||
numInstances += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numInstances == 0) { return 0; }
|
|
||||||
|
|
||||||
dynamicVertexBuffer.SetData(
|
|
||||||
vertexData,
|
|
||||||
0,
|
|
||||||
numInstances,
|
|
||||||
SetDataOptions.Discard
|
|
||||||
);
|
|
||||||
|
|
||||||
return numInstances;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RenderInstanced<T>(
|
public static void RenderInstanced<T>(
|
||||||
GraphicsDevice graphicsDevice,
|
GraphicsDevice graphicsDevice,
|
||||||
T drawable,
|
T drawable,
|
||||||
|
@ -391,6 +367,9 @@ namespace Kav
|
||||||
Deferred_GBufferEffect.Metallic = drawable.Metallic;
|
Deferred_GBufferEffect.Metallic = drawable.Metallic;
|
||||||
Deferred_GBufferEffect.Roughness = drawable.Roughness;
|
Deferred_GBufferEffect.Roughness = drawable.Roughness;
|
||||||
|
|
||||||
|
Deferred_GBufferEffect.NumTextureRows = drawable.NumTextureRows;
|
||||||
|
Deferred_GBufferEffect.NumTextureColumns = drawable.NumTextureColumns;
|
||||||
|
|
||||||
Deferred_GBufferEffect.AlbedoTexture = drawable.AlbedoTexture;
|
Deferred_GBufferEffect.AlbedoTexture = drawable.AlbedoTexture;
|
||||||
Deferred_GBufferEffect.NormalTexture = drawable.NormalTexture;
|
Deferred_GBufferEffect.NormalTexture = drawable.NormalTexture;
|
||||||
Deferred_GBufferEffect.MetallicRoughnessTexture = drawable.MetallicRoughnessTexture;
|
Deferred_GBufferEffect.MetallicRoughnessTexture = drawable.MetallicRoughnessTexture;
|
||||||
|
|
|
@ -8,5 +8,11 @@ namespace Kav
|
||||||
(
|
(
|
||||||
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 2)
|
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static VertexDeclaration PositionTextureOffsetInstanceDeclaration = new VertexDeclaration
|
||||||
|
(
|
||||||
|
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 2),
|
||||||
|
new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 5)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,24 +5,27 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
namespace Kav
|
namespace Kav
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct PositionInstanceVertex : IVertexType, IHasTranslation
|
public struct PositionTextureOffsetInstanceVertex : IVertexType
|
||||||
{
|
{
|
||||||
VertexDeclaration IVertexType.VertexDeclaration
|
VertexDeclaration IVertexType.VertexDeclaration
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return VertexDeclarations.PositionInstanceDeclaration;
|
return VertexDeclarations.PositionTextureOffsetInstanceDeclaration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 Translation { get; set; }
|
public Vector3 Translation { get; set; }
|
||||||
|
public Vector2 UVOffset { get; set; }
|
||||||
|
|
||||||
public static readonly VertexDeclaration VertexDeclaration;
|
public static readonly VertexDeclaration VertexDeclaration;
|
||||||
|
|
||||||
public PositionInstanceVertex(
|
public PositionTextureOffsetInstanceVertex(
|
||||||
Vector3 translation
|
Vector3 translation,
|
||||||
|
Vector2 uvOffset
|
||||||
) {
|
) {
|
||||||
Translation = translation;
|
Translation = translation;
|
||||||
|
UVOffset = uvOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue