Skip to content

Commit 758bac5

Browse files
committed
Support viewport rect
1 parent b80f3e1 commit 758bac5

11 files changed

Lines changed: 283 additions & 80 deletions

File tree

Dev/Effekseer

Submodule Effekseer updated 72 files
8.69 KB
Binary file not shown.

Dev/Plugin/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ void Execute(RTHandle colorBuffer, RTHandle depthBuffer, CommandBuffer cmd, HDCa
3434
prop.depthTargetRenderTexture = depthBuffer;
3535
prop.renderFeature = Effekseer.Internal.RenderFeature.HDRP;
3636

37+
var colorRT = colorBuffer.rt;
38+
3739
// TODO : It needs to support VR and override
38-
prop.Viewport = hdCamera.camera.pixelRect;
40+
prop.ActualScreenSize = new Vector2Int(hdCamera.actualWidth, hdCamera.actualHeight);
41+
prop.Viewport = new Rect(0, 0, hdCamera.camera.pixelRect.width, hdCamera.camera.pixelRect.height);
3942

40-
prop.colorTargetDescriptor = new UnityEngine.RenderTextureDescriptor(hdCamera.actualWidth, hdCamera.actualHeight, colorBuffer.rt.format, 0, colorBuffer.rt.mipmapCount);
43+
prop.colorTargetDescriptor = new UnityEngine.RenderTextureDescriptor(colorRT.width, colorRT.height, colorRT.format, 0, colorRT.mipmapCount);
4144
prop.colorTargetDescriptor.msaaSamples = hdCamera.msaaSamples == MSAASamples.None ? 1 : 2;
4245
prop.isRequiredToChangeViewport = true;
4346
EffekseerSystem.Instance.renderer.Render(hdCamera.camera, LayerMask.value, prop, cmd, true, blitter);
@@ -68,4 +71,4 @@ protected override void Cleanup()
6871
}
6972
}
7073

71-
#endif
74+
#endif

Dev/Plugin/Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, boo
3838
CoreUtils.SetRenderTarget(cmd, color);
3939
}
4040

41-
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, bool xrRendering)
41+
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, Vector2? actualScreenSize, bool xrRendering)
4242
{
4343
CoreUtils.SetRenderTarget(cmd, color, depth);
4444
}

Dev/Plugin/Assets/Effekseer/Scripts/EffekseerBlitter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public interface IEffekseerBlitter
88
void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering);
99
void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material, bool xrRendering);
1010
void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, bool xrRendering);
11-
void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, bool xrRendering);
11+
void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, Vector2? actualScreenSize, bool xrRendering);
1212
}
1313

1414
public class StandardBlitter : IEffekseerBlitter
15-
{
15+
{
1616
public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool xrRendering)
1717
{
1818
cmd.Blit(source, dest);
@@ -35,7 +35,7 @@ public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, boo
3535
}
3636
}
3737

38-
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, bool xrRendering)
38+
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, RenderTargetIdentifier depth, Vector2? actualScreenSize, bool xrRendering)
3939
{
4040
if (xrRendering)
4141
{
@@ -44,6 +44,11 @@ public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier color, Ren
4444
else
4545
{
4646
cmd.SetRenderTarget(color, depth);
47+
48+
if (actualScreenSize.HasValue)
49+
{
50+
cmd.SetViewport(new Rect(0, 0, actualScreenSize.Value.x, actualScreenSize.Value.y));
51+
}
4752
}
4853
}
4954
}

Dev/Plugin/Assets/Effekseer/Scripts/EffekseerRenderer.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public class RenderTargetProperty
7979
public RenderTargetIdentifier colorTargetIdentifier;
8080
public RenderTargetIdentifier? depthTargetIdentifier;
8181
public RenderTextureDescriptor colorTargetDescriptor;
82-
public Rect Viewport;
82+
public Vector2? ActualScreenSize;
83+
public Rect? Viewport;
8384
public bool isRequiredToChangeViewport = false;
8485
public RenderTexture colorTargetRenderTexture = null;
8586
public RenderTexture depthTargetRenderTexture = null;
@@ -135,13 +136,15 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, DepthRenderTexture depthRen
135136
}
136137
else if (renderFeature == RenderFeature.HDRP)
137138
{
139+
var normalizedArea = new Vector4(
140+
Viewport.Value.width / depthTargetRenderTexture.width,
141+
Viewport.Value.height / depthTargetRenderTexture.height,
142+
Viewport.Value.x / depthTargetRenderTexture.width,
143+
Viewport.Value.y / depthTargetRenderTexture.height);
144+
138145
var m = AllocateBlitArrayMaterial();
139146
m.SetTexture("_BackgroundTex", depthTargetRenderTexture);
140-
m.SetVector("textureArea", new Vector4(
141-
Viewport.width / depthTargetRenderTexture.width,
142-
Viewport.height / depthTargetRenderTexture.height,
143-
Viewport.x / depthTargetRenderTexture.width,
144-
Viewport.y / depthTargetRenderTexture.height));
147+
m.SetVector("textureArea", normalizedArea);
145148
cb.SetRenderTarget(depthRenderTexture.renderTexture);
146149
cb.ClearRenderTarget(true, true, new Color(0, 0, 0));
147150
cb.Blit(null, depthRenderTexture.renderTexture, m);
@@ -152,23 +155,25 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, DepthRenderTexture depthRen
152155
}
153156

