Screen Space Reflections in HLSL - proper camera ray casting Hi, I'm trying to implement SSR based on this blog Screen Space Glossy Reflections which is an implementation of Morgan's McGuire raytracing algorithm written in GLSL. Unfortunately I'm getting wrong results on Ray Tracing Screen Space step. Could anybody describe me how to generate camera screen rays properly (float3 viewRay)? My vertex shader looks like this: struct VertexOut { float4 posH : SV_POSITION0; float3 viewRay : POSITION; }; VertexOut VS_SSR( uint id : SV_VertexID ) { VertexOut output; float2 tex = float2( (id << 1) & 2, id & 2 ); output.posH = float4(tex * float2( 2.0f, -2.0f ) + float2( -1.0f, 1.0f) , 0.0f, 1.0f ); output.viewRay = float3(tex.x,tex.y,1); return output; } Draw call in C++ is just a fullscreen quad: setViewPort(renderTargetSize.x,renderTargetSize.y); deviceContext->OMSetRenderTargets(1,&ssrRTV,nullptr); depthResource->SetResource(depthResourceView); normalResource->SetResource(normalResourceView); effect->GetTechniqueByName("RayTrace")->GetPassByIndex(0)->Apply(0,deviceContext); deviceContext->Draw( 4, 0 ); Initialization of effect variables after compiling shader : compileShader(L"ssr.fx",macros,shaderFlags); depthResource = effect->GetVariableByName("depthBuffer")->AsShaderResource(); normalResource = effect->GetVariableByName("normalBuffer")->AsShaderResource(); projection = effect->GetVariableByName("projection")->AsMatrix(); depthBufferSize = effect->GetVariableByName("cb_depthBufferSize")->AsVector(); zThickness = effect->GetVariableByName("cb_zThickness")->AsScalar(); zThickness->SetFloat(1.0f); ZNear = effect->GetVariableByName("cb_ZNear")->AsScalar(); ZNear->SetFloat(0.5f); ZFar = effect->GetVariableByName("cb_ZFar")->AsScalar(); ZFar->SetFloat(32760.0f); stride = effect->GetVariableByName("cb_stride")->AsScalar(); stride->SetFloat(1.0f); maxSteps = effect->GetVariableByName("cb_maxSteps")->AsScalar(); maxSteps->SetFloat(25.0f); maxDistance = effect->GetVariableByName("cb_maxDistance")->AsScalar(); maxDistance->SetFloat(1000.0f); strideZCutoff = effect->GetVariableByName("cb_strideZCutoff")->AsScalar(); strideZCutoff->SetFloat(1.0f); I'm getting camera view dependent ray hit results. I mean when I move camera around hitPixel intersections with DepthBuffer changes. I also assume that viewToTextureSpaceMatrix is my projection matrix calculated in XMMatrixPerspectiveOffCenterLH(..) function call. Is that right ? https://ift.tt/eA8V8J
Hi, I'm trying to implement SSR based on this blog Screen Space Glossy Reflections which is an implementation of Morgan's McGuire raytracing algorithm written in GLSL. Unfortunately I'm getting wrong results on Ray Tracing Screen Space step. Could anybody describe me how to generate camera screen rays properly (float3 viewRay)? My vertex shader looks like this: struct VertexOut { float4 posH : SV_POSITION0; float3 viewRay : POSITION; }; VertexOut VS_SSR( uint id : SV_VertexID ) { VertexOut output; float2 tex = float2( (id << 1) & 2, id & 2 ); output.posH = float4(tex * float2( 2.0f, -2.0f ) + float2( -1.0f, 1.0f) , 0.0f, 1.0f ); output.viewRay = float3(tex.x,tex.y,1); return output; } Draw call in C++ is just a fullscreen quad: setViewPort(renderTargetSize.x,renderTargetSize.y); deviceContext->OMSetRenderTargets(1,&ssrRTV,nullptr); depthResource->SetResource(depthResourceView); normalResource->SetResource(normalResourceView); effect->GetTechniqueByName("RayTrace")->GetPassByIndex(0)->Apply(0,deviceContext); deviceContext->Draw( 4, 0 ); Initialization of effect variables after compiling shader : compileShader(L"ssr.fx",macros,shaderFlags); depthResource = effect->GetVariableByName("depthBuffer")->AsShaderResource(); normalResource = effect->GetVariableByName("normalBuffer")->AsShaderResource(); projection = effect->GetVariableByName("projection")->AsMatrix(); depthBufferSize = effect->GetVariableByName("cb_depthBufferSize")->AsVector(); zThickness = effect->GetVariableByName("cb_zThickness")->AsScalar(); zThickness->SetFloat(1.0f); ZNear = effect->GetVariableByName("cb_ZNear")->AsScalar(); ZNear->SetFloat(0.5f); ZFar = effect->GetVariableByName("cb_ZFar")->AsScalar(); ZFar->SetFloat(32760.0f); stride = effect->GetVariableByName("cb_stride")->AsScalar(); stride->SetFloat(1.0f); maxSteps = effect->GetVariableByName("cb_maxSteps")->AsScalar(); maxSteps->SetFloat(25.0f); maxDistance = effect->GetVariableByName("cb_maxDistance")->AsScalar(); maxDistance->SetFloat(1000.0f); strideZCutoff = effect->GetVariableByName("cb_strideZCutoff")->AsScalar(); strideZCutoff->SetFloat(1.0f); I'm getting camera view dependent ray hit results. I mean when I move camera around hitPixel intersections with DepthBuffer changes. I also assume that viewToTextureSpaceMatrix is my projection matrix calculated in XMMatrixPerspectiveOffCenterLH(..) function call. Is that right ?
from GameDev.net https://ift.tt/2QJmHKN
from GameDev.net https://ift.tt/2QJmHKN
ليست هناك تعليقات