154157
// restore
155-
SetDefaultRenderTarget(cb, blitter);
158+
SetDefaultRenderTarget(cb, blitter);
156159
}
157160
}
158161

159162
internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture backgroundRenderTexture, IEffekseerBlitter blitter)
160163
{
161164
if (isRequiredToChangeViewport)
162165
{
166+
var normalizedArea = new Vector4(
167+
Viewport.Value.width / colorTargetRenderTexture.width,
168+
Viewport.Value.height / colorTargetRenderTexture.height,
169+
Viewport.Value.x / colorTargetRenderTexture.width,
170+
Viewport.Value.y / colorTargetRenderTexture.height);
171+
163172
if (colorTargetRenderTexture.dimension == TextureDimension.Tex2DArray)
164173
{
165174
var m = AllocateBlitArrayMaterial();
166175
m.SetTexture("_BackgroundTex", colorTargetRenderTexture);
167-
m.SetVector("textureArea", new Vector4(
168-
Viewport.width / colorTargetRenderTexture.width,
169-
Viewport.height / colorTargetRenderTexture.height,
170-
Viewport.x / colorTargetRenderTexture.width,
171-
Viewport.y / colorTargetRenderTexture.height));
176+
m.SetVector("textureArea", normalizedArea);
172177
blitter.SetRenderTarget(cb, backgroundRenderTexture.renderTexture, xrRendering);
173178
cb.ClearRenderTarget(true, true, new Color(0, 0, 0));
174179
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, m, xrRendering);
@@ -177,11 +182,7 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture bac
177182
{
178183
var m = AllocateBlitMaterial();
179184
m.SetTexture("_BackgroundTex", colorTargetRenderTexture);
180-
m.SetVector("textureArea", new Vector4(
181-
Viewport.width / colorTargetRenderTexture.width,
182-
Viewport.height / colorTargetRenderTexture.height,
183-
Viewport.x / colorTargetRenderTexture.width,
184-
Viewport.y / colorTargetRenderTexture.height));
185+
m.SetVector("textureArea", normalizedArea);
185186
blitter.SetRenderTarget(cb, backgroundRenderTexture.renderTexture, xrRendering);
186187
cb.ClearRenderTarget(true, true, new Color(0, 0, 0));
187188
blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, m, xrRendering);
@@ -197,21 +198,21 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture bac
197198
}
198199

199200
// restore
200-
SetDefaultRenderTarget(cb, blitter);
201-
201+
SetDefaultRenderTarget(cb, blitter);
202+
202203
}
203204

204-
internal void SetDefaultRenderTarget(CommandBuffer cb, IEffekseerBlitter blitter)
205-
{
206-
if (depthTargetIdentifier.HasValue)
207-
{
208-
blitter.SetRenderTarget(cb, colorTargetIdentifier, depthTargetIdentifier.Value, xrRendering);
209-
}
210-
else
211-
{
212-
blitter.SetRenderTarget(cb, colorTargetIdentifier, xrRendering);
213-
}
214-
}
205+
internal void SetDefaultRenderTarget(CommandBuffer cb, IEffekseerBlitter blitter)
206+
{
207+
if (depthTargetIdentifier.HasValue)
208+
{
209+
blitter.SetRenderTarget(cb, colorTargetIdentifier, depthTargetIdentifier.Value, ActualScreenSize, xrRendering);
210+
}
211+
else
212+
{
213+
blitter.SetRenderTarget(cb, colorTargetIdentifier, xrRendering);
214+
}
215+
}
215216

216217
Material AllocateBlitArrayMaterial()
217218
{

Dev/Plugin/Assets/Effekseer/Scripts/EffekseerRendererNative.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ private void SetupEffekseerRenderCommandBuffer(
102102
blitter.Blit(cmbBuf, renderTargetProperty.colorBufferID.Value, this.renderTexture.renderTexture, renderTargetProperty.xrRendering);
103103
cmbBuf.SetRenderTarget(renderTargetProperty.colorBufferID.Value);
104104

105-
if (renderTargetProperty.Viewport.width > 0)
105+
if (renderTargetProperty.Viewport.HasValue)
106106
{
107-
cmbBuf.SetViewport(renderTargetProperty.Viewport);
107+
cmbBuf.SetViewport(renderTargetProperty.Viewport.Value);
108108
}
109109
}
110110
else
111111
{
112112
renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.renderTexture, blitter);
113113

114-
if (renderTargetProperty.Viewport.width > 0)
114+
if (renderTargetProperty.Viewport.HasValue)
115115
{
116-
cmbBuf.SetViewport(renderTargetProperty.Viewport);
116+
cmbBuf.SetViewport(renderTargetProperty.Viewport.Value);
117117
}
118118
}
119119
}
@@ -142,9 +142,9 @@ private void SetupEffekseerRenderCommandBuffer(
142142
{
143143
renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.depthTexture, blitter);
144144

145-
if (renderTargetProperty.Viewport.width > 0)
145+
if (renderTargetProperty.Viewport.HasValue)
146146
{
147-
cmbBuf.SetViewport(renderTargetProperty.Viewport);
147+
cmbBuf.SetViewport(renderTargetProperty.Viewport.Value);
148148
}
149149
}
150150
else
@@ -163,10 +163,20 @@ private void SetupEffekseerRenderCommandBuffer(
163163
}
164164
}
165165

166+
if (renderTargetProperty != null && renderTargetProperty.Viewport.HasValue)
167+
{
168+
cmbBuf.SetViewport(renderTargetProperty.Viewport.Value);
169+
}
170+
166171
cmbBuf.IssuePluginEvent(Plugin.EffekseerGetRenderBackFunc(), this.renderId);
167172

168173
copyBackground();
169174

175+
if (renderTargetProperty != null && renderTargetProperty.Viewport.HasValue)
176+
{
177+
cmbBuf.SetViewport(renderTargetProperty.Viewport.Value);
178+
}
179+
170180
cmbBuf.IssuePluginEvent(Plugin.EffekseerGetRenderFrontFunc(), this.renderId);
171181
}
172182

@@ -320,4 +330,4 @@ public void OnPostRender(Camera camera)
320330
}
321331
}
322332

323-
}
333+
}

Dev/Plugin/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,11 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
10051005
// Reset command buffer
10061006
path.ResetBuffers();
10071007

1008-
// Reset render target
1009-
renderTargetProperty.SetDefaultRenderTarget(path.commandBuffer, blitter);
1008+
// Reset render target
1009+
if (renderTargetProperty != null)
1010+
{
1011+
renderTargetProperty.SetDefaultRenderTarget(path.commandBuffer, blitter);
1012+
}
10101013

10111014
// copy back
10121015
if (EffekseerRendererUtils.IsDistortionEnabled)
@@ -1015,9 +1018,9 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
10151018
{
10161019
renderTargetProperty.ApplyToCommandBuffer(path.commandBuffer, path.renderTexture, blitter);
10171020

1018-
if (renderTargetProperty.Viewport.width > 0)
1021+
if (renderTargetProperty.Viewport.HasValue)
10191022
{
1020-
path.commandBuffer.SetViewport(renderTargetProperty.Viewport);
1023+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
10211024
}
10221025
}
10231026
else
@@ -1036,9 +1039,9 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
10361039
{
10371040
renderTargetProperty.ApplyToCommandBuffer(path.commandBuffer, path.depthTexture, blitter);
10381041

1039-
if (renderTargetProperty.Viewport.width > 0)
1042+
if (renderTargetProperty.Viewport.HasValue)
10401043
{
1041-
path.commandBuffer.SetViewport(renderTargetProperty.Viewport);
1044+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
10421045
}
10431046
}
10441047
else
@@ -1068,6 +1071,11 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
10681071
path.ReallocateComputeBuffer(maxmumSize);
10691072
}
10701073

1074+
if (renderTargetProperty != null && renderTargetProperty.Viewport.HasValue)
1075+
{
1076+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
1077+
}
1078+
10711079
RenderInternal(path.commandBuffer, path._computeBufferBack, path._materialProps, path._modelBuffers, path._customDataBuffers, path.renderTexture, path.depthTexture);
10721080

10731081
// Distortion
@@ -1080,18 +1088,18 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
10801088
blitter.Blit(path.commandBuffer, renderTargetProperty.colorBufferID.Value, path.renderTexture.renderTexture, renderTargetProperty.xrRendering);
10811089
blitter.SetRenderTarget(path.commandBuffer, renderTargetProperty.colorBufferID.Value, renderTargetProperty.xrRendering);
10821090

1083-
if (renderTargetProperty.Viewport.width > 0)
1091+
if (renderTargetProperty.Viewport.HasValue)
10841092
{
1085-
path.commandBuffer.SetViewport(renderTargetProperty.Viewport);
1093+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
10861094
}
10871095
}
10881096
else if (renderTargetProperty != null)
10891097
{
10901098
renderTargetProperty.ApplyToCommandBuffer(path.commandBuffer, path.renderTexture, blitter);
10911099

1092-
if (renderTargetProperty.Viewport.width > 0)
1100+
if (renderTargetProperty.Viewport.HasValue)
10931101
{
1094-
path.commandBuffer.SetViewport(renderTargetProperty.Viewport);
1102+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
10951103
}
10961104
}
10971105
else
@@ -1120,6 +1128,11 @@ public void Render(Camera camera, int additionalMask, RenderTargetProperty rende
11201128
path.ReallocateComputeBuffer(maxmumSize);
11211129
}
11221130

1131+
if (renderTargetProperty != null && renderTargetProperty.Viewport.HasValue)
1132+
{
1133+
path.commandBuffer.SetViewport(renderTargetProperty.Viewport.Value);
1134+
}
1135+
11231136
RenderInternal(path.commandBuffer, path._computeBufferFront, path._materialProps, path._modelBuffers, path._customDataBuffers, path.renderTexture, path.depthTexture);
11241137
}
11251138

@@ -1660,4 +1673,4 @@ public void OnPostRender(Camera camera)
16601673
_renderPathContainer.OnPostRender(camera);
16611674
}
16621675
}
1663-
}
1676+
}

Tests/HDRPTests/Assets/Tests/Basic.unity

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ MeshRenderer:
480480
m_RenderingLayerMask: 1
481481
m_RendererPriority: 0
482482
m_Materials:
483-
- {fileID: 2100000, guid: b835a14b8c29dc6469a7d8bf737761d1, type: 2}
483+
- {fileID: 2100000, guid: fc1e07330d067bf48996f7d4b661e56d, type: 2}
484484
m_StaticBatchInfo:
485485
firstSubMesh: 0
486486
subMeshCount: 0
@@ -631,7 +631,7 @@ MeshRenderer:
631631
m_RenderingLayerMask: 1
632632
m_RendererPriority: 0
633633
m_Materials:
634-
- {fileID: 2100000, guid: b835a14b8c29dc6469a7d8bf737761d1, type: 2}
634+
- {fileID: 2100000, guid: fc1e07330d067bf48996f7d4b661e56d, type: 2}
635635
m_StaticBatchInfo:
636636
firstSubMesh: 0
637637
subMeshCount: 0
@@ -736,7 +736,7 @@ MeshRenderer:
736736
m_RenderingLayerMask: 1
737737
m_RendererPriority: 0
738738
m_Materials:
739-
- {fileID: 2100000, guid: b835a14b8c29dc6469a7d8bf737761d1, type: 2}
739+
- {fileID: 2100000, guid: fc1e07330d067bf48996f7d4b661e56d, type: 2}
740740
m_StaticBatchInfo:
741741
firstSubMesh: 0
742742
subMeshCount: 0
@@ -834,7 +834,7 @@ Light:
834834
m_Type: 1
835835
m_Shape: 0
836836
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
837-
m_Intensity: 3.1415927
837+
m_Intensity: 7000
838838
m_Range: 10
839839
m_SpotAngle: 30
840840
m_InnerSpotAngle: 21.80208
@@ -875,7 +875,7 @@ Light:
875875
m_RenderingLayerMask: 1
876876
m_Lightmapping: 4
877877
m_LightShadowCasterMode: 2
878-
m_AreaSize: {x: 1, y: 1}
878+
m_AreaSize: {x: 0.5, y: 0.5}
879879
m_BounceIntensity: 1
880880
m_ColorTemperature: 6570
881881
m_UseColorTemperature: 0
@@ -911,7 +911,7 @@ MonoBehaviour:
911911
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
912912
m_Name:
913913
m_EditorClassIdentifier:
914-
m_Intensity: 3.1415927
914+
m_Intensity: 7000
915915
m_EnableSpotReflector: 0
916916
m_LuxAtDistance: 1
917917
m_InnerSpotPercent: 0

0 commit comments

Comments
 (0)